{"id":18654782,"url":"https://github.com/wieni/wmcodestyle","last_synced_at":"2025-04-11T17:31:39.686Z","repository":{"id":46073954,"uuid":"218079728","full_name":"wieni/wmcodestyle","owner":"wieni","description":"A set of Wieni best practices, coding standards and tools to enforce them.","archived":false,"fork":false,"pushed_at":"2023-07-31T13:59:25.000Z","size":107,"stargazers_count":3,"open_issues_count":2,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-25T16:23:48.214Z","etag":null,"topics":["codestyle","configuration","php-cs-fixer","php-cs-fixer-config","php-cs-fixer-custom-fixers","php-cs-fixer-ruleset"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wieni.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-28T15:29:55.000Z","updated_at":"2023-10-20T21:54:37.000Z","dependencies_parsed_at":"2024-06-21T04:19:33.399Z","dependency_job_id":"1cd79ce4-5b34-46ed-83de-da9f653b694b","html_url":"https://github.com/wieni/wmcodestyle","commit_stats":{"total_commits":108,"total_committers":4,"mean_commits":27.0,"dds":0.07407407407407407,"last_synced_commit":"782d76a62dcf137fb49703f8b5e7c65b2a097640"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmcodestyle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmcodestyle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmcodestyle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmcodestyle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wieni","download_url":"https://codeload.github.com/wieni/wmcodestyle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999866,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codestyle","configuration","php-cs-fixer","php-cs-fixer-config","php-cs-fixer-custom-fixers","php-cs-fixer-ruleset"],"created_at":"2024-11-07T07:16:34.772Z","updated_at":"2025-04-11T17:31:34.675Z","avatar_url":"https://github.com/wieni.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"wmcodestyle\n======================\n\n[![Latest Stable Version](https://poser.pugx.org/wieni/wmcodestyle/v/stable)](https://packagist.org/packages/wieni/wmcodestyle)\n[![Total Downloads](https://poser.pugx.org/wieni/wmcodestyle/downloads)](https://packagist.org/packages/wieni/wmcodestyle)\n[![License](https://poser.pugx.org/wieni/wmcodestyle/license)](https://packagist.org/packages/wieni/wmcodestyle)\n\n\u003e A set of Wieni best practices, coding standards and tools to enforce them.\n\n## Why?\n- A central location to keep track of our written coding standards and \n best practices\n- Make configuration for tools to enforce our codestyle available in all\n  of our repositories, without having to duplicate and sync them\n  manually  \n \n## Table of Contents\n1. [Coding standards](#coding-standards-and-best-practices)\n2. [Tooling](#tooling)\n    * [Installation](#installation)\n    * [Sync config files with your project](#sync-config-files-with-your-project)\n    * [PHP-CS-Fixer](#php-cs-fixerhttpgithubcomfriendsofphpphp-cs-fixer)\n    * [Rector](#rectorhttpsgithubcomrectorphprector)\n    * [PHPStan](#phpstanhttpsgithubcomphpstanphpstan)\n    * [composer-normalize](#composer-normalizehttpsgithubcomergebniscomposer-normalize)\n    * [Running code style fixers](#running-code-style-fixers)\n3. [Changelog](#changelog)\n4. [Security](#security)\n5. [License](#license)\n6. [Acknowledgments](#acknowledgments)\n\n## Coding standards\n- [General](standards/GENERAL.md)\n- [Drupal modules](standards/DRUPAL_MODULES.md)\n- [Model–view–controller (and presenter)](standards/MVC.md)\n- [Git](standards/GIT.md)\n\n## Tooling\n### Installation\n\nThis package requires PHP 7.1 or higher and can be installed using\nComposer:\n\n```bash\n composer require --dev wieni/wmcodestyle\n```\n\n### Sync config files with your project\nThis package provides a command to sync any file from this repository to\nyour project. It is recommended to add it to the `scripts` section of\ncomposer.json so it is automatically executed at the appropriate time. \n\n```diff\n {\n   \"name\": \"foo/bar\",\n   \"require\": {\n     \"php\": \"^8.0\",\n   },\n   \"require-dev\": {\n     \"wieni/wmcodestyle\": \"^1.0\"\n+  },\n+  \"scripts\": {\n+    \"post-update-cmd\": [\n+      \"wmcodestyle sync .editorconfig --quiet\"\n+    ]\n   }\n }\n```\n\n### [PHP-CS-Fixer](http://github.com/FriendsOfPHP/PHP-CS-Fixer)\n\nThis package provides a configuration factory and multiple rule sets for\n[`friendsofphp/php-cs-fixer`](http://github.com/FriendsOfPHP/PHP-CS-Fixer).\n\n#### Configuration\n\nPick one of the rule sets:\n\n* [`Wieni\\wmcodestyle\\PhpCsFixer\\Config\\RuleSet\\Php71`](src/PhpCsFixer/Config/RuleSet/Php71.php)\n* [`Wieni\\wmcodestyle\\PhpCsFixer\\Config\\RuleSet\\Php73`](src/PhpCsFixer/Config/RuleSet/Php73.php)\n* [`Wieni\\wmcodestyle\\PhpCsFixer\\Config\\RuleSet\\Php74`](src/PhpCsFixer/Config/RuleSet/Php74.php)\n* [`Wieni\\wmcodestyle\\PhpCsFixer\\Config\\RuleSet\\Php80`](src/PhpCsFixer/Config/RuleSet/Php80.php)\n\nCreate a configuration file `.php_cs.php` in the root of your project:\n\n```php\n\u003c?php\n\nuse Wieni\\wmcodestyle\\PhpCsFixer\\Config\\Factory;\nuse Wieni\\wmcodestyle\\PhpCsFixer\\Config\\RuleSet\\Php73;\n\n$config = Factory::fromRuleSet(new Php73);\n\n$config-\u003egetFinder()\n    -\u003eignoreVCSIgnored(true)\n    -\u003ein(__DIR__)\n    -\u003ename('/\\.(php|module|inc|install|test|profile|theme)$/')\n    -\u003enotPath('/(public|web)\\/(index|update)\\.php/');\n\n$config-\u003esetCacheFile(__DIR__ . '/.cache/php_cs.cache');\n\nreturn $config;\n```\n\nBy default, risky rules are not used. To use them, pass `--allow-risky=yes` to `php-cs-fixer` or set the \n`WMCODESTYLE_RISKY=1` environment variable.\n\n#### Git\n\nAll configuration examples use the caching feature, and if you want to\nuse it as well, you should add the cache folder to `.gitignore`:\n\n```gitignore\n# Ignore files generated by wieni/wmcodestyle\n.cache\n```\n\n#### Configuration with override rules\n\n:bulb: Optionally override rules from a rule set by passing in an array of rules to be merged in:\n\n```diff\n\u003c?php\n\nuse Wieni\\wmcodestyle\\PhpCsFixer\\Config\\Factory;\nuse Wieni\\wmcodestyle\\PhpCsFixer\\Config\\RuleSet\\Php73;\n\n-$config = Factory::fromRuleSet(new Php73);\n+$config = Factory::fromRuleSet(new Php73, [\n+    'mb_str_functions' =\u003e false,\n+    'strict_comparison' =\u003e false,\n+]);\n\n$config-\u003egetFinder()\n    -\u003eignoreVCSIgnored(true)\n    -\u003ein(__DIR__)\n    -\u003ename('/\\.(php|module|inc|install|test|profile|theme)$/')\n    -\u003enotPath('/(public|web)\\/(index|update)\\.php/');\n\n$config-\u003esetCacheFile(__DIR__ . '/.php_cs.cache');\n\nreturn $config;\n```\n\n### [Rector](https://github.com/rectorphp/rector)\n\u003e Instant upgrade and refactoring of your PHP code\n\nThis package provides multiple rule sets for [rector/rector](https://github.com/rectorphp/rector). These rule sets are largely identical to the default rule sets, with the exception of a couple individual rules we don't like/need. Instead of [rector/rector](https://github.com/rectorphp/rector), [rector/rector-prefixed](https://github.com/rectorphp/rector-prefixed) is added as dependency to make it easier to include this package in your Composer project.\n\n#### Rule sets\n\nPick one of the rule sets:\n\n* [`Wieni\\wmcodestyle\\Rector\\SetList\\WieniSetList\\CODE_QUALITY`](rector/code-quality.php)\n* [`Wieni\\wmcodestyle\\Rector\\SetList\\WieniSetList\\CODING_STYLE`](rector/coding-style.php)\n* [`Wieni\\wmcodestyle\\Rector\\SetList\\WieniSetList\\DEPENDENCY_INJECTION`](rector/dependency-injection.php)\n* [`Wieni\\wmcodestyle\\Rector\\SetList\\WieniSetList\\EARLY_RETURN`](rector/early-return.php)\n* [`Wieni\\wmcodestyle\\Rector\\SetList\\WieniSetList\\TYPE_DECLARATION`](rector/type-declaration.php)\n\n#### Example configuration\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Rector\\Core\\Configuration\\Option;\nuse Rector\\Set\\ValueObject\\SetList;\nuse Rector\\Symfony\\Set\\TwigSetList;\nuse Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ContainerConfigurator;\nuse Wieni\\wmcodestyle\\Rector\\SetList as WieniSetList;\n\nreturn static function (ContainerConfigurator $containerConfigurator): void {\n    $parameters = $containerConfigurator-\u003eparameters();\n\n    $parameters-\u003eset(Option::AUTO_IMPORT_NAMES, true);\n    $parameters-\u003eset(Option::IMPORT_SHORT_CLASSES, false);\n\n    $parameters-\u003eset(Option::PATHS, [\n        __DIR__ . '/public/modules/custom',\n    ]);\n\n    $parameters-\u003eset(Option::AUTOLOAD_PATHS, [\n        __DIR__ . '/public/core',\n        __DIR__ . '/public/core/modules',\n        __DIR__ . '/public/modules',\n        __DIR__ . '/public/profiles',\n        __DIR__ . '/public/sites',\n        __DIR__ . '/public/themes',\n    ]);\n\n    $parameters-\u003eset(Option::SETS, [\n        SetList::DEAD_CODE,\n        SetList::PHP_73,\n        SetList::PHP_74,\n        TwigSetList::TWIG_UNDERSCORE_TO_NAMESPACE,\n    ]);\n\n    $containerConfigurator-\u003eimport(WieniSetList::CODE_QUALITY);\n    $containerConfigurator-\u003eimport(WieniSetList::CODING_STYLE);\n    $containerConfigurator-\u003eimport(WieniSetList::DEPENDENCY_INJECTION);\n    $containerConfigurator-\u003eimport(WieniSetList::EARLY_RETURN);\n    $containerConfigurator-\u003eimport(WieniSetList::TYPE_DECLARATION);\n};\n```\n\n#### Add Symfony container XML\nTo work with some Symfony rules, you now need to link your container XML file:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Rector\\Core\\Configuration\\Option;\nuse Rector\\Set\\ValueObject\\SetList;\nuse Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ContainerConfigurator;\nuse Wieni\\wmcodestyle\\Rector\\SetList as WieniSetList;\n\nreturn static function (ContainerConfigurator $containerConfigurator): void {\n    $parameters = $containerConfigurator-\u003eparameters();\n    $parameters-\u003eset(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, __DIR__ . '/.cache/drupal_container.xml');\n};\n```\n\n```neon\n// phpstan-for-rector.neon\nparameters:\n    symfony:\n        container_xml_path: %currentWorkingDirectory%/.cache/drupal_container.xml\n\nincludes:\n\t- vendor/wieni/wmcodestyle/phpstan/for-rector.neon\n```\n\nDumping the container is not possible out-of-the-box when using Drupal, but our [Container Dumper module](https://github.com/wieni/container_dumper) makes this possible.\n\n### [PHPStan](https://github.com/phpstan/phpstan)\n\u003e PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even \n\u003e before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of \n\u003e each line of the code can be checked before you run the actual line.\n\n#### Drupal\nFor better integration with Drupal, consider adding [`mglaman/phpstan-drupal`](https://github.com/mglaman/phpstan-drupal)\nand [`phpstan/phpstan-symfony`](https://github.com/phpstan/phpstan-symfony) to your project. These extensions are \nrequired when using the `drupal-module` or `drupal-site` configs.\n\nYou can use the [Container Dumper module](https://www.drupal.org/project/container_dumper) to dump the Symfony container\nto an XML file. The Symfony extension can then use this file to get better insights into your project. Add the following\nto your PHPStan config:\n\n```yaml\nparameters:\n    symfony:\n        container_xml_path: %currentWorkingDirectory%/.cache/drupal_container.xml\n```\n#### Symfony\nFor better integration with Symfony, consider adding \n[`phpstan/phpstan-symfony`](https://github.com/phpstan/phpstan-symfony) and\n[`phpstan/phpstan-doctrine`](https://github.com/phpstan/phpstan-doctrine) to your project.\n\n### [composer-normalize](https://github.com/ergebnis/composer-normalize)\n\u003e Provides a composer plugin for normalizing composer.json.\n\nWe highly recommend this Composer plugin to make sure your composer.json is formatted consistently.\n\n### Running code style fixers\n\n#### Makefile\n\nIf you like [`Makefile`](https://www.gnu.org/software/make/manual/make.html#Introduction)s, create a `Makefile` with a \n`coding-standards` target:\n\n```diff\n+.PHONY: coding-standards\n+coding-standards: vendor\n+    mkdir -p .build/php-cs-fixer\n+    vendor/bin/php-cs-fixer fix --config=.php_cs --diff --verbose\n+    composer normalize\"\n+    vendor/bin/rector process\"\n+    vendor/bin/php-cs-fixer fix --config=.php_cs.php\n+    vendor/bin/phpstan analyse\n\n vendor: composer.json composer.lock\n     composer validate\n     composer install\n```\n\nRun\n\n```\n$ make coding-standards\n```\n\nto automatically fix coding standard violations.\n\n#### Composer script\n\nIf you like [`composer` scripts](https://getcomposer.org/doc/articles/scripts.md), add a `coding-standards` script to `composer.json`:\n\n```diff\n {\n   \"name\": \"foo/bar\",\n   \"require\": {\n     \"php\": \"^8.0\",\n   },\n   \"require-dev\": {\n     \"wieni/wmcodestyle\": \"^1.0\"\n+  },\n+  \"scripts\": {\n+    \"coding-standards\": [\n+      \"@composer normalize\",\n+      \"rector process\",\n+      \"php-cs-fixer fix --config=.php_cs.php\",\n+      \"phpstan analyse\"\n+    ]\n   }\n }\n```\n\nRun\n\n```\n$ composer coding-standards\n```\n\n## Changelog\nAll notable changes to this project will be documented in the\n[CHANGELOG](CHANGELOG.md) file.\n\n## Security\nIf you discover any security-related issues, please email\n[security@wieni.be](mailto:security@wieni.be) instead of using the issue\ntracker.\n\n## License\nDistributed under the MIT License. See the [LICENSE](LICENSE.md) file\nfor more information.\n\n## Acknowledgments\n- [ergebnis/php-cs-fixer-config](https://github.com/ergebnis/php-cs-fixer-config)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieni%2Fwmcodestyle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwieni%2Fwmcodestyle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieni%2Fwmcodestyle/lists"}