PHPackages                             amashukov/rector-php-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. amashukov/rector-php-rules

ActiveRector-extension[Validation &amp; Sanitization](/categories/validation)

amashukov/rector-php-rules
==========================

Opinionated Rector rules for PHP — strict-assertion enforcement, no @phpstan-ignore, no env-checks in src, no superglobals, PSR Clock requirement, no direct DB / event-dispatch / assert() inside functional tests, and a comment-stripper that keeps only PHPStan tag blocks.

v0.4.0(1mo ago)0694↑52.1%17MITPHPPHP &gt;=8.3CI passing

Since May 29Pushed 1mo agoCompare

[ Source](https://github.com/AndreyMashukov/rector-php-rules)[ Packagist](https://packagist.org/packages/amashukov/rector-php-rules)[ Docs](https://github.com/AndreyMashukov/rector-php-rules)[ RSS](/packages/amashukov-rector-php-rules/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (7)Versions (6)Used By (17)

amashukov/rector-php-rules
==========================

[](#amashukovrector-php-rules)

Fifteen portable custom Rector rules for PHP 8.3+ — a static-analysis code-quality gate enforcing strict assertions, no `@phpstan-ignore`, no superglobals, no env-checks, no constructor fallbacks, no deferred `TODO`/`FIXME` markers, PSR Clock, clean functional tests, and comment-free YAML.

[![CI](https://camo.githubusercontent.com/209b7b8323dbd494d35f87b74564c61ea44abd80498a37a8618b230a051cf09a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f416e647265794d617368756b6f762f726563746f722d7068702d72756c65732f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349)](https://github.com/AndreyMashukov/rector-php-rules/actions)[![PHPStan L9](https://camo.githubusercontent.com/d8ced4929c35adbecb5d736d79c8d6689f4a476425c8413b7443e6d0eb541184/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f416e647265794d617368756b6f762f726563746f722d7068702d72756c65732f7374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d5048505374616e2532304c39)](https://github.com/AndreyMashukov/rector-php-rules/actions)[![Latest Version](https://camo.githubusercontent.com/dbb1b2749fc135ea99189fbc68ba54f494f60177caed21506b3843a7c807219b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d617368756b6f762f726563746f722d7068702d72756c6573)](https://packagist.org/packages/amashukov/rector-php-rules)[![Downloads](https://camo.githubusercontent.com/5ec5ba99136a8fe000dd6d48eceefc0121c388effc6f850dd33dd54ea12dca05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d617368756b6f762f726563746f722d7068702d72756c6573)](https://packagist.org/packages/amashukov/rector-php-rules)[![PHP](https://camo.githubusercontent.com/5c5d425599ea6e10aac815135da1ec5c4add03f4c24c10100e426cac671bdd7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f616d617368756b6f762f726563746f722d7068702d72756c65732f706870)](https://packagist.org/packages/amashukov/rector-php-rules)[![License](https://camo.githubusercontent.com/b0281979edfc36d23e0253691132d20b420cc75e0a702b9c0a7a2b5962f27c20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d617368756b6f762f726563746f722d7068702d72756c6573)](LICENSE)[![Stars](https://camo.githubusercontent.com/848b50686b7ec58f2947b600885353961f416b1e26017f19e896db4d8c706764/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f416e647265794d617368756b6f762f726563746f722d7068702d72756c65733f7374796c653d736f6369616c)](https://github.com/AndreyMashukov/rector-php-rules)

`amashukov/rector-php-rules` is a set of **portable custom Rector rules for PHP 8.3+** that enforce a single, consistent quality bar across `src/`, `bundles/`, `tests/`, and your YAML config files: explicit failure modes in production code, deterministic and value-pinning assertions in tests, no environment branching, no superglobals, no `@phpstan-ignore`, no constructor fallbacks (`?? new ...`), no non-DI clock access, no deferred `TODO`/`FIXME` markers, and no narrative comments in PHP or YAML. Drop them into any project's `rector.php` and turn architectural conventions into an enforced, CI-gated coding standard. Fifteen rules in total.

Features
--------

[](#features)

- **Production-code guards** — ban `assert()`, superglobals + `getenv()`, runtime environment branching, and `@phpstan-ignore` suppressions in `src/`.
- **Strict-test enforcement** — forbid type-only / existence-only / inline-array `assertContains` assertions, and conditional assertions inside `if`/`match` branches.
- **Functional-test purity** — block direct DB mutations and direct event/message-bus dispatch in `tests/Functional/**`, forcing tests through the public API.
- **PSR Clock requirement** — ban `time()` / `new DateTime` in production, mandating injected `Psr\Clock\ClockInterface`.
- **No constructor fallbacks** — flag the `$dep ?? new ClassName(...)` pattern that hides a required dependency behind a default-construction trapdoor.
- **Comment hygiene** — strip every comment outside interface method doc-blocks, with a PHPStan-tag carve-out.
- **YAML comment hygiene** — extends the same no-comments policy to `*.yaml` / `*.yml` files via a dedicated Rector rule that walks the configured paths, strips comments in place, and fails the run.
- **Detection-only by default for PHP** — most PHP rules attach a `// RECTOR-BAN: …` marker so a dry-run surfaces the violation in CI without silently rewriting domain semantics. The YAML rule strips and re-throws.

The full rule catalogue with BAD/GOOD examples is documented under [Rule catalogue](#rule-catalogue) below.

Installation
------------

[](#installation)

```
composer require --dev amashukov/rector-php-rules
```

Usage
-----

[](#usage)

Register the rules you want in your `rector.php`:

```
