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.0(4mo ago)1923.2M↑14.4%1520MITPHPPHP ^7.4 || ^8.0CI passing

Since Dec 16Pushed 4mo 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 1mo ago

READMEChangelogDependencies (2)Versions (120)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

63

—

FairBetter than 99% of packages

Maintenance76

Regular maintenance activity

Popularity60

Solid adoption and visibility

Community37

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

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

Recently: every ~98 days

Total

117

Last Release

131d ago

Major Versions

0.4.0 → 1.0.02024-10-01

1.1.0 → 2.0.02024-12-12

PHP version history (6 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

### 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 (134 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

### 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

[larastan/larastan

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

6.4k43.5M5.2k](/packages/larastan-larastan)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

78768.9M1.5k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

66766.6M1.1k](/packages/phpstan-phpstan-doctrine)[tomasvotruba/bladestan

PHPStan rule for static analysis of Blade templates

363584.5k4](/packages/tomasvotruba-bladestan)[phpstan/phpstan-strict-rules

Extra strict and opinionated rules for PHPStan

69661.6M3.9k](/packages/phpstan-phpstan-strict-rules)[phpstan/phpstan-phpunit

PHPUnit extensions and rules for PHPStan

529102.1M8.6k](/packages/phpstan-phpstan-phpunit)

PHPackages © 2026

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