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

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

ngmy/unused-public
==================

Detect unused public properties, constants and methods in your code

08.5kPHP

Since Feb 15Pushed 1y agoCompare

[ Source](https://github.com/ngmy/unused-public)[ Packagist](https://packagist.org/packages/ngmy/unused-public)[ RSS](/packages/ngmy-unused-public/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

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;
    }
}
```

Public Methods Used in Tests Only
---------------------------------

[](#public-methods-used-in-tests-only)

Some public methods are designed to be used in tests only. Is element reported as unused, but it's actually used in tests?

Mark the class or element with `@internal` annotation to reported as used:

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

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/7420a4f9654469ce1854f94fe56c240f0b930e692cdcfc8746f8a46480d9579d?d=identicon)[ngmy](/maintainers/ngmy)

---

Top Contributors

[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (129 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (44 commits)")[![ngmy](https://avatars.githubusercontent.com/u/864041?v=4)](https://github.com/ngmy "ngmy (9 commits)")[![LeoVie](https://avatars.githubusercontent.com/u/7249788?v=4)](https://github.com/LeoVie "LeoVie (1 commits)")[![pilif](https://avatars.githubusercontent.com/u/4990?v=4)](https://github.com/pilif "pilif (1 commits)")[![transistive](https://avatars.githubusercontent.com/u/16435930?v=4)](https://github.com/transistive "transistive (1 commits)")

### Embed Badge

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

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

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

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