1. Go to this page and download the library: Download narrowspark/coding-standard 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/ */
narrowspark / coding-standard example snippets
declare(strict_types=1);
use Ergebnis\License;
use Narrowspark\CS\Config\Config;
$license = License\Type\MIT::markdown(
__DIR__ . '/LICENSE.md',
License\Range::since(
License\Year::fromString('2021'),
new \DateTimeZone('UTC')
),
License\Holder::fromString('Daniel Bannert'),
License\Url::fromString('https://github.com/{name}/{repo}')
);
$license->save();
$config = new Config($license->header());
$config->getFinder()
->files()
->in(__DIR__)
->exclude([
'.build',
'.docker',
'.github',
'vendor'
])
// php_unit_namespaced rule thinks than the const are some namespaces
->notPath('rector.php')
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php_cs.cache');
return $config;
declare(strict_types=1);
/**
* Copyright (c) 2021 Daniel Bannert
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/narrowspark/php-cs-fixer-config
*/
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
// paths to refactor; solid alternative to CLI arguments
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
// is your PHP version different from the one your refactor to? [default: your PHP version], uses PHP_VERSION_ID format
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);
// auto import fully qualified class names? [default: false]
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
// skip root namespace classes, like \DateTime or \Exception [default: true]
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
// Run Rector only on changed files
$parameters->set(Option::ENABLE_CACHE, true);
$phpstanPath = getcwd() . '/phpstan.neon';
$phpstanNeonContent = FileSystem::read($phpstanPath);
$bleedingEdgePattern = '#\n\s+-(.*?)bleedingEdge\.neon[\'|"]?#';
// bleeding edge clean out, see https://github.com/rectorphp/rector/issues/2431
if (Strings::match($phpstanNeonContent, $bleedingEdgePattern)) {
$temporaryPhpstanNeon = getcwd() . '/rector-temp-phpstan.neon';
$clearedPhpstanNeonContent = Strings::replace($phpstanNeonContent, $bleedingEdgePattern);
FileSystem::write($temporaryPhpstanNeon, $clearedPhpstanNeonContent);
$phpstanPath = $temporaryPhpstanNeon;
}
// Path to phpstan with extensions, that PHPStan in Rector uses to determine types
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, $phpstanPath);
$parameters->set(Option::SETS, [
SetList::CODING_STYLE,
SetList::CODE_QUALITY,
SetList::CODE_QUALITY_STRICT,
SetList::DEAD_CODE,
SetList::PRIVATIZATION,
SetList::NAMING,
SetList::TYPE_DECLARATION,
SetList::ORDER,
SetList::PHP_71,
SetList::PHP_72,
SetList::PHP_73,
SetList::PHP_74,
SetList::PHP_80,
SetList::EARLY_RETURN,
SetList::TYPE_DECLARATION_STRICT,
SetList::PSR_4,
// SetList::SAFE_07, enable if https://github.com/thecodingmachine/safe is used
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_91,
PHPUnitSetList::PHPUNIT_EXCEPTION,
PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER,
PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD,
]);
};