diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index bffde53..ffe8879 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,5 +1,4 @@ # https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository github: D3strukt0r patreon: d3strukt0r -open_collective: d3strukt0r buy_me_a_coffee: d3strukt0r diff --git a/.github/ISSUE_TEMPLATE/1-bug-report.yml b/.github/ISSUE_TEMPLATE/1-bug-report.yml deleted file mode 100644 index 6142304..0000000 --- a/.github/ISSUE_TEMPLATE/1-bug-report.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Bug report 🐛 -description: Existing feature does not behave as expected. -labels: [kind/bug, status/to verify] -body: - - type: markdown - attributes: - value: | - Before reporting a bug, make sure you are up-to-date and the problem is/was not reported already. - - type: textarea - id: problem-description - attributes: - label: Problem description - description: - Please describe encountered problem and provide the background of it - maybe including contextual information and images. - validations: - required: true - - type: textarea - id: to-reproduce - attributes: - label: To reproduce - description: | - Steps to reproduce the behavior: - - 1. Go to '...' - 2. Click on '....' - 3. Scroll down to '....' - 4. See error - - Please use markdown syntax for each code snippet. - validations: - required: true - - type: input - id: version - attributes: - label: Version - description: Provide the action version in X.Y.Z format - validations: - required: true - - type: checkboxes - id: terms - attributes: - label: Contribution Checks - options: - - label: I have verified if this problem was already reported - required: false - - label: - I am familiar with ["Feature or - bug?"](https://github.com/iwf-web/php-coding-standard/blob/master/.github/feature-or-bug.md) - required: false diff --git a/.github/ISSUE_TEMPLATE/2-feature-request.yml b/.github/ISSUE_TEMPLATE/2-feature-request.yml deleted file mode 100644 index 93d21e1..0000000 --- a/.github/ISSUE_TEMPLATE/2-feature-request.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Feature request 🚀 -description: - I have a suggestion about a new feature (and may want to implement it)! -labels: [kind/feature request, status/to verify] -body: - - type: markdown - attributes: - value: | - Before requesting a new feature, make sure your version is up-to-date. - - > [!IMPORTANT] - > For initial ideas it's preferable to use [discussions](https://github.com/iwf-web/php-coding-standard/discussions). - - As a maintainers we prefer to have only actionable issues in the backlog, with clear definition of done, - that's why Discussions are the best way to start. When scope of the request is established, then actual issue can be created. - - type: textarea - id: feature-request - attributes: - label: Feature request - description: - Please describe the feature you would like to see implemented. - validations: - required: true - - type: input - id: discussion-reference - attributes: - label: Link to Discussion where feature request was formed - placeholder: https://github.com/iwf-web/php-coding-standard/discussions/ - validations: - required: false - - type: checkboxes - id: terms - attributes: - label: Contribution Checks - options: - - label: I have verified if this feature request was already discussed - required: false - - label: - I am familiar with ["Feature or - bug?"](https://github.com/iwf-web/php-coding-standard/blob/master/.github/feature-or-bug.md) - required: false diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index a3e818a..0000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,5 +0,0 @@ -blank_issues_enabled: false -contact_links: - - name: Community Support - url: https://github.com/iwf-web/php-coding-standard/discussions - about: Please ask and answer questions here. diff --git a/.github/PULL_REQUEST_TEMPLATE/default.md b/.github/PULL_REQUEST_TEMPLATE/default.md deleted file mode 100644 index e69de29..0000000 diff --git a/.github/feature-or-bug.md b/.github/feature-or-bug.md deleted file mode 100644 index 996c311..0000000 --- a/.github/feature-or-bug.md +++ /dev/null @@ -1,25 +0,0 @@ -# Is it a feature or a bug ? - -Sometimes it's a bit tricky to define if given change proposal or change request -is adding new feature or fixing existing issue. This document is providing more -clarity about categorisation we use. - -## Bug - -Example of bugs: - -- crash during application or rule execution -- wrong changes are applied during "fixing codebase" process -- issue with generated report - -## Feature - -Example of features: - -- introduction of new rule -- enhancement of existing rule to cover more cases (for example adding support - for newly introduced PHP syntax) -- introduction of new ruleset -- update of existing ruleset (for example adjusting it to match newest style of - given community or adding newly implemented rule that was supposed to be - followed by style of given community, yet not implemented as a rule before) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82e1cf8..7fc5ad5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: - - main + branches: [main, develop] pull_request: + branches: [main, develop] permissions: contents: read diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 239c1a8..af0ebd0 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -2,14 +2,15 @@ name: Labeler on: [pull_request] +permissions: + contents: read + pull-requests: write # Adding Existing Labels + issues: write # Creating New Labels + jobs: label: name: Label PR runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write # Adding Existing Labels - issues: write # Creating New Labels steps: - name: Label PR uses: actions/labeler@v6 diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index d78cc51..c99903a 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,11 +2,10 @@ require_once __DIR__.'/vendor/autoload.php'; -use IWF\CodingStandard\IWFRiskySet; -use IWF\CodingStandard\IWFSet; +use IWFWeb\CodingStandard\IWFWebStandardRiskySet; +use IWFWeb\CodingStandard\IWFWebStandardSet; use PhpCsFixer\Config; use PhpCsFixer\Finder; -use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; $year = date('Y'); $header = <<registerCustomRuleSets([ - new IWFSet(), - new IWFRiskySet(), + new IWFWebStandardSet(), + new IWFWebStandardRiskySet(), ]) ->setFinder(Finder::create() ->in(__DIR__) ->ignoreDotFiles(false) - ->ignoreVCSIgnored(true) - ->notPath('.php-cs-fixer.dist.php') + ->ignoreVCSIgnored(true), ) - ->setParallelConfig(ParallelConfigFactory::detect()) ->setUnsupportedPhpVersionAllowed(true) ->setRiskyAllowed(true) ->setRules([ - '@IWF/standard' => true, - '@IWF/standard:risky' => true, + '@IWFWeb/standard' => true, + '@IWFWeb/standard:risky' => true, 'header_comment' => [ 'comment_type' => 'PHPDoc', 'header' => $header, ], ]) ; + +// @php-cs-fixer-ignore header_comment diff --git a/.vscode/settings.json b/.vscode/settings.json index 68d302a..4c0ab67 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "editor.formatOnSave": true, + "editor.formatOnSave": false, "[php]": { "editor.tabSize": 4, "editor.defaultFormatter": "junstyle.php-cs-fixer" diff --git a/ACKNOWLEDGMENTS.md b/ACKNOWLEDGMENTS.md deleted file mode 100644 index f059265..0000000 --- a/ACKNOWLEDGMENTS.md +++ /dev/null @@ -1,5 +0,0 @@ -# Acknowledgments - -This project uses code from the following libraries: - -- None yet diff --git a/AUTHORS.md b/AUTHORS.md deleted file mode 100644 index 10da331..0000000 --- a/AUTHORS.md +++ /dev/null @@ -1,5 +0,0 @@ -# Project Authors - -## Developers - -* **Manuele** - [D3strukt0r](https://github.com/D3strukt0r) diff --git a/CLAUDE.md b/CLAUDE.md index b1ebb9c..b284c34 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -5,8 +5,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Project Overview This is a Composer package (`iwf-web/php-coding-standard`) that provides custom PHP-CS-Fixer rule sets for IWF Web Solutions projects. It defines two rule sets: -- `@IWF/standard` - Non-risky formatting rules -- `@IWF/standard:risky` - Risky rules that may alter code behavior +- `@IWFWeb/standard` - Non-risky formatting rules +- `@IWFWeb/standard:risky` - Risky rules that may alter code behavior ## Commands @@ -30,30 +30,34 @@ No test suite exists - this is a configuration library. The package contains two source files in `src/`: -- **IWFSet.php** - Extends `AbstractRuleSetDefinition`, returns `@IWF/standard`. Builds on `@PhpCsFixer` with customizations: no Yoda style, strict types at file top (no blank line), trailing commas everywhere, preserved single-line DocBlocks. +- **IWFWebStandardSet.php** - Extends `AbstractRuleSetDefinition`, returns `@IWFWeb/standard`. Builds on `@PhpCsFixer` with customizations: no Yoda style, strict types at file top (no blank line), trailing commas everywhere, preserved single-line DocBlocks. -- **IWFRiskySet.php** - Extends `AbstractRuleSetDefinition`, returns `@IWF/standard:risky`. Builds on `@PhpCsFixer:risky` with customizations: PHPUnit uses `self::` instead of `$this->`, flexible data provider naming. +- **IWFWebStandardRiskySet.php** - Extends `AbstractRuleSetDefinition`, returns `@IWFWeb/standard:risky`. Builds on `@PhpCsFixer:risky` with customizations: PHPUnit uses `self::` instead of `$this->`, flexible data provider naming. + +- **IWFSet.php** - Deprecated wrapper for `IWFWebStandardSet`. Will be removed in v2.0. + +- **IWFRiskySet.php** - Deprecated wrapper for `IWFWebStandardRiskySet`. Will be removed in v2.0. ## Usage in Other Projects ```php registerCustomRuleSets([ - new IWFSet(), - new IWFRiskySet(), + new IWFWebStandardSet(), + new IWFWebStandardRiskySet(), ]) ->setFinder(Finder::create()->in(__DIR__)) ->setRiskyAllowed(true) ->setRules([ - '@IWF/standard' => true, - '@IWF/standard:risky' => true, + '@IWFWeb/standard' => true, + '@IWFWeb/standard:risky' => true, ]); ``` diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 5ad6a16..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,83 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our community include: - -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the overall community - -Examples of unacceptable behavior include: - -* The use of sexualized language or imagery, and sexual attention or advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [web-solutions@iwf.ch]. All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series of actions. - -**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within the community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. - -Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. - -For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations]. - -[homepage]: https://www.contributor-covenant.org -[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html -[Mozilla CoC]: https://github.com/mozilla/diversity -[FAQ]: https://www.contributor-covenant.org/faq -[translations]: https://www.contributor-covenant.org/translations diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index e954fc8..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,114 +0,0 @@ -# Contributing - -Please note we have a [code of conduct](CODE_OF_CONDUCT.md), please follow it in all your interactions with the project. - -## Submitting bugs - -### Due diligence - -Before submitting a bug, please do the following: - -* Perform basic troubleshooting steps: - - * Make sure you’re on the latest version. If you’re not on the most recent version, your problem may have been solved already! Upgrading is always the best first step. - * Try older versions. If you’re already on the latest release, try rolling back a few minor versions (e.g. if on 1.7, try 1.5 or 1.6) and see if the problem goes away. This will help the devs narrow down when the problem first arose in the commit log. - * Try switching up dependency versions. If the software in question has dependencies (other libraries, etc) try upgrading/downgrading those as well. - -* Search the project’s bug/issue tracker to make sure it’s not a known issue. -* If you don’t find a pre-existing issue, consider checking with the mailing list and/or IRC channel in case the problem is non-bug-related. - -### What to put in your bug report - -Make sure your report gets the attention it deserves: bug reports with missing information may be ignored or punted back to you, delaying a fix. The below constitutes a bare minimum; more info is almost always better: - -* What version of the core programming language interpreter/compiler are you using? For example, if it’s a Python project, are you using Python 2.7.3? Python 3.3.1? PyPy 2.0? -* What operating system are you on? Windows? (Vista? 7? 32-bit? 64-bit?) Mac OS X? (10.7.4? 10.9.0?) Linux? (Which distro? Which version of that distro? 32 or 64 bits?) Again, more detail is better. -* Which version or versions of the software are you using? Ideally, you followed the advice above and have ruled out (or verified that the problem exists in) a few different versions. -* How can the developers recreate the bug on their end? If possible, include a copy of your code, the command you used to invoke it, and the full output of your run (if applicable.) - - * A common tactic is to pare down your code until a simple (but still bug-causing) “base case” remains. Not only can this help you identify problems which aren’t real bugs, but it means the developer can get to fixing the bug faster. - -## Contributing changes - -### Licensing of contributed material - -Keep in mind as you contribute, that code, docs and other material submitted to open source projects are usually considered licensed under the same terms as the rest of the work. - -The details vary from project to project, but from the perspective of this document’s authors: - -* Anything submitted to a project falls under the licensing terms in the repository’s top level [LICENSE.txt](LICENSE.txt) file. - - * For example, if a project’s LICENSE is BSD-based, contributors should be comfortable with their work potentially being distributed in binary form without the original source code. - -* Per-file copyright/license headers are typically extraneous and undesirable. Please don’t add your own copyright headers to new files unless the project’s license actually requires them! - - * Not least because even a new file created by one individual (who often feels compelled to put their personal copyright notice at the top) will inherently end up contributed to by dozens of others over time, making a per-file header outdated/misleading. - -### Version control branching - -* Always make a new branch for your work, no matter how small. This makes it easy for others to take just that one set of changes from your repository, in case you have multiple unrelated changes floating around. - - * A corollary: don’t submit unrelated changes in the same branch/pull request! The maintainer shouldn’t have to reject your awesome bugfix because the feature you put in with it needs more review. - -* Base your new branch off of the appropriate branch on the main repository (`develop`): - - * Bug fixes should be based on the branch named after the oldest supported release line the bug affects. - - * E.g. if a feature was introduced in 1.1, the latest release line is 1.3, and a bug is found in that feature - make your branch based on 1.1. The maintainer will then forward-port it to 1.3 and master. - * Bug fixes requiring large changes to the code or which have a chance of being otherwise disruptive, may need to base off of master instead. This is a judgement call – ask the devs! - * New features should branch off of the `develop` branch. - - * Note that depending on how long it takes for the dev team to merge your patch, the copy of `develop` you worked off of may get out of date! If you find yourself ‘bumping’ a pull request that’s been sidelined for a while, make sure you rebase or merge to latest `develop` to ensure a speedier resolution. - -### Code formatting - -* Follow the style you see used in the primary repository! Consistency with the rest of the project always trumps other considerations. It doesn’t matter if you have your own style or if the rest of the code breaks with the greater community - just follow along. -* Python projects usually follow the PEP-8 guidelines (though many have minor deviations depending on the lead maintainers’ preferences.) - -### Documentation isn’t optional - -It’s not! Patches without documentation will be returned to sender. By “documentation” we mean: - -* Docstrings (for Python; or API-doc-friendly comments for other languages) must be created or updated for public API functions/methods/etc. (This step is optional for some bugfixes.) - - * Don’t forget to include versionadded/versionchanged ReST directives at the bottom of any new or changed Python docstrings! - - * Use versionadded for truly new API members – new methods, functions, classes or modules. - * Use versionchanged when adding/removing new function/method arguments, or whenever behavior changes. - -* New features should ideally include updates to prose documentation, including useful example code snippets. -* All submissions should have a changelog entry crediting the contributor and/or any individuals instrumental in identifying the problem. - -### Tests aren’t optional - -Any bugfix that doesn’t include a test proving the existence of the bug being fixed, may be suspect. Ditto for new features that can’t prove they actually work. - -We’ve found that test-first development really helps make features better architected and identifies potential edge cases earlier instead of later. Writing tests before the implementation is strongly encouraged. - -### Full example - -Here’s an example workflow for a project `theproject` hosted on GitHub, which is currently in version 1.3.x. Your username is `yourname` and you’re submitting a basic bugfix. - -#### Preparing your Fork - -* Click ‘Fork’ on GitHub, creating e.g. `yourname/theproject`. -* Clone your project: `git clone git@github.com:yourname/theproject`. -* `cd theproject` -* Create and activate a virtual environment. -* Install the development requirements: `pip install -r dev-requirements.txt`. -* Create a branch: `git checkout -b foo-the-bars 1.3.` - -#### Making your Changes - -* Add changelog entry crediting yourself. -* Write tests expecting the correct/fixed functionality; make sure they fail. -* Hack, hack, hack. -* Run tests again, making sure they pass. -* Commit your changes: `git commit -m "Foo the bars"` - -#### Creating Pull Requests - -* Push your commit to get it back up to your fork: `git push origin HEAD` -* Visit GitHub, click handy “Pull request” button that it will make upon noticing your new branch. -* In the description field, write down issue number (if submitting code fixing an existing issue) or describe the issue + your fix (if submitting a wholly new bugfix). -* Hit ‘submit’! And please be patient - the maintainers will get to you when they can. diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md deleted file mode 100644 index d0fd134..0000000 --- a/CONTRIBUTORS.md +++ /dev/null @@ -1,17 +0,0 @@ -# Contributors - -## Special thanks for all the people who had helped this project so far - -* **Manuele** - [D3strukt0r](https://github.com/D3strukt0r) - -See also the full list of [contributors](https://github.com/iwf-web/php-coding-standard/contributors) who participated in this project. - -## I would like to join this list. How can I help the project? - -We're currently looking for contributions for the following: - -- [ ] Bug fixes -- [ ] Translations -- [ ] etc... - -For more information, please refer to our [CONTRIBUTING](CONTRIBUTING.md) guide. diff --git a/README.md b/README.md index 6ef2c52..32f58f9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# IWF PHP Coding Standard +# IWF Web PHP Coding Standard -Custom PHP-CS-Fixer rule sets for consistent code style across IWF projects. +Custom PHP-CS-Fixer rule sets for consistent code style across IWF Web projects. [![License](https://img.shields.io/github/license/iwf-web/php-coding-standard)][license] [![Version](https://img.shields.io/packagist/v/iwf-web/php-coding-standard?label=latest%20release)][packagist] @@ -11,12 +11,12 @@ Custom PHP-CS-Fixer rule sets for consistent code style across IWF projects. This package provides two rule sets: -| Rule Set | Description | -|----------|-------------| -| `@IWF/standard` | Non-risky coding style rules for consistent formatting | -| `@IWF/standard:risky` | Risky rules that may change code behavior (use with caution) | +| Rule Set | Description | +| ------------------------ | ------------------------------------------------------------ | +| `@IWFWeb/standard` | Non-risky coding style rules for consistent formatting | +| `@IWFWeb/standard:risky` | Risky rules that may change code behavior (use with caution) | -Both rule sets build upon the excellent `@PhpCsFixer` rule set (which includes `@Symfony` and `@PSR12`) with customizations tailored for IWF projects. +Both rule sets build upon the excellent `@PhpCsFixer` rule set (which includes `@Symfony` and `@PSR12`) with customizations tailored for IWF Web projects. ## Getting Started @@ -40,16 +40,16 @@ Create a `.php-cs-fixer.dist.php` file in your project root: require_once __DIR__.'/vendor/autoload.php'; -use IWF\CodingStandard\IWFRiskySet; -use IWF\CodingStandard\IWFSet; +use IWFWeb\CodingStandard\IWFWebStandardRiskySet; +use IWFWeb\CodingStandard\IWFWebStandardSet; use PhpCsFixer\Config; use PhpCsFixer\Finder; use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; return new Config() ->registerCustomRuleSets([ - new IWFSet(), - new IWFRiskySet(), + new IWFWebStandardSet(), + new IWFWebStandardRiskySet(), ]) ->setFinder(Finder::create() ->in(__DIR__) @@ -57,8 +57,8 @@ return new Config() ->setParallelConfig(ParallelConfigFactory::detect()) ->setRiskyAllowed(true) ->setRules([ - '@IWF/standard' => true, - '@IWF/standard:risky' => true, + '@IWFWeb/standard' => true, + '@IWFWeb/standard:risky' => true, ]) ; ``` @@ -75,7 +75,7 @@ vendor/bin/php-cs-fixer fix ## Rule Customizations -### @IWF/standard +### @IWFWeb/standard Key customizations over the base `@PhpCsFixer` rule set: @@ -86,7 +86,7 @@ Key customizations over the base `@PhpCsFixer` rule set: - **Trailing commas everywhere** - In arrays, arguments, parameters, and match expressions - **PHPUnit flexibility** - Does not require `@covers` annotations on test classes -### @IWF/standard:risky +### @IWFWeb/standard:risky Key customizations over the base `@PhpCsFixer:risky` rule set: @@ -95,9 +95,37 @@ Key customizations over the base `@PhpCsFixer:risky` rule set: - **Flexible data providers** - Does not enforce naming conventions for PHPUnit data providers - **Ignored comment tags** - Preserves `php-cs-fixer-ignore` and `todo` comments +## Migration from v1.x + +In v1.x, the namespace was `IWF\CodingStandard` with classes `IWFSet` and `IWFRiskySet`, and rule sets `@IWF/standard` and `@IWF/standard:risky`. These still work but are **deprecated** and will be removed in v2.0. + +To migrate, update your `.php-cs-fixer.dist.php`: + +```diff +-use IWF\CodingStandard\IWFRiskySet; +-use IWF\CodingStandard\IWFSet; ++use IWFWeb\CodingStandard\IWFWebStandardRiskySet; ++use IWFWeb\CodingStandard\IWFWebStandardSet; + + return new Config() + ->registerCustomRuleSets([ +- new IWFSet(), +- new IWFRiskySet(), ++ new IWFWebStandardSet(), ++ new IWFWebStandardRiskySet(), + ]) + ->setRules([ +- '@IWF/standard' => true, +- '@IWF/standard:risky' => true, ++ '@IWFWeb/standard' => true, ++ '@IWFWeb/standard:risky' => true, + ]) + ; +``` + ## Contributing -Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests. +Please read [CONTRIBUTING.md][contributing] for details on our code of conduct and the process for submitting pull requests. This project uses [Conventional Commits](https://www.conventionalcommits.org/) for automated releases and changelog generation. @@ -107,21 +135,32 @@ We use [SemVer](http://semver.org/) for versioning. For available versions, see ## Authors -All authors can be found in the [AUTHORS.md](AUTHORS.md) file. +### Special thanks for all the people who had helped this project so far -Contributors can be found in the [CONTRIBUTORS.md](CONTRIBUTORS.md) file. +- **Manuele** - [D3strukt0r](https://github.com/D3strukt0r) See also the full list of [contributors][gh-contributors] who participated in this project. +### I would like to join this list. How can I help the project? + +We're currently looking for contributions for the following: + +- [ ] Bug fixes +- [ ] Translations +- [ ] etc... + +For more information, please refer to our [CONTRIBUTING.md][contributing] guide. + ## License This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details. ## Acknowledgments -A list of used libraries and code with their licenses can be found in the [ACKNOWLEDGMENTS.md](ACKNOWLEDGMENTS.md) file. +This project currently uses no third-party libraries or copied code. [license]: https://github.com/iwf-web/php-coding-standard/blob/main/LICENSE.txt [packagist]: https://packagist.org/packages/iwf-web/php-coding-standard [gh-tags]: https://github.com/iwf-web/php-coding-standard/tags [gh-contributors]: https://github.com/iwf-web/php-coding-standard/contributors +[contributing]: https://github.com/iwf-web/.github/blob/main/CONTRIBUTING.md diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 8cac179..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,18 +0,0 @@ -# Security Policy - -## Supported Versions - -Only the latest version is being supported. - - - -## Reporting a Vulnerability - -If you find a vulnerability please report it on the [issues page](https://github.com/iwf-web/php-coding-standard/issues) and add the tag `vulnerability`. We will then try to find the fix as soon as possible. diff --git a/SUPPORT.md b/SUPPORT.md deleted file mode 100644 index faf365e..0000000 --- a/SUPPORT.md +++ /dev/null @@ -1,3 +0,0 @@ -# How to get support - -If you need help please try to solve it by creating an issue on the [discussions page](https://github.com/iwf-web/php-coding-standard/discussions). diff --git a/composer.json b/composer.json index f43442e..8aee0ab 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ }, "autoload": { "psr-4": { + "IWFWeb\\CodingStandard\\": "src/", "IWF\\CodingStandard\\": "src/" } }, diff --git a/src/IWFRiskySet.php b/src/IWFRiskySet.php index bb75d65..445e4a3 100644 --- a/src/IWFRiskySet.php +++ b/src/IWFRiskySet.php @@ -12,54 +12,33 @@ namespace IWF\CodingStandard; -use PhpCsFixer\RuleSet\AbstractRuleSetDefinition; +use IWFWeb\CodingStandard\IWFWebStandardRiskySet; /** - * IWF Coding Standard - Risky rules. + * @deprecated Use {@see IWFWebStandardRiskySet} instead. Will be removed in v2.0. * - * This ruleset contains risky rules that may change code behavior. - * These are rules that require careful review as they can affect runtime behavior. - * - * Usage: '@IWF/standard:risky' => true + * TODO: Remove in v2.0 */ -final class IWFRiskySet extends AbstractRuleSetDefinition +class IWFRiskySet extends IWFWebStandardRiskySet { - public function getName(): string + public function __construct() { - // @IWF:risky -> @IWF/standard:risky - return implode(':', array_filter([($parts = explode(':', parent::getName()))[0].'/standard', $parts[1] ?? null])); + parent::__construct(); + + @trigger_error(\sprintf( + 'Class "%s" is deprecated, use "%s" instead. It will be removed in v2.0.', + self::class, + IWFWebStandardRiskySet::class, + ), E_USER_DEPRECATED); } - public function getRules(): array + public function getDescription(): string { - return [ - // Base risky rulesets - '@auto:risky' => true, // Automatically chooses PHP & PHPUnit risky rulesets based on composer.json - '@PhpCsFixer:risky' => true, // includes @Symfony:risky, @PSR12:risky, and more - - // Fix PhpUnit wrong access (mock expecations are not static calls) - 'php_unit_test_case_static_method_calls' => [ - 'call_type' => 'self', - 'methods' => [ - 'never' => 'this', - 'once' => 'this', - 'exactly' => 'this', - ], - ], - - // Disable strict types, we use PhpStan for that - 'declare_strict_types' => false, - - // We might want to use a provider for multiple files, so don't force a match - 'php_unit_data_provider_name' => false, - - // Ignore some tags when converting comments to PHPDoc - 'comment_to_phpdoc' => ['ignored_tags' => ['php-cs-fixer-ignore', 'todo']], - ]; + return 'Deprecated: Use @IWFWeb/standard:risky instead. '.parent::getDescription(); } - public function getDescription(): string + public function getName(): string { - return 'IWF Coding Standard - Risky rules that may change code behavior.'; + return '@IWF/standard:risky'; } } diff --git a/src/IWFSet.php b/src/IWFSet.php index a3c3b8c..b8df598 100644 --- a/src/IWFSet.php +++ b/src/IWFSet.php @@ -12,93 +12,33 @@ namespace IWF\CodingStandard; -use PhpCsFixer\RuleSet\AbstractRuleSetDefinition; +use IWFWeb\CodingStandard\IWFWebStandardSet; /** - * IWF Coding Standard - Non-risky rules. + * @deprecated Use {@see IWFWebStandardSet} instead. Will be removed in v2.0. * - * This ruleset contains all non-risky coding style rules - * that are standard across IWF projects. - * - * Usage: '@IWF/standard' => true + * TODO: Remove in v2.0 */ -final class IWFSet extends AbstractRuleSetDefinition +class IWFSet extends IWFWebStandardSet { - public function getName(): string + public function __construct() { - // @IWF -> @IWF/standard - return implode(':', array_filter([($parts = explode(':', parent::getName()))[0].'/standard', $parts[1] ?? null])); + parent::__construct(); + + @trigger_error(\sprintf( + 'Class "%s" is deprecated, use "%s" instead. It will be removed in v2.0.', + self::class, + IWFWebStandardSet::class, + ), E_USER_DEPRECATED); } - public function getRules(): array + public function getDescription(): string { - return [ - // Base rulesets - '@auto' => true, // Automatically chooses PHP rulesets based on composer.json - '@PhpCsFixer' => true, // includes @Symfony, @PSR12, and more - - // No header, since no licence to put - 'header_comment' => [ - 'header' => '', - ], - - // Don't use unreadable yoda style - 'yoda_style' => [ - 'equal' => false, - 'identical' => false, - 'less_and_greater' => false, - ], - - // Required, so "declare(strict_types=1);" is always on top - 'blank_line_after_opening_tag' => false, - 'linebreak_after_opening_tag' => false, - - // Reset order to simply put traits first - 'ordered_class_elements' => ['order' => ['use_trait']], - - // Keep single line DocBlocks to overwrite types - 'single_line_comment_style' => ['comment_types' => ['hash']], - - // Remove "yield" from requiring one space before (from base @PhpCsFixer) - 'blank_line_before_statement' => ['statements' => [ - 'break', 'continue', 'declare', 'default', 'exit', 'goto', - 'include', 'include_once', 'phpdoc', 'require', 'require_once', - 'return', 'switch', 'throw', 'try', 'yield_from', - ]], - - // Add PhpUnit DocBlocks grouping - 'phpdoc_separation' => ['groups' => [ - ['deprecated', 'link', 'see', 'since'], - ['author', 'copyright', 'license'], - ['category', 'package', 'subpackage'], - ['property', 'property-read', 'property-write'], - // PhpUnit - ['internal', 'internalNothing', 'covers', 'coversNothing'], - ]], - - // Keep space between constructor parameters in Messages - 'method_argument_space' => ['on_multiline' => 'ignore'], - - // Revert requiring @covers/@coversNothing for tests - 'php_unit_test_class_requires_covers' => false, - - // Do not remove @inheritDoc - 'no_superfluous_phpdoc_tags' => [ - 'allow_hidden_params' => true, - 'allow_mixed' => true, - 'remove_inheritdoc' => false, - ], - - // Always add trailing comma - 'trailing_comma_in_multiline' => [ - 'after_heredoc' => true, - 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'], - ], - ]; + return 'Deprecated: Use @IWFWeb/standard instead. '.parent::getDescription(); } - public function getDescription(): string + public function getName(): string { - return 'IWF Coding Standard - Non-risky rules for consistent code style across IWF projects.'; + return '@IWF/standard'; } } diff --git a/src/IWFWebStandardRiskySet.php b/src/IWFWebStandardRiskySet.php new file mode 100644 index 0000000..5b62c78 --- /dev/null +++ b/src/IWFWebStandardRiskySet.php @@ -0,0 +1,64 @@ + + * @copyright Copyright (c) 2025-2026 IWF Web Solutions + * @license https://github.com/iwf-web/php-coding-standard/blob/main/LICENSE.txt MIT License + * @link https://github.com/iwf-web/php-coding-standard + */ + +namespace IWFWeb\CodingStandard; + +use PhpCsFixer\RuleSet\AbstractRuleSetDefinition; + +/** + * IWF Web Coding Standard - Risky rules. + * + * This ruleset contains risky rules that may change code behavior. + * These are rules that require careful review as they can affect runtime behavior. + * + * Usage: '@IWFWeb/standard:risky' => true + */ +class IWFWebStandardRiskySet extends AbstractRuleSetDefinition +{ + public function getDescription(): string + { + return 'IWF Web Coding Standard - Risky rules that may change code behavior.'; + } + + public function getName(): string + { + return RuleSetNameResolver::resolve(parent::getName()); + } + + public function getRules(): array + { + return [ + // Base risky rulesets + '@auto:risky' => true, // Automatically chooses PHP & PHPUnit risky rulesets based on composer.json + '@PhpCsFixer:risky' => true, // includes @Symfony:risky, @PSR12:risky, and more + + // Fix PhpUnit wrong access (mock expecations are not static calls) + 'php_unit_test_case_static_method_calls' => [ + 'call_type' => 'self', + 'methods' => [ + 'never' => 'this', + 'once' => 'this', + 'exactly' => 'this', + ], + ], + + // Disable strict types, we use PhpStan for that + 'declare_strict_types' => false, + + // We might want to use a provider for multiple files, so don't force a match + 'php_unit_data_provider_name' => false, + + // Ignore some tags when converting comments to PHPDoc + 'comment_to_phpdoc' => ['ignored_tags' => ['php-cs-fixer-ignore', 'todo']], + ]; + } +} diff --git a/src/IWFWebStandardSet.php b/src/IWFWebStandardSet.php new file mode 100644 index 0000000..2d56f40 --- /dev/null +++ b/src/IWFWebStandardSet.php @@ -0,0 +1,103 @@ + + * @copyright Copyright (c) 2025-2026 IWF Web Solutions + * @license https://github.com/iwf-web/php-coding-standard/blob/main/LICENSE.txt MIT License + * @link https://github.com/iwf-web/php-coding-standard + */ + +namespace IWFWeb\CodingStandard; + +use PhpCsFixer\RuleSet\AbstractRuleSetDefinition; + +/** + * IWF Web Coding Standard - Non-risky rules. + * + * This ruleset contains all non-risky coding style rules + * that are standard across IWF Web projects. + * + * Usage: '@IWFWeb/standard' => true + */ +class IWFWebStandardSet extends AbstractRuleSetDefinition +{ + public function getDescription(): string + { + return 'IWF Web Coding Standard - Non-risky rules for consistent code style across IWF Web projects.'; + } + + public function getName(): string + { + return RuleSetNameResolver::resolve(parent::getName()); + } + + public function getRules(): array + { + return [ + // Base rulesets + '@auto' => true, // Automatically chooses PHP rulesets based on composer.json + '@PhpCsFixer' => true, // includes @Symfony, @PSR12, and more + + // No header, since no licence to put + 'header_comment' => [ + 'header' => '', + ], + + // Don't use unreadable yoda style + 'yoda_style' => [ + 'equal' => false, + 'identical' => false, + 'less_and_greater' => false, + ], + + // Required, so "declare(strict_types=1);" is always on top + 'blank_line_after_opening_tag' => false, + 'linebreak_after_opening_tag' => false, + + // Reset order to simply put traits first + 'ordered_class_elements' => ['order' => ['use_trait']], + + // Keep single line DocBlocks to overwrite types + 'single_line_comment_style' => ['comment_types' => ['hash']], + + // Remove "yield" from requiring one space before (from base @PhpCsFixer) + 'blank_line_before_statement' => ['statements' => [ + 'break', 'continue', 'declare', 'default', 'exit', 'goto', + 'include', 'include_once', 'phpdoc', 'require', 'require_once', + 'return', 'switch', 'throw', 'try', 'yield_from', + ]], + + // Add PhpUnit DocBlocks grouping + 'phpdoc_separation' => ['groups' => [ + ['deprecated', 'link', 'see', 'since'], + ['author', 'copyright', 'license'], + ['category', 'package', 'subpackage'], + ['property', 'property-read', 'property-write'], + // PhpUnit + ['internal', 'internalNothing', 'covers', 'coversNothing'], + ]], + + // Keep space between constructor parameters in Messages + 'method_argument_space' => ['on_multiline' => 'ignore'], + + // Revert requiring @covers/@coversNothing for tests + 'php_unit_test_class_requires_covers' => false, + + // Do not remove @inheritDoc + 'no_superfluous_phpdoc_tags' => [ + 'allow_hidden_params' => true, + 'allow_mixed' => true, + 'remove_inheritdoc' => false, + ], + + // Always add trailing comma + 'trailing_comma_in_multiline' => [ + 'after_heredoc' => true, + 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'], + ], + ]; + } +} diff --git a/src/RuleSetNameResolver.php b/src/RuleSetNameResolver.php new file mode 100644 index 0000000..722c069 --- /dev/null +++ b/src/RuleSetNameResolver.php @@ -0,0 +1,51 @@ + + * @copyright Copyright (c) 2025-2026 IWF Web Solutions + * @license https://github.com/iwf-web/php-coding-standard/blob/main/LICENSE.txt MIT License + * @link https://github.com/iwf-web/php-coding-standard + */ + +namespace IWFWeb\CodingStandard; + +/** + * Resolves a base rule set name from {@see AbstractRuleSetDefinition::getName()} + * into the final rule set name with vendor prefix separation. + * + * Takes the output of parent::getName() (e.g. @IWFWebStandard or @IWFWebStandard:risky) + * and inserts a "/" between the vendor prefix and the set name. + * + * Examples: + * - @IWFWebStandard -> @IWFWeb/standard + * - @IWFWebStandard:risky -> @IWFWeb/standard:risky + * + * @internal + */ +final class RuleSetNameResolver +{ + private const VENDOR_PREFIX = 'IWFWeb'; + + /** + * Resolve a base rule set name to the final rule set name. + * + * @param string $baseName the output of parent::getName() + */ + public static function resolve(string $baseName): string + { + // Split off :risky suffix if present + $parts = explode(':', $baseName); + + // Strip @ prefix, then strip vendor prefix to get set name + $setName = substr($parts[0], 1 + \strlen(self::VENDOR_PREFIX)); + + // Rebuild: @IWFWeb/{setname}[:risky] + return implode(':', array_filter([ + '@'.self::VENDOR_PREFIX.'/'.strtolower($setName), + $parts[1] ?? null, + ])); + } +}