PHPackages                             rasuvaeff/rector-named-literals - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. rasuvaeff/rector-named-literals

ActiveLibrary[Testing &amp; Quality](/categories/testing)

rasuvaeff/rector-named-literals
===============================

Rector rule that adds parameter names to literal arguments (bool by default, numeric/string opt-in)

v1.0.0(1mo ago)02.7k20BSD-3-ClausePHPPHP 8.3 - 8.5CI passing

Since Jul 11Pushed 2w agoCompare

[ Source](https://github.com/rasuvaeff/rector-named-literals)[ Packagist](https://packagist.org/packages/rasuvaeff/rector-named-literals)[ Docs](https://github.com/rasuvaeff/rector-named-literals)[ RSS](/packages/rasuvaeff-rector-named-literals/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (10)Versions (3)Used By (20)

rasuvaeff/rector-named-literals
===============================

[](#rasuvaeffrector-named-literals)

[![Stable Version](https://camo.githubusercontent.com/2af05109cb0d170412cc854e27f2b427cb8f8861708a9e4d2203afabdf428180/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261737576616566662f726563746f722d6e616d65642d6c69746572616c732e737667)](https://packagist.org/packages/rasuvaeff/rector-named-literals)[![Total Downloads](https://camo.githubusercontent.com/a74cb930fe3a0be63b3aece046cd8946b1dcaf22782ddf343772721d8e668100/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261737576616566662f726563746f722d6e616d65642d6c69746572616c732e737667)](https://packagist.org/packages/rasuvaeff/rector-named-literals)[![Build](https://camo.githubusercontent.com/14c149238eb90c474116cff1743104f87e016ff1639f433b155291333dbd1af7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7261737576616566662f726563746f722d6e616d65642d6c69746572616c732f6275696c642e796d6c3f6272616e63683d6d6173746572)](https://github.com/rasuvaeff/rector-named-literals/actions)[![Static Analysis](https://camo.githubusercontent.com/9645332e2079401b5e0752df2717af52201d0036226c96a158fe811b3f0a469e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7261737576616566662f726563746f722d6e616d65642d6c69746572616c732f7374617469632d616e616c797369732e796d6c3f6272616e63683d6d6173746572)](https://github.com/rasuvaeff/rector-named-literals/actions)[![PHP](https://camo.githubusercontent.com/b385823155b569a1badc27f4b0b1bf00c555a7b96d058100cd402953752aab29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7261737576616566662f726563746f722d6e616d65642d6c69746572616c732f706870)](https://packagist.org/packages/rasuvaeff/rector-named-literals)[![License](https://camo.githubusercontent.com/8f9449bc2c83eb6f22636d7ba4b203a607c0d89794921cdb260987594aa7cf32/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7261737576616566662f726563746f722d6e616d65642d6c69746572616c732e737667)](LICENSE.md)

[Русская версия](README.ru.md)

A [Rector](https://getrector.com) rule that defuses the **boolean trap**: it adds parameter names to literal arguments, so call sites explain themselves.

```
// before — what do true and false mean here?
$mailer->send($message, true, false);

// after
$mailer->send($message, urgent: true, queue: false);
```

> Using an AI coding assistant? [llms.txt](llms.txt) has a compact reference you can pass as context.

Requirements
------------

[](#requirements)

- PHP 8.3+ to run the rule
- `rector/rector` ^2.0

The **processed code** only needs PHP 8.0+ (named arguments): the rule declares `MinPhpVersionInterface`, so Rector automatically skips it when your project's PHP version target is below 8.0.

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

[](#installation)

```
composer require --dev rasuvaeff/rector-named-literals
```

Usage
-----

[](#usage)

```
// rector.php
use Rasuvaeff\RectorNamedLiterals\AddNameToLiteralArgumentRector;

return RectorConfig::configure()
    ->withRules([AddNameToLiteralArgumentRector::class]);        // bool literals only
```

Numeric and string literals are opt-in:

```
->withConfiguredRule(AddNameToLiteralArgumentRector::class, [
    AddNameToLiteralArgumentRector::BOOL => true,     // default
    AddNameToLiteralArgumentRector::NUMERIC => true,  // 3, 2.5, -5
    AddNameToLiteralArgumentRector::STRING => true,   // 'linear'
])
```

An unknown configuration key or a non-boolean value fails the run — no silent misconfiguration.

What exactly it does (and refuses to do)
----------------------------------------

[](#what-exactly-it-does-and-refuses-to-do)

Named-argument semantics are honoured: PHP forbids a positional argument after a named one, so when the matched literal is not the last argument, **every following positional argument is named too**:

```
$task->run(true, $mode);          // → $task->run(force: true, mode: $mode);
```

A call is left untouched when the conversion is not provably safe:

Skipped caseWhyCallee declared on an **interface**implementations may legally rename parameters — named arguments would break LSP-compatible classes`@no-named-arguments` on the function, class or any ancestorthe author explicitly opted the parameter names out of the contractArgument unpacking (`...$args`) in the callpositional arithmetic is not decidable staticallyMatched position maps to a **variadic** parametervariadic values cannot be namedCallee not resolvable by reflectionno parameter names to takeFirst-class callable syntax (`foo(...)`)not an invocation**Built-in** callee whose planned names fail native reflectionPHPStan's signature map invents fixed-arity variants for variadic built-ins (`min(arg1, arg2, …)`) — PHP rejects those names at runtime with "unknown named parameter". Every planned name on a built-in is confirmed against the real signature first`null` literals are deliberately out of scope — Rector's own `AddNameToNullArgumentRector` (CodeQuality set) already covers them; run both rules together for full literal coverage.

### How it differs from `savinmikhail/AddNamedArgumentsRector`

[](#how-it-differs-from-savinmikhailaddnamedargumentsrector)

That package names **all** arguments of a call (`str_contains(haystack: 'a', needle: 'b')`) with per-call strategies. This rule is **per-argument**: only literals get names, variables stay positional — the diff touches only the places where the call does not read.

Caveat
------

[](#caveat)

Adding a parameter name makes that name part of your compile-time contract with the callee: if a dependency renames the parameter in a minor release, your call breaks. That is exactly why interface callees and `@no-named-arguments` are skipped — but for third-party classes, apply the rule to vendor calls consciously.

Development
-----------

[](#development)

```
docker run --rm -v "$PWD":/app -w /app composer:2 composer build
docker run --rm -v "$PWD":/app -w /app composer:2 composer test
```

The e2e suite runs the real `rector process` binary over fixture files and compares the results with committed `.expected` counterparts.

License
-------

[](#license)

BSD-3-Clause.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

51d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0812d5572a7041dfe36e222d295b2e6dc55833a605350fcde58a51a5965ed30?d=identicon)[rasuvaeff](/maintainers/rasuvaeff)

---

Top Contributors

[![rasuvaeff](https://avatars.githubusercontent.com/u/1352718?v=4)](https://github.com/rasuvaeff "rasuvaeff (16 commits)")

---

Tags

boolean-trapcode-qualitynamed-argumentsphprectorrector-rulerefactoringstatic-analysisstatic analysisrefactoringrectornamed-argumentsrector-ruleboolean-trap

###  Code Quality

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rasuvaeff-rector-named-literals/health.svg)

```
[![Health](https://phpackages.com/badges/rasuvaeff-rector-named-literals/health.svg)](https://phpackages.com/packages/rasuvaeff-rector-named-literals)
```

###  Alternatives

[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2653.5M531](/packages/ssch-typo3-rector)[tempest/framework

The PHP framework that gets out of your way.

2.3k42.4k21](/packages/tempest-framework)[denzyl/phanalist

Performant static analyzer for PHP, which is extremely easy to use. It helps you catch common mistakes in your PHP code.

16148.0k](/packages/denzyl-phanalist)[savinmikhail/add_named_arguments_rector

Rector extension for PHP that converts positional function, method, and constructor calls to named arguments.

20129.7k5](/packages/savinmikhail-add-named-arguments-rector)

PHPackages © 2026

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