worksome / coding-style
Worksomes coding style
Package info
github.com/worksome/coding-style
Type:composer-plugin
pkg:composer/worksome/coding-style
Requires
- php: ^8.4
- composer-plugin-api: ^2.0
- laravel/pao: ^1.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.3
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-mockery: ^2.0
- rector/rector: ^2.8.1
- slevomat/coding-standard: ^8.31
- spaze/phpstan-disallowed-calls: ^4.15
- symplify/easy-coding-standard: ^13.3
Requires (Dev)
- canvural/larastan-strict-rules: ^3.0
- composer/composer: ^2.10
- friendsofphp/php-cs-fixer: ^3.95.27
- larastan/larastan: ^3.10
- orchestra/testbench: ^11.3
- pestphp/pest: ^5.3
- squizlabs/php_codesniffer: ^4.0.4
Suggests
- canvural/larastan-strict-rules: Required for the Larastan strict rules in Laravel projects.
- larastan/larastan: Required for the Laravel PHPStan rules in Laravel projects.
Provides
None
Conflicts
- canvural/larastan-strict-rules: <3.0
- larastan/larastan: <3.10
- squizlabs/php_codesniffer: >= 5
Replaces
None
- dev-main
- v6.0.1
- v6.0.0
- v5.2.0
- v5.1.0
- v5.0.0
- v4.0.1
- v4.0.0
- v3.4.0
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.1
- v3.1.0
- v3.0.0
- v2.15.0
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.0
- v2.10.2
- v2.10.1
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.1
- v2.5.0
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v1.1.0
- v1.0.0
- v0.29.0
- v0.28.0
- v0.27.0
- v0.26.0
- v0.25.0
- v0.24.1
- v0.24.0
- v0.23.0
- v0.22.0
- v0.21.2
- v0.21.1
- v0.21.0
- v0.20.0
- v0.19.0
- v0.18.0
- v0.17.0
- v0.16.0
- v0.15.0
- v0.14.0
- v0.13.0
- v0.12.1
- v0.12.0
- v0.11.0
- v0.10.0
- v0.9.0
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-bugfix/illuminate-str-dependency
- dev-feature/extension-installer
- dev-JIRA-16089_legacy-collection-type
- dev-feature/todo-comments-phpstan
This package is auto-updated.
Last update: 2026-10-27 15:21:16 UTC
README
This repository contains the coding style followed by Worksome.
It includes configuration for ECS, PHPStan, and Rector.
Setup
Install this Composer package:
composer require --dev worksome/coding-style
Run the generate command for generating the config files:
composer generate-coding-style-stubs
Add the following section to your composer.json file:
"scripts": { "ecs": "vendor/bin/ecs", "ecs:fix": "vendor/bin/ecs --fix", "phpstan": "vendor/bin/phpstan analyse", "rector": "vendor/bin/rector process --dry-run --ansi", "rector:fix": "vendor/bin/rector process --ansi" },
PHPStan
PHPStan extensions are registered via phpstan/extension-installer, which is installed
alongside this package. Allow the plugin when prompted by Composer, or add it to your composer.json file:
"config": { "allow-plugins": { "phpstan/extension-installer": true } }
The Worksome rules, along with the PHPStan extensions this package depends on, are then loaded automatically.
Laravel projects should also install Larastan and the Larastan strict rules:
composer require --dev larastan/larastan canvural/larastan-strict-rules
The Laravel rules (and Larastan within the Rector config) are only loaded when Larastan is installed, and the strict
rules are only loaded when both packages are installed. Packages listed in the extension installer's ignore option
are treated as not installed.
Note: Do not include the configuration files of any PHPStan extension that is registered with the extension installer (e.g.
vendor/larastan/larastan/extension.neonorvendor/worksome/coding-style/larastan.neon) in yourphpstan.neonfile. PHPStan will fail if a file is included more than once.
Usage
To use it, simply run one of the scripts added to composer.
$ composer ecs
$ composer ecs:fix
$ composer phpstan
$ composer rector
$ composer rector:fix
ECS Rules
The Worksome code style extends the PSR-12 base rule set.
Additional / Customised Rules
Note: Customised rules have a ⚙️ icon.
PhpCsFixer
ArraySyntaxFixerBinaryOperatorSpacesFixer⚙️BlankLineBeforeStatementFixer⚙️ClassAttributesSeparationFixerClassDefinitionFixerLineEndingFixerListSyntaxFixerNoEmptyCommentFixerNoEmptyPhpdocFixerOperatorLinebreakFixer⚙️OrderedImportsFixer⚙️PhpdocAlignFixer⚙️PhpdocNoUselessInheritdocFixerPhpdocSeparationFixerPhpdocTrimFixerSingleQuoteFixerSingleTraitInsertPerStatementFixerShortScalarCastFixerStandardizeNotEqualsFixerNoEmptyStatementFixerNoUnneededImportAliasFixerNoUnusedImportsFixerTrailingCommaInMultilineFixerTypesSpacesFixerUnaryOperatorSpacesFixer
PHP CodeSniffer
CommentedOutCodeSniff⚙️ForbiddenFunctionsSniff⚙️SpaceAfterNotSniffEndFileNewlineSniffMethodDeclarationSniffSpaceAfterCastSniffLowercaseDeclarationSniffInlineControlStructureSniffLowerCaseKeywordSniffLanguageConstructSpacingSniff
Slevomat Coding Standard
ClassConstantVisibilitySniffClassMemberSpacingSniffDisallowGroupUseSniffEmptyLinesAroundClassBracesSniff⚙️ForbiddenAnnotationsSniff⚙️MethodSpacingSniffModernClassNameReferenceSniffNamespaceDeclarationSniffParameterTypeHintSpacingSniffPropertyDeclarationSniffPropertySpacingSniffRequireMultiLineCallSniffRequireMultiLineConditionSniffRequireMultiLineMethodSignatureSniffRequireMultiLineTernaryOperatorSniff⚙️RequireOneNamespaceInFileSniffRequireShortTernaryOperatorSniffRequireTrailingCommaInDeclarationSniffReturnTypeHintSpacingSniffUselessConstantTypeHintSniffUselessInheritDocCommentSniff
Symplify Coding Standard
Worksome
ConfigFilenameKebabCaseSniffDisallowBladeOutsideOfResourcesDirectorySniffDisallowCompactUsageSniffDisallowEnvUsageSniffDisallowHasFactorySniffDisallowParamNoTypeOrCommentSniffDisallowTodoCommentsSniffEventListenerSuffixSniffExceptionSuffixSniffPropertyDollarSignSniffPascalCasingEnumCasesSniffSpaceInGenericsFixer
Custom PHPStan rules
The Worksome code style includes the following custom PHPStan rules.
Generic
Rules that are applied to all projects.
DeclareStrictTypes
Identifier: worksome.declareStrictTypes
This rule is used to ensure that all PHP files include with the declare(strict_types=1) statement.
DisallowPHPUnit
Identifier: worksome.disallowPhpunit
This rule prevents PHPUnit tests in favour of Pest PHP. It will allow abstract TestCase classes.
NamespaceBasedSuffix
Identifier: worksome.namespaceBasedSuffix
Sets up configuration for suffixing the following namespaces
App\Events:EventApp\Listener:ListenerApp\Policies:PolicyApp\Jobs:Job
This makes sures events, listeners, policies and jobs has the same suffix.
Laravel
Rules that are only applied in a Laravel context.
DisallowEnvironmentCheckRule
Identifier: worksome.laravel.disallowEnvironmentCheck
This rule will prevent checking the application environment, instead preferring that a driver based approach is used.
EnforceKebabCaseArtisanCommandsRule
Identifier: worksome.laravel.kebabCaseArtisanCommands
This rule will enforce the use of kebab-case for Artisan commands.
RequireWithoutTimestampsRule
Identifier: worksome.laravel.requireWithoutTimestamps
This rule enforces that all update, insert, save, saveQuietly, delete, restore, method calls within Laravel migration files are properly enclosed in a withoutTimestamps() context.
Custom PHP_CodeSniffer sniffs
The Worksome code style includes various custom PHP_CodeSniffer sniffs where auto-fixers via PHP CS Fixer are not possible.
Generic
Pascal-casing enum cases
This ensures that all enum cases use pascal-casing (e.g. Case::PascalCase).
Laravel
All custom sniffs specific to Laravel.
Config filename kebab case
Checks if all config files are written in kebab case.
Disallow compact usage
Makes sure that compact() isn't used in code.
Disallow env usage
Makes sure that you don't use env helper in your code, except for config files.
Disallow HasFactory usage
Ensures that the HasFactory trait is not used on models, this ensures that the factory class is called directly.
Event listener suffix
Enforces event listeners to end with a specific suffix, this suffix is defaulted to Listener.
| parameters | defaults |
|---|---|
| suffix | Listener |
Disallow blade outside the resources directory
Makes sure no .blade.php files exist outside of Laravel's resources directory.
| parameters | defaults |
|---|---|
| resourcesDirectory | {YOUR_PROJECT}/resources |
Exception suffix
This ensures that all Exception classes should have a suffix of Exception.
PhpDoc
All custom sniffs which are not specific to Laravel.
Property dollar sign
Makes sure that you always have a dollar sign in your properties defined in phpdoc.
/** * @property string $name */ class User {}
Param tags with no type or comment
This removes all @param tags which has not specified a type or comment.
/** * @param string $name * @param $type some random type * @param $other // <-- will be removed */ public function someMethod($name, $type, $other): void {}
This is mainly because PHPStan requires this before it sees the property as valid.
Disallow TODO comments
This ensures that all to-do comments are blocked from use. Jira should be used instead.
Space in generics
This ensures that generics types in PHPDoc comments contain a single space after the comma.
Custom Rector rules
The Worksome code style includes custom Rector rules for automatically refactoring code.
Generic
Disallowed Attributes
This ensures that specified PHP attributes are automatically removed when they are not allowed.
Credits
- Worksome
- Kuba Werłos for the initial code for
SpaceInGenericsFixer - All Contributors