PHPackages                             tomasvotruba/unused-public - 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. tomasvotruba/unused-public

ActivePhpstan-extension[Testing &amp; Quality](/categories/testing)

tomasvotruba/unused-public
==========================

Detect unused public properties, constants and methods in your code

2.2.1(1w ago)1943.5M↓19.5%15[1 PRs](https://github.com/TomasVotruba/unused-public/pulls)20MITPHPPHP ^8.4CI passing

Since Dec 16Pushed 1w ago4 watchersCompare

[ Source](https://github.com/TomasVotruba/unused-public)[ Packagist](https://packagist.org/packages/tomasvotruba/unused-public)[ Fund](https://www.paypal.me/rectorphp)[ GitHub Sponsors](https://github.com/tomasvotruba)[ RSS](/packages/tomasvotruba-unused-public/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (17)Versions (121)Used By (20)

Find Unused Public Elements in Your Code
========================================

[](#find-unused-public-elements-in-your-code)

 [![](/docs/unused_public.jpg)](/docs/unused_public.jpg)

It's easy to find unused private class elements, because they're not used in the class itself. But what about public methods/properties/constants?

```
 final class Book
 {
     public function getTitle(): string
     {
         // ...
     }

-    public function getSubtitle(): string
-    {
-        // ...
-    }
}
```

**How can we detect unused public element?**

- find a public method
- find all public method calls in code and templates
- if the public method is not found, it probably unused

That's exactly what this package does.

This technique is very useful for private projects and to detect accidentally used `public` modifier that should be changed to `private` as called locally only.

Install
-------

[](#install)

```
composer require tomasvotruba/unused-public --dev
```

The package is available for PHP 7.2+ version.

Usage
-----

[](#usage)

With [PHPStan extension installer](https://github.com/phpstan/extension-installer), everything is ready to run.

Enable each item on their own with simple configuration:

```
# phpstan.neon
parameters:
    unused_public:
        methods: true
        properties: true
        constants: true
```

Do you have hundreds of reported public method? You don't have time to check them all, but want to handle them gradually?

Set maximum allowed % configuration instead:

```
# phpstan.neon
parameters:
    unused_public:
        methods: 2.5
```

This means maximum 2.5 % of all public methods is allowed as unused:

- If it's 5 %, you'll be alerted.
- If it's 1 %, it will be skipped as tolerated.

Do you want to check local-only method calls that should not be removed, but be turned into `private`/`protected` instead?

```
# phpstan.neon
parameters:
    unused_public:
        local_methods: true
```

Exclude methods called in templates
-----------------------------------

[](#exclude-methods-called-in-templates)

Some methods are used only in TWIG or Blade templates, and could be reported false positively as unused.

```
{{ book.getTitle() }}
```

How can we exclude them? Add your TWIG or Blade template directories in config to exclude methods names:

```
# phpstan.neon
parameters:
    unused_public:
        template_paths:
            - templates
```

Known Limitations
-----------------

[](#known-limitations)

In some cases, the rules report false positives:

- when used only in templates, apart Twig paths, it's not possible to detect them

Skip Public-Only Methods
------------------------

[](#skip-public-only-methods)

Open-source vendors design public API to be used by projects. Is element reported as unused, but it's actually designed to be used public?

Mark the class or element with `@api` annotation to skip it:

```
final class Book
{
    /**
     * @api
     */
    public function getName()
    {
        return $this->name;
    }
}
```

###  Health Score

73

—

ExcellentBetter than 100% of packages

Maintenance98

Actively maintained with recent releases

Popularity60

Solid adoption and visibility

Community39

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71.4% 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 ~11 days

Recently: every ~118 days

Total

118

Last Release

13d ago

Major Versions

0.4.0 → 1.0.02024-10-01

1.1.0 → 2.0.02024-12-12

PHP version history (7 changes)0.0.1PHP ^8.1

0.0.8.72PHP ^7.2|^8.0

0.0.9.72PHP ^7.2|8.0

0.0.26.72PHP ^7.2 || 8.0.\*

0.3.0.72PHP ^7.2 || ^8.0

2.0.0PHP ^7.4 || ^8.0

2.2.1PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/924196?v=4)[Tomas Votruba](/maintainers/TomasVotruba)[@TomasVotruba](https://github.com/TomasVotruba)

---

Top Contributors

[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (137 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (46 commits)")[![ngmy](https://avatars.githubusercontent.com/u/864041?v=4)](https://github.com/ngmy "ngmy (2 commits)")[![pilif](https://avatars.githubusercontent.com/u/4990?v=4)](https://github.com/pilif "pilif (2 commits)")[![Chris53897](https://avatars.githubusercontent.com/u/7104259?v=4)](https://github.com/Chris53897 "Chris53897 (1 commits)")[![transistive](https://avatars.githubusercontent.com/u/16435930?v=4)](https://github.com/transistive "transistive (1 commits)")[![elliotbruneel](https://avatars.githubusercontent.com/u/37578863?v=4)](https://github.com/elliotbruneel "elliotbruneel (1 commits)")[![LeoVie](https://avatars.githubusercontent.com/u/7249788?v=4)](https://github.com/LeoVie "LeoVie (1 commits)")[![ricardomm85](https://avatars.githubusercontent.com/u/11030924?v=4)](https://github.com/ricardomm85 "ricardomm85 (1 commits)")

---

Tags

dead-codephpstanstatic-analysisstatic analysisphpstan-extension

###  Code Quality

TestsPHPUnit

Static AnalysisRector

Code StyleECS

### Embed Badge

![Health badge](/badges/tomasvotruba-unused-public/health.svg)

```
[![Health](https://phpackages.com/badges/tomasvotruba-unused-public/health.svg)](https://phpackages.com/packages/tomasvotruba-unused-public)
```

###  Alternatives

[infection/infection

Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.

2.2k28.9M2.4k](/packages/infection-infection)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.5k55.4M8.5k](/packages/larastan-larastan)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

79475.7M2.2k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

67272.8M1.4k](/packages/phpstan-phpstan-doctrine)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9224.3M28](/packages/phparkitect-phparkitect)

PHPackages © 2026

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