PHPackages                             pekral/phpcs-rules - 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. [DevOps &amp; Deployment](/categories/devops)
4. /
5. pekral/phpcs-rules

ActivePhpcodesniffer-standard[DevOps &amp; Deployment](/categories/devops)

pekral/phpcs-rules
==================

Custom ruleset for PHP\_CodeSniffer (PHPCS) with additional rules and configuration, based on Slevomat Coding Standard. Helps to enforce consistent code style and best practices in PHP projects.

0.4.8(2mo ago)19.6k5MITPHPPHP ^8.4CI passing

Since Jan 9Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/pekral/phpcs-rules)[ Packagist](https://packagist.org/packages/pekral/phpcs-rules)[ Docs](https://github.com/pekral/phpcs-rules)[ GitHub Sponsors](https://github.com/sponsors/pekral)[ RSS](/packages/pekral-phpcs-rules/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (15)Used By (5)

phpcs-rules
===========

[](#phpcs-rules)

[![Latest Version](https://camo.githubusercontent.com/2a991e15748ab86812edcb83d7792c60a8a125b1e4300af9559c73d47c42516a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70656b72616c2f70687063732d72756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pekral/phpcs-rules)[![License](https://camo.githubusercontent.com/e2d49fd79332a7a9fdaff2261b36b37a55149d10e7bc0a03c66d10462fe14968/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70656b72616c2f70687063732d72756c65732e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Downloads](https://camo.githubusercontent.com/0039ca3889b5e647ce588830bfa48555ad23750d1286a95bff1fbc6659ba38f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70656b72616c2f70687063732d72756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pekral/phpcs-rules)

---

🚀 Introduction
--------------

[](#-introduction)

**phpcs-rules** is an extensible package of custom rules for [PHP\_CodeSniffer (PHPCS)](https://github.com/squizlabs/PHP_CodeSniffer), based on the [Slevomat Coding Standard](https://github.com/slevomat/coding-standard). It helps you maintain consistent code style and high code quality in your PHP projects.

---

📦 Installation
--------------

[](#-installation)

```
composer require --dev pekral/phpcs-rules
```

---

⚙️ Usage
--------

[](#️-usage)

1. Add a `ruleset.xml` file to your project or use the one provided in this package.
2. Run PHPCS with this ruleset:

```
vendor/bin/phpcs --standard=vendor/pekral/phpcs-rules/ruleset.xml src/
```

---

📝 Usage Examples
----------------

[](#-usage-examples)

### Code check

[](#code-check)

```
vendor/bin/phpcs --standard=vendor/pekral/phpcs-rules/ruleset.xml src/
```

### Automatic fix

[](#automatic-fix)

```
vendor/bin/phpcbf --standard=vendor/pekral/phpcs-rules/ruleset.xml src/
```

### Example configuration (ruleset.xml)

[](#example-configuration-rulesetxml)

```

```

---

⚙️ Configuration
----------------

[](#️-configuration)

- Rules can be extended and customized in `ruleset.xml`.
- Supports PHP 8.4+.
- Easy integration with CI/CD (GitHub Actions, GitLab CI, ...).

---

📋 Used Rules
------------

[](#-used-rules)

This package includes the following coding standard rules:

### Arrays

[](#arrays)

RuleDescription`SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys`Ensures array keys are sorted alphabetically`SlevomatCodingStandard.Arrays.ArrayAccess`Enforces consistent array access syntax`SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation`Prevents implicit array creation`SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed`Disallows partially keyed arrays`SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement`Controls multi-line array bracket placement`SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace`Enforces whitespace rules for single-line arrays`SlevomatCodingStandard.Arrays.TrailingArrayComma`Requires trailing commas in multi-line arrays### Attributes

[](#attributes)

RuleDescription`SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing`Controls spacing around attributes and targets`SlevomatCodingStandard.Attributes.AttributesOrder`Enforces alphabetical ordering of attributes`SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment`Requires attributes to be placed after doc comments### Classes

[](#classes)

RuleDescription`SlevomatCodingStandard.Classes.BackedEnumTypeSpacing`Controls spacing in backed enums`SlevomatCodingStandard.Classes.ClassConstantVisibility`Enforces visibility declarations for class constants`SlevomatCodingStandard.Classes.ClassLength`Limits class length (max 500 lines, excludes tests)`SlevomatCodingStandard.Classes.ClassMemberSpacing`Controls spacing between class members`SlevomatCodingStandard.Classes.ClassStructure`Enforces class structure rules`SlevomatCodingStandard.Classes.ConstantSpacing`Controls spacing around constants`SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants`Prevents late static binding for constants`SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces`Controls empty lines around class braces`SlevomatCodingStandard.Classes.EnumCaseSpacing`Controls spacing in enum cases`SlevomatCodingStandard.Classes.ForbiddenPublicProperty`Disallows public properties`SlevomatCodingStandard.Classes.MethodSpacing`Controls spacing between methods`SlevomatCodingStandard.Classes.ModernClassNameReference`Enforces modern class name references`SlevomatCodingStandard.Classes.ParentCallSpacing`Controls spacing around parent calls`SlevomatCodingStandard.Classes.PropertyDeclaration`Enforces property declaration rules`SlevomatCodingStandard.Classes.PropertySpacing`Controls spacing around properties`SlevomatCodingStandard.Classes.RequireAbstractOrFinal`Requires classes to be abstract or final`SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion`Enforces constructor property promotion`SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature`Requires multi-line method signatures for long lines`SlevomatCodingStandard.Classes.RequireSelfReference`Enforces self references`SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature`Requires single-line method signatures for short lines`SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming`Prevents superfluous abstract class naming`SlevomatCodingStandard.Classes.SuperfluousErrorNaming`Prevents superfluous error naming`SlevomatCodingStandard.Classes.SuperfluousExceptionNaming`Prevents superfluous exception naming`SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming`Prevents superfluous interface naming`SlevomatCodingStandard.Classes.SuperfluousTraitNaming`Prevents superfluous trait naming`SlevomatCodingStandard.Classes.TraitUseDeclaration`Enforces trait use declaration rules`SlevomatCodingStandard.Classes.TraitUseSpacing`Controls spacing around trait uses`SlevomatCodingStandard.Classes.UselessLateStaticBinding`Prevents useless late static binding### Commenting

[](#commenting)

RuleDescription`SlevomatCodingStandard.Commenting.AnnotationName`Enforces annotation naming conventions`SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration`Controls deprecated annotation declarations`SlevomatCodingStandard.Commenting.DisallowCommentAfterCode`Prevents comments after code`SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment`Disallows one-line property doc comments`SlevomatCodingStandard.Commenting.DocCommentSpacing`Controls doc comment spacing`SlevomatCodingStandard.Commenting.EmptyComment`Prevents empty comments`SlevomatCodingStandard.Commenting.ForbiddenAnnotations`Disallows forbidden annotations`SlevomatCodingStandard.Commenting.ForbiddenComments`Disallows forbidden comments`SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration`Enforces inline doc comment declarations`SlevomatCodingStandard.Commenting.UselessFunctionDocComment`Prevents useless function doc comments`SlevomatCodingStandard.Commenting.UselessInheritDocComment`Prevents useless inherit doc comments### Complexity

[](#complexity)

RuleDescription`SlevomatCodingStandard.Complexity.Cognitive`Limits cognitive complexity (warning/error threshold: 9)### Control Structures

[](#control-structures)

RuleDescription`SlevomatCodingStandard.ControlStructures.AssignmentInCondition`Prevents assignments in conditions`SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing`Controls spacing around control structures`SlevomatCodingStandard.ControlStructures.DisallowEmpty`Disallows empty control structures`SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch`Prevents continue without integer operand in switch`SlevomatCodingStandard.ControlStructures.DisallowTrailingMultiLineTernaryOperator`Disallows trailing multi-line ternary operators`SlevomatCodingStandard.ControlStructures.DisallowYodaComparison`Disallows Yoda comparisons`SlevomatCodingStandard.ControlStructures.EarlyExit`Enforces early exit patterns`SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing`Controls spacing around jump statements`SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses`Requires parentheses with language constructs`SlevomatCodingStandard.ControlStructures.NewWithParentheses`Requires parentheses with new operator`SlevomatCodingStandard.ControlStructures.RequireMultiLineCondition`Requires multi-line conditions for long lines`SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator`Requires multi-line ternary operators for long lines`SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator`Enforces null coalesce equal operator`SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator`Enforces null coalesce operator`SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator`Enforces null safe object operator`SlevomatCodingStandard.ControlStructures.RequireShortTernaryOperator`Enforces short ternary operators`SlevomatCodingStandard.ControlStructures.RequireSingleLineCondition`Requires single-line conditions for short lines`SlevomatCodingStandard.ControlStructures.RequireTernaryOperator`Enforces ternary operators`SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn`Prevents useless if conditions with return`SlevomatCodingStandard.ControlStructures.UselessTernaryOperator`Prevents useless ternary operators### Exceptions

[](#exceptions)

RuleDescription`SlevomatCodingStandard.Exceptions.DeadCatch`Prevents dead catch blocks`SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly`Enforces Throwable references only`SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch`Requires non-capturing catch blocks### Files

[](#files)

RuleDescription`SlevomatCodingStandard.Files.FileLength`Limits file length (max 500 lines, excludes tests)`SlevomatCodingStandard.Files.LineLength`Limits line length (max 156 chars, ignores comments/imports)### Functions

[](#functions)

RuleDescription`SlevomatCodingStandard.Functions.ArrowFunctionDeclaration`Enforces arrow function declarations`SlevomatCodingStandard.Functions.DisallowEmptyFunction`Disallows empty functions`SlevomatCodingStandard.Functions.FunctionLength`Limits function length (max 30 lines)`SlevomatCodingStandard.Functions.DisallowTrailingCommaInClosureUse`Disallows trailing commas in closure use`SlevomatCodingStandard.Functions.NamedArgumentSpacing`Controls named argument spacing`SlevomatCodingStandard.Functions.RequireArrowFunction`Enforces arrow functions`SlevomatCodingStandard.Functions.RequireMultiLineCall`Requires multi-line calls for long lines`SlevomatCodingStandard.Functions.RequireSingleLineCall`Requires single-line calls for short lines`SlevomatCodingStandard.Functions.RequireTrailingCommaInCall`Requires trailing commas in calls`SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration`Requires trailing commas in declarations`SlevomatCodingStandard.Functions.StaticClosure`Enforces static closures`SlevomatCodingStandard.Functions.StrictCall`Enforces strict calls`SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure`Prevents unused inherited variables in closures`SlevomatCodingStandard.Functions.UnusedParameter`Prevents unused parameters`SlevomatCodingStandard.Functions.UselessParameterDefaultValue`Prevents useless parameter default values### Methods

[](#methods)

RuleDescription`PSR2.Methods.FunctionClosingBrace`Enforces PSR2 function closing brace rules`PSR2.Methods.MethodDeclaration.Underscore`Prevents underscore in method declarations### Namespaces

[](#namespaces)

RuleDescription`SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses`Enforces alphabetically sorted use statements`SlevomatCodingStandard.Namespaces.DisallowGroupUse`Disallows group use statements`SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation`Enforces fully qualified class names in annotations`SlevomatCodingStandard.Namespaces.MultipleUsesPerLine`Controls multiple uses per line`SlevomatCodingStandard.Namespaces.NamespaceDeclaration`Enforces namespace declaration rules`SlevomatCodingStandard.Namespaces.NamespaceSpacing`Controls namespace spacing`SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly`Enforces reference of used names only`SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile`Requires one namespace per file`SlevomatCodingStandard.Namespaces.UnusedUses`Prevents unused use statements`SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash`Prevents use statements starting with backslash`SlevomatCodingStandard.Namespaces.UseFromSameNamespace`Prevents use statements from same namespace`SlevomatCodingStandard.Namespaces.UseSpacing`Controls use statement spacing`SlevomatCodingStandard.Namespaces.UselessAlias`Prevents useless aliases### Naming Conventions

[](#naming-conventions)

RuleDescription`Generic.NamingConventions.CamelCapsFunctionName`Enforces camelCase function naming`PSR2.Classes.PropertyDeclaration.Underscore`Prevents underscore in property declarations`Squiz.NamingConventions.ValidFunctionName.PrivateNoUnderscore`Prevents underscore in private function names`Squiz.NamingConventions.ValidVariableName.NotCamelCaps`Enforces camelCase variable naming`Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore`Prevents underscore in private variable names### Numbers

[](#numbers)

RuleDescription`SlevomatCodingStandard.Numbers.RequireNumericLiteralSeparator`Requires numeric literal separators### Operators

[](#operators)

RuleDescription`SlevomatCodingStandard.Operators.DisallowEqualOperators`Disallows equal operators`SlevomatCodingStandard.Operators.NegationOperatorSpacing`Controls negation operator spacing`SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator`Enforces combined assignment operators`SlevomatCodingStandard.Operators.SpreadOperatorSpacing`Controls spread operator spacing`SlevomatCodingStandard.Operators.RequireOnlyStandaloneIncrementAndDecrementOperators`Enforces standalone increment/decrement operators### PHP

[](#php)

RuleDescription`SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall`Disallows direct magic invoke calls`SlevomatCodingStandard.PHP.UselessParentheses`Prevents useless parentheses`SlevomatCodingStandard.PHP.ForbiddenClasses`Disallows forbidden classes`SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking`Enforces optimized functions without unpacking`SlevomatCodingStandard.PHP.ReferenceSpacing`Controls reference spacing`SlevomatCodingStandard.PHP.RequireExplicitAssertion`Requires explicit assertions`SlevomatCodingStandard.PHP.RequireNowdoc`Enforces nowdoc syntax`SlevomatCodingStandard.PHP.ShortList`Enforces short list syntax`SlevomatCodingStandard.PHP.TypeCast`Enforces type casting rules`SlevomatCodingStandard.PHP.UselessSemicolon`Prevents useless semicolons`SlevomatCodingStandard.PHP.DisallowReference`Disallows references### Strings

[](#strings)

RuleDescription`SlevomatCodingStandard.Strings.DisallowVariableParsing`Disallows variable parsing in strings### Type Hints

[](#type-hints)

RuleDescription`SlevomatCodingStandard.TypeHints.ClassConstantTypeHint`Enforces class constant type hints`SlevomatCodingStandard.TypeHints.DeclareStrictTypes`Enforces strict types declaration`SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax`Disallows array type hint syntax`SlevomatCodingStandard.TypeHints.DNFTypeHintFormat`Enforces DNF type hint format`SlevomatCodingStandard.TypeHints.LongTypeHints`Controls long type hints`SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue`Enforces nullable types for null default values`SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition`Enforces null type hints on last position`SlevomatCodingStandard.TypeHints.ParameterTypeHint`Enforces parameter type hints`SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing`Controls parameter type hint spacing`SlevomatCodingStandard.TypeHints.PropertyTypeHint`Enforces property type hints`SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint`Enforces native type hints for properties`SlevomatCodingStandard.TypeHints.ReturnTypeHint`Enforces return type hints`SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing`Controls return type hint spacing`SlevomatCodingStandard.TypeHints.UselessConstantTypeHint`Prevents useless constant type hints### Variables

[](#variables)

RuleDescription`SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable`Disallows super global variables`SlevomatCodingStandard.Variables.DisallowVariableVariable`Disallows variable variables`SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable`Prevents duplicate assignments to variables`SlevomatCodingStandard.Variables.UnusedVariable`Prevents unused variables`SlevomatCodingStandard.Variables.UselessVariable`Prevents useless variables### Whitespace and Formatting

[](#whitespace-and-formatting)

RuleDescription`Generic.Arrays.ArrayIndent`Controls array indentation (4 spaces)`Generic.WhiteSpace.DisallowTabIndent`Disallows tab indentation`Generic.WhiteSpace.ScopeIndent`Controls scope indentation (4 spaces)`PEAR.ControlStructures.MultiLineCondition`Controls multi-line condition indentation (4 spaces)`PEAR.WhiteSpace.ObjectOperatorIndent`Controls object operator indentation (4 spaces)`SlevomatCodingStandard.Whitespaces.DuplicateSpaces`Prevents duplicate spaces`Squiz.Strings.ConcatenationSpacing`Controls concatenation spacing (1 space)`Squiz.WhiteSpace.OperatorSpacing`Controls operator spacing### External Rules

[](#external-rules)

RuleDescription`Squiz.PHP.DiscouragedFunctions`Disallows discouraged functions (dump, dd, error\_log, var\_dump, die)---

❓ FAQ
-----

[](#-faq)

**Q: How do I add a custom rule?**A: Add it to your `ruleset.xml` or extend this package.

**Q: How do I run PHPCS only on specific folders?**A: Adjust the path in the PHPCS command, e.g. `src/`, `app/`.

**Q: How can I contribute?**A: Open an issue or pull request on GitHub.

---

🔗 Further Resources
-------------------

[](#-further-resources)

- [PHP\_CodeSniffer (PHPCS)](https://github.com/squizlabs/PHP_CodeSniffer)
- [Slevomat Coding Standard](https://github.com/slevomat/coding-standard)

---

📝 License
---------

[](#-license)

This package is licensed under the [MIT license](LICENSE).

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance87

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~103 days

Recently: every ~27 days

Total

12

Last Release

84d ago

PHP version history (4 changes)0.1PHP ^8.1

0.3PHP ^8.3

0.4PHP ^8.4

0.4.3PHP ^8.4|^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/820760fa5b2ca7e1c749f0e15c0fb9b0881ddc54ce924cb083f4bb6ae2490948?d=identicon)[pekral](/maintainers/pekral)

---

Top Contributors

[![pekral](https://avatars.githubusercontent.com/u/9308589?v=4)](https://github.com/pekral "pekral (145 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

---

Tags

phpphpcsstatic analysisCode stylePHP\_CodeSniffercode qualitylintsnifferciBest-PracticesCoding Standardcomposer-packageopen-sourcerulesetpsr12slevomatcustom-ruleset

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pekral-phpcs-rules/health.svg)

```
[![Health](https://phpackages.com/badges/pekral-phpcs-rules/health.svg)](https://phpackages.com/packages/pekral-phpcs-rules)
```

###  Alternatives

[consistence/coding-standard

Consistence - Coding Standard - PHP Code Sniffer rules

75833.3k94](/packages/consistence-coding-standard)[mayflower/mo4-coding-standard

PHP CodeSniffer ruleset implementing the MO4 coding standards extending the Symfony coding standards.

17508.3k5](/packages/mayflower-mo4-coding-standard)[orisai/coding-standard

Strict PHP coding standard

19193.5k62](/packages/orisai-coding-standard)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
