narrowspark / coding-standard
The Narrowspark Coding Standard is a set of phpstan, psalm, infection, rector and php-cs-fixer rules applied to all Narrowspark projects.
Fund package maintenance!
prisis
Installs: 39 916
Dependents: 46
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 2
Open Issues: 26
Language:Dockerfile
Requires
- php: ^7.3
- ekino/phpstan-banned-code: ~0.3.1
- felixfbecker/advanced-json-rpc: ^3.1.1
- infection/infection: ~0.16.2
- jwage/changelog-generator: ~1.2.0
- narrowspark/php-cs-fixer-config: ~6.1.0
- phpstan/phpstan: ~0.12.19
- phpstan/phpstan-deprecation-rules: ~0.12.2
- phpstan/phpstan-mockery: ~0.12.4
- phpstan/phpstan-phpunit: ~0.12.8
- phpstan/phpstan-strict-rules: ~0.12.2
- psalm/plugin-mockery: ~0.3.0
- psalm/plugin-phpunit: ^0.10.0
- rector/rector: ~0.7.12
- slam/phpstan-extensions: ~5.0.0
- thecodingmachine/phpstan-strict-rules: ~0.12.0
- vimeo/psalm: ^3.11.2
Requires (Dev)
- phpunit/phpunit: ^9.1.2
- symfony/var-exporter: ^5.0.7
Suggests
- phpstan/phpstan-doctrine: doctrine extensions for PHPStan (*)
- phpstan/phpstan-php-parser: PHP-Parser extensions for PHPStan (*)
- dev-master
- 5.1.0
- 5.0.0
- 4.1.0
- 4.0.0
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.0
- 2.1.1
- 2.1.0
- 2.0.0
- 1.4.0
- 1.3.0
- 1.2.1
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-dependabot/composer/phpstan/phpstan-approx-0.12.79
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/composer/phpstan/phpstan-approx-0.12.78
- dev-dependabot/npm_and_yarn/write-good-1.0.8
- dev-dependabot/composer/phpstan/phpstan-mockery-approx-0.12.12
- dev-dependabot/npm_and_yarn/textlint-11.8.2
- dev-renovate/configure
- dev-dependabot/composer/phpunit/phpunit-tw-9.5.2
- dev-dependabot/composer/rector/rector-approx-0.9.2
- dev-dependabot/npm_and_yarn/textlint-rule-terminology-2.1.5
- dev-dependabot/composer/phpstan/phpstan-strict-rules-approx-0.12.9
- dev-dependabot/composer/felixfbecker/advanced-json-rpc-tw-3.2.0
- dev-dependabot/npm_and_yarn/ini-1.3.8
- dev-dependabot/composer/phpstan/phpstan-phpunit-approx-0.12.17
- dev-dependabot/composer/phpstan/phpstan-deprecation-rules-approx-0.12.6
- dev-dependabot/composer/psalm/plugin-phpunit-approx-0.12.2
- dev-dependabot/npm_and_yarn/textlint-rule-en-capitalization-2.0.3
- dev-dependabot/composer/vimeo/psalm-approx-3.18.2
- dev-dependabot/composer/infection/infection-approx-0.18.2
- dev-dependabot/composer/slam/phpstan-extensions-approx-5.0.2
- dev-dependabot/npm_and_yarn/node-fetch-2.6.1
- dev-dependabot/composer/thecodingmachine/phpstan-strict-rules-approx-0.12.1
- dev-dependabot/npm_and_yarn/textlint-rule-alex-3.0.0
- dev-dependabot/npm_and_yarn/dot-prop-4.2.1
- dev-dependabot/npm_and_yarn/textlint-rule-no-dead-link-4.7.0
- dev-dependabot/composer/psalm/plugin-mockery-approx-0.4.0
- dev-dependabot/composer/jwage/changelog-generator-approx-1.2.1
This package is auto-updated.
Last update: 2021-02-26 06:43:58 UTC
README
The Narrowspark Coding Standard for all Narrowspark projects.
Installation
composer require narrowspark/coding-standard
Use
PHPstan
Create a configuration file phpstan.neon
Add the rules manually or use composer require --dev phpstan/extension-installer
.
If you don’t want to use phpstan/extension-installer
, include extension.neon in your project’s PHPStan config:
includes: - vendor/narrowspark/coding-standard/base_rules.neon
Or
includes: - vendor/ekino/phpstan-banned-code/extension.neon - vendor/phpstan/phpstan-deprecation-rules/rules.neon - vendor/phpstan/phpstan-mockery/extension.neon - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon - vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/phpstan/phpstan/conf/bleedingEdge.neon - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon - vendor/slam/phpstan-extensions/conf/slam-rules.neon parameters: level: max inferPrivatePropertyTypeFromConstructor: true excludes_analyse: - vendor banned_code: # enable detection of `use Tests\Foo\Bar` in a non-test file use_from_tests: true
Follow the links to check, how to configure the rules:
PHP-CS-Fixer
Create a configuration file .php_cs
in the root of your project with this content:
<?php 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('2020'), 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__ . DIRECTORY_SEPARATOR . 'src') ->exclude('build') ->exclude('vendor') ->name('*.php') ->ignoreDotFiles(true) ->ignoreVCS(true); $cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__; $config->setCacheFile($cacheDir . '/.php_cs.cache'); return $config;
Info:
The used php-cs-fixer rules.
For more information, take a look on php-cs-fixer-config.
Psalm
Add your config with this command.
./vendor/bin/psalm --init
Now you need to add the phpunit
and mockery
plugin to the created psalm.xml
... +<plugins> + <pluginClass class="Psalm\MockeryPlugin\Plugin" /> + <pluginClass class="Psalm\PhpUnitPlugin\Plugin" /> +</plugins> ...
Infection
The first time you run Infection for your project, it will ask you questions to create a config file infection.json.dist
Changelog
Create this labels on github Added
, Changed
, Deprecated
, Removed
, Fixed
, Security
Create a configuration file .changelog
in the root of your project with this content:
<?php declare(strict_types=1); use ChangelogGenerator\ChangelogConfig; return [ (new ChangelogConfig( '{organisation name}', '{repository name}', '{your next version}', ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'] )) ];
Create a CHANGELOG.md
file and put this on the top.
# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
Info: for more information, take a look on keepachangelog.
Rector
Create rector-src.yaml
and add the configurations to it.
imports: - { resource: './vendor/thecodingmachine/safe/rector-migrate-0.7.yml' } parameters: php_version_features: '7.2' # change the php version to your used one project_type: "open-source" sets: - 'action-injection-to-constructor-injection' - 'array-str-functions-to-static-call' - 'celebrity' - 'doctrine' - 'phpstan' - 'solid' - 'early-return' - 'doctrine-code-quality' - 'dead-code' - 'code-quality' - 'type-declaration' - 'php71' - 'php72' # - 'php73' # - 'php74'
Create rector-tests.yaml
and add the configurations to it.
parameters: php_version_features: '7.2' # change the php version to your used one sets: - 'celebrity' - 'phpstan' - 'phpunit-code-quality' - 'phpunit-exception' - 'phpunit-injector' - 'phpunit-specific-method' - 'early-return' - 'dead-code' - 'code-quality' - 'type-declaration' - 'php71' - 'php72' # - 'php73' # - 'php74'
Info: for more information about existing sets and setting options, take a look on rectorphp docs.
Composer
Then edit your composer.json
file and add these scripts:
{ "scripts": { "changelog": "changelog-generator generate --config=\"./.changelog\" --file --prepend", "cs": "php-cs-fixer fix --config=\"./.php_cs\" --ansi", "cs:check": "php-cs-fixer fix --config=\"./.php_cs\" --ansi --dry-run", "phpstan": "phpstan analyse -c ./phpstan.neon --ansi", "psalm": "psalm --threads=$(nproc)", "psalm:fix": "psalm --alter --issues=all --threads=$(nproc) --ansi", "infection": "infection --configuration=\"./infection.json\" -j$(nproc) --ansi", "rector-src": "rector process ./src/ --config=./rector-src.yaml --ansi --dry-run", "rector-src:fix": "rector process ./src/ --config=./rector-src.yaml --ansi", "rector-tests": "rector process ./tests/ --config=./rector-tests.yaml --ansi --dry-run", "rector-tests:fix": "rector process ./tests/ --config=./rector-tests.yaml --ansi" } }
Tip: if some processes taking longer than the default composer
process-timeout: 300
you can add this to in your composer.json
{
"config": {
"process-timeout": 2000 #choose you needed time
}
}
Add .php_cs.cache
to your .gitignore
file.
Versioning
This library follows semantic versioning, and additions to the code ruleset are performed in major releases.
Testing
composer test
Contributing
If you would like to help take a look at the list of issues and check our CONTRIBUTING.md guide.
Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
License
The Narrowspark Coding Standard is open-sourced software licensed under the MIT license