worksome / code-sniffer
Worksome's preferences and custom sniffers for phpcs
Installs: 288 459
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 15
Forks: 1
Open Issues: 0
Type:phpcodesniffer-standard
Requires
- php: ^8.0
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.0
- illuminate/collections: ^8.78 || ^9.0
- illuminate/contracts: ^8.78 || ^9.0
- illuminate/support: ^8.78 || ^9.0
- slevomat/coding-standard: ^8.5
- squizlabs/php_codesniffer: ^3.6.1
- thecodingmachine/safe: ^2.0
Requires (Dev)
- pestphp/pest: ^1.21
- symfony/var-dumper: ^5.3
This package is auto-updated.
Last update: 2022-10-29 14:34:55 UTC
README
⚠️ Deprecated in favor of coding-style package ⚠️
Worksome's custom sniffs
This package contains all of Worksome's custom sniffs and configuration.
composer require worksome/code-sniffer --dev
Usage
Create a phpcs.xml
in the root of your project with content like the following
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="YourCompany"> <description>YourCompany Coding Standard</description> <file>./app</file> <file>./tests</file> <file>./config</file> <arg name="colors"/> <arg name="parallel" value="75"/> <!-- Adds all of Worksome's coding style --> <rule ref="WorksomeSniff"/> </ruleset>
Run phpcs for seeing if you have any errors
vendor/bin/phpcs
Or run phpcbf for automatically fixing the errors when possible
vendor/bin/phpcbf
We suggest adding the commands as scripts in your composer.json
for easier execution.
... "scripts": { "phpcs": "vendor/bin/phpcs", "phpcbf": "vendor/bin/phpcbf" } ...
This way you can now execute them via composer
$ composer phpcs
$ composer phpcbf
Custom sniffs
List all the custom sniffs created by Worksome.
Laravel
All custom sniffs specific to Laravel.
Config filename kebab case
Checks if all config files are written in kebab case.
Disallow env usage
Makes sure that you don't use env
helper in your code, except for config files.
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 of the resources
directory
Makes sure no .blade.php
files exist outside of Laravel's resources
directory.
parameters | defaults |
---|---|
resourcesDirectory | {YOUR_PROJECT}/resources |
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 no 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.