PHP code example of juampi92 / phecks

1. Go to this page and download the library: Download juampi92/phecks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juampi92 / phecks example snippets


/**
 * @implements Check<ReflectionClass>
 */
class ConsoleClassesMustBeSuffixedWithCommandCheck implements Check
{
    public function __construct(
        private readonly ClassSource $source,
    ) {}

    /**
     * This method will get all the possible matches.
     */
    public function getMatches(): MatchCollection
    {
        return $this->source
            ->directory('./app/Console')
            ->run()
            ->reject(fn (ReflectionClass $class): bool => $class->isAbstract())
            ->pipe(new WhereExtendsClassFilter(\Illuminate\Console\Command::class));
    }

    /**
     * processMatch will check if the matches are
     * actual violations, and format them properly.
     */
    public function processMatch($match, FileMatch $file): array
    {
        if (Str::endsWith($match->getName(), 'Command')) {
            return [];
        }

        return [
            ViolationBuilder::make()->message('Command classes must be suffixed with \'Command\''),
        ];
    }
}
bash
php artisan phecks:run