PHPackages                             worksome/coding-style - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. worksome/coding-style

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

worksome/coding-style
=====================

Worksomes coding style

v3.4.0(2mo ago)49771.7k↑17.9%4[1 PRs](https://github.com/worksome/coding-style/pulls)20MITPHPPHP ^8.4CI passing

Since Mar 12Pushed 2mo ago15 watchersCompare

[ Source](https://github.com/worksome/coding-style)[ Packagist](https://packagist.org/packages/worksome/coding-style)[ RSS](/packages/worksome-coding-style/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (97)Used By (20)

Worksome Coding Style
=====================

[](#worksome-coding-style)

[![Latest Stable Version](https://camo.githubusercontent.com/76d1ffdb5e77c74931ef2d5e28dea7243d5c132bfbbb16888c4f59d13fa5a84d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776f726b736f6d652f636f64696e672d7374796c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/worksome/coding-style)[![Total Downloads](https://camo.githubusercontent.com/c177d4fb8f3f0d373269fa461fbb57d6c3692261379d2ce3f78da9b11f23c2ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776f726b736f6d652f636f64696e672d7374796c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/worksome/coding-style)[![Latest Unstable Version](https://camo.githubusercontent.com/85afbac0745eb275d863cee4b1701a70c0e30315d27990b00f1abd553b8761e8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f756e737461626c652d6465762d2d6d61696e2d6f72616e67653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/worksome/coding-style#dev-main)[![License](https://camo.githubusercontent.com/c70d4132d54d64983a2cd6d8230fe780e1488a6fc41b2e0eabe6ac6ca2039d9d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776f726b736f6d652f636f64696e672d7374796c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/worksome/coding-style)

This repository contains the coding style followed by Worksome.

It includes configuration for [ECS](https://github.com/symplify/easy-coding-standard), [PHPStan](https://phpstan.org), and [Rector](https://getrector.org).

Setup
-----

[](#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"
},
```

Usage
-----

[](#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
---------

[](#ecs-rules)

The Worksome code style extends the [PSR-12 base rule set](https://php-fig.org/psr/psr-12).

### Excluded / Skipped Rules

[](#excluded--skipped-rules)

- [`UnaryOperatorSpacesFixer`](https://cs.symfony.com/doc/rules/operator/unary_operator_spaces.html)

### Additional / Customised Rules

[](#additional--customised-rules)

> **Note:** Customised rules have a ⚙️ icon.

#### [PhpCsFixer](https://cs.symfony.com)

[](#phpcsfixer)

- [`ArraySyntaxFixer`](https://cs.symfony.com/doc/rules/array_notation/array_syntax.html)
- [`BinaryOperatorSpacesFixer` ⚙️](https://cs.symfony.com/doc/rules/operator/binary_operator_spaces.html)
- [`BlankLineBeforeStatementFixer` ⚙️](https://cs.symfony.com/doc/rules/whitespace/blank_line_before_statement.html)
- [`ClassAttributesSeparationFixer`](https://cs.symfony.com/doc/rules/class_notation/class_attributes_separation.html)
- [`ClassDefinitionFixer`](https://cs.symfony.com/doc/rules/class_notation/class_definition.html)
- [`LineEndingFixer`](https://cs.symfony.com/doc/rules/whitespace/line_ending.html)
- [`ListSyntaxFixer`](https://cs.symfony.com/doc/rules/list_notation/list_syntax.html)
- [`NoEmptyCommentFixer`](https://cs.symfony.com/doc/rules/comment/no_empty_comment.html)
- [`NoEmptyPhpdocFixer`](https://cs.symfony.com/doc/rules/phpdoc/no_empty_phpdoc.html)
- [`OperatorLinebreakFixer` ⚙️](https://cs.symfony.com/doc/rules/operator/operator_linebreak.html)
- [`OrderedImportsFixer` ⚙️](https://cs.symfony.com/doc/rules/import/ordered_imports.html)
- [`PhpdocAlignFixer` ⚙️](https://cs.symfony.com/doc/rules/phpdoc/phpdoc_align.html)
- [`PhpdocNoUselessInheritdocFixer`](https://cs.symfony.com/doc/rules/phpdoc/phpdoc_no_useless_inheritdoc.html)
- [`PhpdocSeparationFixer`](https://cs.symfony.com/doc/rules/phpdoc/phpdoc_separation.html)
- [`PhpdocTrimFixer`](https://cs.symfony.com/doc/rules/phpdoc/phpdoc_trim.html)
- [`SingleQuoteFixer`](https://cs.symfony.com/doc/rules/string_notation/single_quote.html)
- [`SingleTraitInsertPerStatementFixer`](https://cs.symfony.com/doc/rules/class_notation/single_trait_insert_per_statement.html)
- [`ShortScalarCastFixer`](https://cs.symfony.com/doc/rules/cast_notation/short_scalar_cast.html)
- [`StandardizeNotEqualsFixer`](https://cs.symfony.com/doc/rules/operator/standardize_not_equals.html)
- [`NoEmptyStatementFixer`](https://cs.symfony.com/doc/rules/semicolon/no_empty_statement.html)
- [`NoUnneededImportAliasFixer`](https://cs.symfony.com/doc/rules/import/no_unneeded_import_alias.html)
- [`NoUnusedImportsFixer`](https://cs.symfony.com/doc/rules/import/no_unused_imports.html)
- [`TrailingCommaInMultilineFixer`](https://cs.symfony.com/doc/rules/control_structure/trailing_comma_in_multiline.html)
- [`TypesSpacesFixer`](https://cs.symfony.com/doc/rules/whitespace/types_spaces.html)

#### [PHP CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer)

[](#php-codesniffer)

- [`CommentedOutCodeSniff` ⚙️](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#squizphpcommentedoutcode)
- [`ForbiddenFunctionsSniff` ⚙️](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#genericphpforbiddenfunctions)
- [`SpaceAfterNotSniff`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Formatting/SpaceAfterNotSniff.php)
- [`EndFileNewlineSniff`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php)
- [`MethodDeclarationSniff`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php)
- [`SpaceAfterCastSniff`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Formatting/SpaceAfterCastSniff.php)
- [`LowercaseDeclarationSniff`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/ControlStructures/LowercaseDeclarationSniff.php)
- [`InlineControlStructureSniff`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php)
- [`LowerCaseKeywordSniff`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php)
- [`LanguageConstructSpacingSniff`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/LanguageConstructSpacingSniff.php)

#### [Slevomat Coding Standard](https://github.com/slevomat/coding-standard)

[](#slevomat-coding-standard)

- [`ClassConstantVisibilitySniff`](https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassesclassconstantvisibility-)
- [`ClassMemberSpacingSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassesclassmemberspacing-)
- [`DisallowGroupUseSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/namespaces.md#slevomatcodingstandardnamespacesdisallowgroupuse)
- [`EmptyLinesAroundClassBracesSniff` ⚙️](https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassesemptylinesaroundclassbraces-)
- [`ForbiddenAnnotationsSniff` ⚙️](https://github.com/slevomat/coding-standard/blob/master/doc/commenting.md#slevomatcodingstandardcommentingforbiddenannotations-)
- [`MethodSpacingSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassesmethodspacing-)
- [`ModernClassNameReferenceSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassesmodernclassnamereference-)
- [`NamespaceDeclarationSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/namespaces.md#slevomatcodingstandardnamespacesnamespacedeclaration-)
- [`ParameterTypeHintSpacingSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/type-hints.md#slevomatcodingstandardtypehintsparametertypehintspacing-)
- [`PropertyDeclarationSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassespropertydeclaration-)
- [`PropertySpacingSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassespropertyspacing-)
- [`RequireMultiLineCallSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/functions.md#slevomatcodingstandardfunctionsrequiremultilinecall-)
- [`RequireMultiLineConditionSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/control-structures.md#slevomatcodingstandardcontrolstructuresrequiremultilinecondition-)
- [`RequireMultiLineMethodSignatureSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassesrequiremultilinemethodsignature-)
- [`RequireMultiLineTernaryOperatorSniff` ⚙️](https://github.com/slevomat/coding-standard/blob/master/doc/control-structures.md#slevomatcodingstandardcontrolstructuresrequiremultilineternaryoperator-)
- [`RequireOneNamespaceInFileSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/namespaces.md#slevomatcodingstandardnamespacesrequireonenamespaceinfile)
- [`RequireShortTernaryOperatorSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/control-structures.md#slevomatcodingstandardcontrolstructuresrequireshortternaryoperator-)
- [`RequireTrailingCommaInDeclarationSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/functions.md#slevomatcodingstandardfunctionsrequiretrailingcommaindeclaration-)
- [`ReturnTypeHintSpacingSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/type-hints.md#slevomatcodingstandardtypehintsreturntypehintspacing-)
- [`UselessConstantTypeHintSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/type-hints.md#slevomatcodingstandardtypehintsuselessconstanttypehint-)
- [`UselessInheritDocCommentSniff`](https://github.com/slevomat/coding-standard/blob/master/doc/commenting.md#slevomatcodingstandardcommentinguselessinheritdoccomment-)

#### [Symplify Coding Standard](https://github.com/symplify/coding-standard)

[](#symplify-coding-standard)

- [`LineLengthFixer` ⚙️](https://github.com/symplify/coding-standard/blob/main/docs/rules_overview.md#linelengthfixer)

#### [Worksome](src)

[](#worksome)

- [`ConfigFilenameKebabCaseSniff`](#config-filename-kebab-case)
- [`DisallowBladeOutsideOfResourcesDirectorySniff`](#disallow-blade-outside-the-resources-directory)
- [`DisallowCompactUsageSniff`](#disallow-compact-usage)
- [`DisallowEnvUsageSniff`](#disallow-env-usage)
- [`DisallowHasFactorySniff`](#disallow-hasfactory-usage)
- [`DisallowParamNoTypeOrCommentSniff`](#param-tags-with-no-type-or-comment)
- [`DisallowTodoCommentsSniff`](#disallow-todo-comments)
- [`EventListenerSuffixSniff`](#event-listener-suffix)
- [`ExceptionSuffixSniff`](#exception-suffix)
- [`PropertyDollarSignSniff`](#property-dollar-sign)
- [`PascalCasingEnumCasesSniff`](#pascal-casing-enum-cases)
- [`SpaceInGenericsFixer`](#space-in-generics)

Custom PHPStan rules
--------------------

[](#custom-phpstan-rules)

The Worksome code style includes the following custom PHPStan rules.

### Generic

[](#generic)

Rules that are applied to all projects.

#### [`DeclareStrictTypes`](src/PHPStan/DeclareStrictTypesRule.php)

[](#declarestricttypes)

**Identifier:** `worksome.declareStrictTypes`

This rule is used to ensure that all PHP files include with the `declare(strict_types=1)` statement.

#### [`DisallowPHPUnit`](src/PHPStan/DisallowPHPUnitRule.php)

[](#disallowphpunit)

**Identifier:** `worksome.disallowPhpunit`

This rule prevents PHPUnit tests in favour of Pest PHP. It will allow abstract `TestCase` classes.

#### [`NamespaceBasedSuffix`](src/PHPStan/NamespaceBasedSuffixRule.php)

[](#namespacebasedsuffix)

**Identifier:** `worksome.namespaceBasedSuffix`

Sets up configuration for suffixing the following namespaces

- `App\Events`: `Event`
- `App\Listener`: `Listener`
- `App\Policies`: `Policy`
- `App\Jobs`: `Job`

This makes sures events, listeners, policies and jobs has the same suffix.

### Laravel

[](#laravel)

Rules that are only applied in a Laravel context.

#### [`DisallowEnvironmentCheckRule`](src/PHPStan/Laravel/DisallowEnvironmentCheck/DisallowEnvironmentCheckRule.php)

[](#disallowenvironmentcheckrule)

**Identifier:** `worksome.laravel.disallowEnvironmentCheck`

This rule will prevent checking the application environment, instead preferring that a driver based approach is used.

#### [`EnforceKebabCaseArtisanCommandsRule`](src/PHPStan/Laravel/EnforceKebabCaseArtisanCommandsRule.php)

[](#enforcekebabcaseartisancommandsrule)

**Identifier:** `worksome.laravel.kebabCaseArtisanCommands`

This rule will enforce the use of kebab-case for Artisan commands.

#### [`RequireWithoutTimestampsRule`](src/PHPStan/Laravel/Migrations/RequireWithoutTimestampsRule.php)

[](#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
------------------------------

[](#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

[](#generic-1)

#### [Pascal-casing enum cases](src/Sniffs/Enums/PascalCasingEnumCasesSniff.php)

[](#pascal-casing-enum-cases)

This ensures that all enum cases use pascal-casing (e.g. `Case::PascalCase`).

### Laravel

[](#laravel-1)

All custom sniffs specific to Laravel.

#### [Config filename kebab case](src/Sniffs/Laravel/ConfigFilenameKebabCaseSniff.php)

[](#config-filename-kebab-case)

Checks if all config files are written in kebab case.

#### [Disallow `compact` usage](src/Sniffs/Functions/DisallowCompactUsageSniff.php)

[](#disallow-compact-usage)

Makes sure that `compact()` isn't used in code.

#### [Disallow `env` usage](src/Sniffs/Laravel/DisallowEnvUsageSniff.php)

[](#disallow-env-usage)

Makes sure that you don't use `env` helper in your code, except for config files.

#### [Disallow `HasFactory` usage](src/Sniffs/Laravel/DisallowHasFactorySniff.php)

[](#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](src/Sniffs/Laravel/EventListenerSuffixSniff.php)

[](#event-listener-suffix)

Enforces event listeners to end with a specific suffix, this suffix is defaulted to `Listener`.

parametersdefaultssuffix`Listener`#### [Disallow blade outside the `resources` directory](src/Sniffs/Laravel/DisallowBladeOutsideOfResourcesDirectorySniff.php)

[](#disallow-blade-outside-the-resources-directory)

Makes sure no `.blade.php` files exist outside of Laravel's `resources` directory.

parametersdefaultsresourcesDirectory`{YOUR_PROJECT}/resources`#### [Exception suffix](src/Sniffs/Classes/ExceptionSuffixSniff.php)

[](#exception-suffix)

This ensures that all `Exception` classes should have a suffix of `Exception`.

### PhpDoc

[](#phpdoc)

All custom sniffs which are not specific to Laravel.

#### [Property dollar sign](src/Sniffs/PhpDoc/PropertyDollarSignSniff.php)

[](#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](src/Sniffs/PhpDoc/DisallowParamNoTypeOrCommentSniff.php)

[](#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 //
