diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..37cfad7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..369c021 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +/.github export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2130d09 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.idea +/vendor +composer.lock diff --git a/CodingStandard/ruleset.xml b/CodingStandard/ruleset.xml new file mode 100644 index 0000000..d308062 --- /dev/null +++ b/CodingStandard/ruleset.xml @@ -0,0 +1,16 @@ + + + Backdevs Coding Standard. + + ../autoload-standalone.php + + + + + + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..030c47a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Backdevs + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..292f703 --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ +# Backdevs' PHP Coding Standard + +A [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) coding standard and other static analysis tools configuration files for Backdevs' PHP projects. + +## Included default configurations +- [PHP_CodeSniffer](./phpcs/phpcs.xml) +- [PHP Mess Detector](./phpmd/phpmd.xml) + +## Installation + +Composer: +```shell +composer require --dev backdevs/coding-standard +``` + +## Usage + +### PHP_CodeSniffer: + +In your project's `phpcs.xml` file add the following line: +```xml + +``` + +If you don't have a `phpcs.xml` file, here's an example for a Laravel project: +```xml + + + Backdevs Coding Standard. + + + + + + + app + bootstrap + config + database + routes + tests + + cache/* + + + +``` + +Now you should be able to run: +```shell +vendor/bin/phpcs +``` + +### PHP Mess Detector: +If you don't have the `phpmd/phpmd` package installed, you can install it by running: +```shell +composer require --dev phpmd/phpmd +``` + +Then, in your project's `phpmd.xml` file add the following line: +```xml + +``` + +If you don't have a `phpmd.xml` file, here's a simple example: +```xml + + + Backdevs Coding Standard. + + + +``` + +Now you can run: +```shell +vendor/bin/phpmd app,bootstrap,config,database,routes,tests text phpmd.xml +``` diff --git a/autoload-standalone.php b/autoload-standalone.php new file mode 100644 index 0000000..753ae67 --- /dev/null +++ b/autoload-standalone.php @@ -0,0 +1,11 @@ + + + Backdevs PHP_CodeSniffer default configuration. + + + + + + + + + + diff --git a/phpcs/rulesets/base.xml b/phpcs/rulesets/base.xml new file mode 100644 index 0000000..c1aa361 --- /dev/null +++ b/phpcs/rulesets/base.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + + diff --git a/phpcs/rulesets/psr.xml b/phpcs/rulesets/psr.xml new file mode 100644 index 0000000..1eff604 --- /dev/null +++ b/phpcs/rulesets/psr.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/phpcs/rulesets/slevomat.xml b/phpcs/rulesets/slevomat.xml new file mode 100644 index 0000000..ef0ee62 --- /dev/null +++ b/phpcs/rulesets/slevomat.xml @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + tests/*/*Test.php + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpmd/phpmd.xml b/phpmd/phpmd.xml new file mode 100644 index 0000000..9e108c6 --- /dev/null +++ b/phpmd/phpmd.xml @@ -0,0 +1,83 @@ + + + Backdevs PHPMD default configuration. + + + tests/ + vendor/ + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +