Worksomes coding style

Installs: 514 085

Dependents: 29

Suggesters: 0

Security: 0

Stars: 46

Watchers: 17

Forks: 3

Open Issues: 0


v2.11.0 2024-06-25 08:29 UTC


Worksome Coding Style

Latest Stable Version Total Downloads Latest Unstable Version License

This repository contains the coding style followed by Worksome.

It includes configuration for ECS, PHPStan, and Rector.


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"


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.

Excluded / Skipped Rules

Additional / Customised Rules

Note: Customised rules have a ⚙️ icon.


PHP CodeSniffer

Slevomat Coding Standard

Symplify Coding Standard


Custom PHPStan rules

The Worksome code style includes the following custom PHPStan rules.


Rules that are applied to all projects.


Identifier: worksome.declareStrictTypes

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


Identifier: worksome.disallowPhpunit

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


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.


Rules that are only applied in a Laravel context.


Identifier: worksome.laravel.disallowEnvironmentCheck

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


Identifier: worksome.laravel.disallowPartialRouteResource

This rule disallows the usage of the Route::resource method when combined with only or except. Instead, partial route resources should be split into multiple routes.


Identifier: worksome.laravel.disallowPartialRouteResource

Similar to DisallowPartialRouteVariableResourceRule, but prevents partial resource usage when used in a route group.


Identifier: worksome.laravel.kebabCaseArtisanCommands

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

Custom PHP_CodeSniffer sniffs

The Worksome code style includes various custom PHP_CodeSniffer sniffs where auto-fixers via PHP CS Fixer are not possible.


Pascal-casing enum cases

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


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.


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.


Disallowed Attributes

This ensures that specified PHP attributes are automatically removed when they are not allowed.