shopsys / coding-standards
Coding standards definition compatible with PSR-2
Requires
- php: ^8.3
- ext-tokenizer: *
- friendsofphp/php-cs-fixer: ^3.58.1
- nette/utils: ^3.1.3
- php-parallel-lint/php-parallel-lint: ^1.3.1
- phpstan/phpstan: ^1.11.7
- slevomat/coding-standard: ^8.13.1
- squizlabs/php_codesniffer: ^3.6.2
- symfony/finder: ^5.4
- symplify/easy-coding-standard: ^12.2.0
Requires (Dev)
- nikic/php-parser: ^5.1
- phpunit/phpunit: ^11.2.1
Suggests
- zalas/phpunit-injector: Needed if you want to use PhpStan extension to understand injected dependencies in tests
- 16.0.x-dev
- 15.0.x-dev
- v15.0.0
- 14.0.x-dev
- v14.0.1
- v14.0.0
- 13.0.x-dev
- v13.0.0
- 12.1.x-dev
- 12.0.x-dev
- v12.0.0
- v11.1.0
- dev-master / 11.0.x-dev
- v11.0.0
- 10.0.x-dev
- v10.0.5
- v10.0.4
- v10.0.3
- v10.0.2
- v10.0.1
- v10.0.0
- 9.1.x-dev
- v9.1.3
- v9.1.2
- v9.1.1
- v9.1.0
- 9.0.x-dev
- v9.0.4
- v9.0.3
- v9.0.2
- v9.0.1
- v9.0.0
- 8.1.x-dev
- v8.1.2
- v8.1.1
- v8.1.0
- 8.0.x-dev
- v8.0.0
- 7.3.x-dev
- v7.3.7
- v7.3.6
- v7.3.5
- v7.3.4
- v7.3.3
- v7.3.2
- v7.3.1
- v7.3.0
- 7.2.x-dev
- v7.2.2
- v7.2.1
- v7.2.0
- 7.1.x-dev
- v7.1.1
- v7.1.0
- 7.0.x-dev
- v7.0.1
- v7.0.0
- v7.0.0-beta6
- v7.0.0-beta5
- v7.0.0-beta4
- v7.0.0-beta3
- v7.0.0-beta2
- v7.0.0-beta1
- v7.0.0-alpha6
- v7.0.0-alpha5
- v7.0.0-alpha4
- v7.0.0-alpha3
- v7.0.0-alpha2
- v7.0.0-alpha1
- v4.0
- v3.x-dev
- v3.1.1
- v3.1.0
- v3.0.2
- v3.0.1
- v3.0.0
- v2.0.1
- v2.0.0
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
- dev-alpha
- dev-tl-fix-using-wrong-classes
- dev-tl-convertim-backend
- dev-pt-yaml-standards-vol-2
- dev-rc-12-0-0
- dev-tl-fix-failing-12-0-builds
- dev-mg-js-translations-fix
- dev-mg-split-repo
- dev-rc-11-1-0
- dev-mg-deployment
- dev-mg-remove-manifests
- dev-mg-project-cold-fusion
- dev-rc-11-0-0
- dev-tl-fix-project-base
- dev-rk-fw-uprage-from-10-to-11-part-3
- dev-rc-v9-1-3
- dev-test-composer-from-91
- dev-rk-fw-1019-api-query-name-in-symfony-profiler
- dev-rk-fw-uprage-from-10-to-11-part-2
- dev-rc-10-0-3
- dev-rc-10-0-4
- dev-rc-10-0-5
- dev-mg-release-lock
- dev-rk-fw-uprage-from-10-to-11-part-1
- dev-rc-10-0-1
- dev-rc-10-0-2
- dev-mg-fw-933-remove-rootdir
- dev-mg-remove-twig-extension
- dev-rc-10-0-0
- dev-mg-upgrade-php8
- dev-mg-remove-be-api-integration
- dev-rv-fw-837-doctrine-upgrade
- dev-rv-fw-847-migrations-tests
- dev-mg-drop-72-packages
- dev-mg-improve-entity-extension
- dev-rv-fw-810-fix-actions
- dev-rv-test-conflict
- dev-mg-fix-phpstan-packages
- dev-mg-force-proxy-manager-version
- dev-mg-update-node
- dev-origin/tl-phpstan-all-packages
- dev-rc-v9-1-2
- dev-mg-allow-dependency
- dev-rc-v7-3-7
- dev-tl-release-9-1-1
- dev-tl-remove-package-builder
- dev-ds-coding-standards-allow-symfony-5-higher
- dev-tl-github-actions-for-packages
- dev-mg-update-helios-elfinder
- dev-tl-github-actions
- dev-ds-fix-ecs
- dev-tp-allow-coding-standards-for-symfony5
- dev-mg-php74-only
- dev-rc-v9-1-0
- dev-tl-fix-docker-limits
- dev-ds-more-coding-standards
- dev-rc-v9-0-3
- dev-rc-v9-0-4
- dev-ds-ecs-path-fix
- dev-ds-eof-new-line
- dev-tl-fix-phpstan
- dev-ds-phpstan-lvl-5
- dev-ds-fixed-framework-standaards
- dev-rc-v9-0-1
- dev-rc-v9-0-2
- dev-tl-add-psr-14
- dev-rc-v8-1-2
- dev-rc-v9-0-0
- dev-tl-fix-current-customer-user
- dev-rc-v7-3-4
- dev-rc-v7-3-5
- dev-rc-v7-3-6
- dev-tp-js-fixes
- dev-vitek-rostislav-patch-3
- dev-tg-grunt-webpack
- dev-tp-symfony4
- dev-rv-eur-on-first-domain
- dev-tp-update-composer
- dev-rc-v7-3-3
- dev-ds-easier-elastic-extensebility
- dev-rc-v8-1-1
- dev-tp-npm-link
- dev-rc-v8-1-0
- dev-mg-weird-flex-but-ok
- dev-ds-fix-project-base-dependency
- dev-ds-fix-sed-macos
- dev-mg-graphql-categories
- dev-ds-kubernetes-simplify
- dev-tl-rv-datafixtures-refactoring
- dev-ds-kubernetes-simplify-test
- dev-rv-extended-classes-fixer
- dev-rv-phpstan-lvl4
- dev-ds-test-install-script-automatically
- dev-rc-8-0-0
- dev-ss-api-import-products
- dev-ss-api-separated-from-default-project-base
- dev-do-elastic-structure-deploy
- dev-do-version-lock
- dev-mg-fix-k8s-https
- dev-ph-price-calculation
- dev-ph-redis-clients
- dev-rc-v7-3-0
- dev-tl-fix-tests-bc-break
- dev-tl-removed-tests-bc-break
- dev-tl-united-non-bc-break-service-injections
- dev-ss-tl-api-products
- dev-bb-multidomain-sitemap
- dev-ph-phing-test
- dev-tl-end-support-php-71
- dev-bb-flysystem-volume-driver
- dev-bb-initcontainer-owner-fix
- dev-do-mg-mail-attachments
- dev-do-phpstan-upgrade
- dev-rv-read-model-bck
- dev-bb-ecs-hotfix
- dev-jg-redis-cache
- dev-mg-elastic-filtering
- dev-rv-upgrade-ecs
- dev-rv-better-php-doc-parser-config
- dev-jg-form-ordering
- dev-do-fixtures-project-base
- dev-mg-multiple-cron
- dev-mc-cdn-bucket
- dev-sspooky13-pt-yaml-standards
- dev-do-product-export-fix
- dev-mc-ph-google-cloud-bundle
This package is auto-updated.
Last update: 2024-12-13 13:20:18 UTC
README
Shopsys Coding Standards are based on PSR-2.
This project bundles tools along with predefined rulesets for automated checks of Shopsys Coding Standards that we use in many Shopsys projects. The repository also contains few custom rules.
This repository is maintained by shopsys/shopsys monorepo, information about changes is in monorepo CHANGELOG.md.
Provided tools:
- PHP-Parallel-Lint
- EasyCodingStandard that combines PHP-CS-Fixer and PHP_CodeSniffer
For further information see official documentation of those tools.
Installation
php composer require shopsys/coding-standards
Usage
Create easy-coding-standard.yml
config file in your project which includes predefined ruleset.
You can also customize the rules
and even add your own sniffs and fixers in the config.
#easy-coding-standard.yml imports: - { resource: '%vendor_dir%/shopsys/coding-standards/easy-coding-standard.yml' }
In terminal, run following commands:
php vendor/bin/parallel-lint /path/to/project php vendor/bin/ecs check /path/to/project --config=/path/to/project/custom-coding-standard.yml
Custom rules
Rules for PHP-CS-Fixer
Shopsys/missing_button_type
All <button>
HTML tags in .html
and .html.twig
files must have explicit type
attribute.
If the type
is not specified it will be fixed to type="button""
because the implicit value is submit
which makes it behave differently based on the context (<button>
inside <form>
element submits the form).
Shopsys/orm_join_column_require_nullable
Doctrine annotations @ORM\ManyToOne
and @ORM\OneToOne
must have nullable
option defined explicitly in @ORM\JoinColumn
.
If the nullable
option is not specified it will be fixed to nullable=false
because the implicit value is true
but this is the opposite to the implicit value of nullable
for @Column
annotation.
This makes it consistent.
Rules for PHP_CodeSniffer
ForbiddenExitSniff
Function exit()
is not allowed.
ForbiddenSuperGlobalSniff
Usage of superglobals ($_COOKIE
, $_GET
, $_FILES
, $_POST
, $_REQUEST
, $_SERVER
) is not allowed.
ObjectIsCreatedByFactorySniff
Instantiation of objects that can be created by their factories is not allowed outside of the factory.
ValidVariableNameSniff
Default \PHP_CodeSniffer\Standards\Squiz\Sniffs\NamingConventions\ValidVariableNameSniff
does not report method parameters in $_var
format as an violation but it should.
It also skips checking of private members when PrivateNoUnderscore
property is disabled.
This sniff provides the missing functionality and is intended to be used as an addition to the default ValidVariableNameSniff
.
Contributing
Thank you for your contributions to Shopsys Coding Standards package. Together we are making Shopsys Platform better.
This repository is READ-ONLY. If you want to report issues and/or send pull requests, please use the main Shopsys repository.
Please, check our Contribution Guide before contributing.
Support
What to do when you are in troubles or need some help? The best way is to join our Slack.
If you want to report issues, please use the main Shopsys repository.