PHPackages                             komtaki/visibility-recommender - 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. komtaki/visibility-recommender

ActiveLibrary

komtaki/visibility-recommender
==============================

The tool is refactoring object constant visibility.

v1.1.1(5y ago)1616MITPHPPHP ^7.2 || ^8.0

Since Dec 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/komtaki/visibility-recommender)[ Packagist](https://packagist.org/packages/komtaki/visibility-recommender)[ Docs](https://github.com/komtaki/visibility-recommender)[ RSS](/packages/komtaki-visibility-recommender/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (8)Versions (9)Used By (0)

komtaki/visibility-recommender
==============================

[](#komtakivisibility-recommender)

[![Run tests](https://github.com/komtaki/visibility-recommender/workflows/Run%20tests/badge.svg)](https://github.com/komtaki/visibility-recommender/actions?query=workflow%3A%22Run+tests%22)

Analyze of PHP file, it will suggest the recommended visibility on [PSR-12](https://www.php-fig.org/psr/psr-12/) by modifying the constants directly.

> 4.3 Properties and Constants Visibility MUST be declared on all properties.
>
> Visibility MUST be declared on all constants if your project PHP minimum version supports constant visibilities (PHP 7.1 or later).
>
>

The recommended access modifiers are `public`, `private` and `protected`.

Feature
=======

[](#feature)

- Three kinds of `public, protected, private` can be given to public object constants automatically.
- Only minimal changes are required, and all line breaks and spaces are preserved.
- Supported files
    - Mixed classes with and without namespaces.
    - A mixture of constants with and without access modifiers.
    - Plain view files.
- Not supported
    - Functions that can recover constants by string concatenation, such as `eval()` and `constant()`.

Roughly pattern
---------------

[](#roughly-pattern)

Of course, we don't know if the constant reference is constructed by string concatenation using [eval](https://www.php.net/manual/ja/function.eval.php).

### public

[](#public)

- Constants are fetched by the unique class name other than `self`, `parent`, and `static`.

### protected

[](#protected)

- Constants are fetched by `self`, `parent` and `static` from inherit classes.
- Constants are fetched by `static` from own classes.
- Constants with the same name are declared in parent and children classes in the inherit relationship.

### private

[](#private)

- Constants that do not fit into any of the above patterns. Following example.
    - Constants declared in own class and are fetched only in own class by `self`.
    - Constants are seemed to not used from anywhere.

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

[](#installation)

```
composer require komtaki/visibility-recommender

```

Sample
------

[](#sample)

### Execution config

[](#execution-config)

```
declare(strict_types=1);

require_once __DIR__ . '/../vendor/autoload.php';

use Komtaki\VisibilityRecommender\Commands\RecommendConstVisibility;

// The directory or file name where the file you want to modify may be used.
$autoloadDirs = [__DIR__ . '/../tests/Fake/FixMe'];

// The directory or file name that you want to modify.
$targetDir = __DIR__ . '/../tests/Fake/FixMe';

// Convert
(new RecommendConstVisibility($autoloadDirs, $targetDir))->run();
```

[./bin/command](./bin/command)

### After

[](#after)

```
 class Mail
 {
    // not used
-    const STATUS_YET = 0;
+    private const STATUS_YET = 0;
    // used by command class
-    const STATUS_PROCESS = 1;
+    public const STATUS_PROCESS = 1;
    // not used
-    public const STATUS_DONE = 2;
+    private const STATUS_DONE = 2;
    // used by view
-    const STATUS_CANCEL = 99;
+    public const STATUS_CANCEL = 99;
 }

 class MailCommand
 {
-    const PROTECTED_USE_BY_SELF = true;
+    protected const PROTECTED_USE_BY_SELF = true;

-    const PROTECTED_USE_BY_CHILD = 200;
+    protected const PROTECTED_USE_BY_CHILD = 200;

-    const PROTECTED_USE_BY_GRAND_CHILD = true;
+    protected const PROTECTED_USE_BY_GRAND_CHILD = true;

 class ExtendsMailCommand extends MailCommand
 {
-    const PROTECTED_OVERRIDE = false;
+    protected const PROTECTED_OVERRIDE = false;

class NestExtendsMailCommand extends ExtendsMailCommand
{
-    const PROTECTED_OVERRIDE =true;
+    protected const PROTECTED_OVERRIDE =true;
```

### Target file before execution

[](#target-file-before-execution)

```
./tests/Fake/FixMe/
├── Mail.php
├── commands
│   ├── ExtendsMailCommand.php
│   ├── MailCommand.php
│   └── NestExtendsMailCommand.php
└── views
    └── index.php

```

```
declare(strict_types=1);

class Mail
{
    // not used
    const STATUS_YET = 0;
    // used by command class
    const STATUS_PROCESS = 1;
    // not used
    public const STATUS_DONE = 2;
    // used by view
    const STATUS_CANCEL = 99;
}
```

```
class MailCommand
{
    const PROTECTED_USE_BY_SELF = true;

    const PROTECTED_USE_BY_CHILD = 200;

    const PROTECTED_USE_BY_GRAND_CHILD = true;

    public function run()
    {
        echo Mail::STATUS_PROCESS;
    }

    public function getStatus()
    {
        return static::PROTECTED_USE_BY_SELF;
    }
}
```

```
class ExtendsMailCommand extends MailCommand
{
    const PROTECTED_OVERRIDE = false;

    public function run()
    {
        return self::PROTECTED_USE_BY_CHILD;
    }
}
```

```
class NestExtendsMailCommand extends ExtendsMailCommand
{
    const PROTECTED_OVERRIDE =true;

    public function run()
    {
        return self::PROTECTED_USE_BY_GRAND_CHILD;
    }
}
```

```

```

Available Commands for development
----------------------------------

[](#available-commands-for-development)

```
composer test              // Run unit test
composer tests             // Test and quality checks
composer cs-fix            // Fix the coding style
composer phpstan           // Run phpstan
composer psalm             // Run psalm
composer run-script --list // List all commands

```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

Every ~10 days

Total

8

Last Release

1888d ago

Major Versions

v0.0.5 → v1.0.02021-02-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/0dc2c4a676ff9e36ee895119c8563fa9907698263c2ac05c9e6fe516e80e5ba6?d=identicon)[komtaki](/maintainers/komtaki)

---

Top Contributors

[![komtaki](https://avatars.githubusercontent.com/u/39375566?v=4)](https://github.com/komtaki "komtaki (34 commits)")

---

Tags

refactorvisibilityconstant

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/komtaki-visibility-recommender/health.svg)

```
[![Health](https://phpackages.com/badges/komtaki-visibility-recommender/health.svg)](https://phpackages.com/packages/komtaki-visibility-recommender)
```

###  Alternatives

[felixfbecker/language-server

PHP Implementation of the Visual Studio Code Language Server Protocol

1.2k95.4k](/packages/felixfbecker-language-server)[kartik-v/yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.

743.1M27](/packages/kartik-v-yii2-dynagrid)[ph-7/just-http-status-codes

Just all HTTP status codes

1447.7k4](/packages/ph-7-just-http-status-codes)[phpfui/constantcontact

Object Oriented Wrapper for Constant Contact API V3 for PHP 8+

2015.7k1](/packages/phpfui-constantcontact)

PHPackages © 2026

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