PHPackages                             rg/phpnsc - 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. rg/phpnsc

ActiveLibrary

rg/phpnsc
=========

6.3.2(1y ago)40139.8k↓34.3%4[4 issues](https://github.com/researchgate/phpnsc/issues)[1 PRs](https://github.com/researchgate/phpnsc/pulls)MITPHPPHP &gt;=7.4CI passing

Since Oct 16Pushed 1y ago7 watchersCompare

[ Source](https://github.com/researchgate/phpnsc)[ Packagist](https://packagist.org/packages/rg/phpnsc)[ RSS](/packages/rg-phpnsc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (39)Used By (0)

phpnsc
======

[](#phpnsc)

[![Test status](https://github.com/researchgate/phpnsc/actions/workflows/tests.yml/badge.svg)](https://github.com/researchgate/phpnsc/actions/workflows/tests.yml/badge.svg)[![Latest Stable Version](https://camo.githubusercontent.com/5ae47c46d2c92e9dc8dd88c999260bc3b5d71a9a6f03f583a32f95377d547651/68747470733a2f2f706f7365722e707567782e6f72672f72672f7068706e73632f762f737461626c65)](https://packagist.org/packages/rg/phpnsc)[![Total Downloads](https://camo.githubusercontent.com/b2981145d756ca2cf4845ee95727139145b9394dab3cc99c6dd438dbad9d5bc4/68747470733a2f2f706f7365722e707567782e6f72672f72672f7068706e73632f646f776e6c6f616473)](https://packagist.org/packages/rg/phpnsc)[![License](https://camo.githubusercontent.com/a1fafca8be855943a035f232369fc99f4a9ef4003a434549d0be387fc52716db/68747470733a2f2f706f7365722e707567782e6f72672f72672f7068706e73632f6c6963656e7365)](https://packagist.org/packages/rg/phpnsc)

The PHP namespace checker, checks all files in a project for invalid class references.

It prints an error, if a class was used with it's simple or relative name but is:

- not in the same namespace
- or not in the corresponding sub namespace
- or does not have a corresponding use statement

Usage
-----

[](#usage)

- Add a JSON config file to your project root (see `config.sample.json`)
- Run phpnsc:

```
phpnsc run path/to/config.json
```

Configuration
-------------

[](#configuration)

The configuration has to be in a JSON file, that usually is placed in the root of your project. Example:

```
{
    "sources": [
        {
            "vendor": "vendorNamespace",
            "folders": {
                "root": "path/to/sources",
                "include": [
                    "subpackage",
                    "subpackage_two"
                ],
                "exclude": [
                    "subpackage/excluded"
                ]
            },
            "filetypes": {
                "include": [
                    ".php"
                ],
                "exclude": [
                    ".config.php"
                ]
            }
        }
    ],
    "output": [
        {
            "class": "rg\\tools\\phpnsc\\CheckstyleOutput",
            "parameter": "build/logs/phpnsc.xml"
        },
        {
            "class": "rg\\tools\\phpnsc\\ConsoleOutput",
            "parameter": ""
        }
    ]
}
```

- sources: list of source folders to be scanned
    - vendor: specifies the root vendor namespace of your project, see ()
    - folders/root: the root folder of your project
    - include: which sub-folders of your project root should be included?
    - exclude: are there be any sub-sub-folders that should be excluded?
    - filetypes: file types that should be included and excluded from analysis
- output: array of output classes that should be used. Currently support are:
    - CheckstyleOutput (checkstyle compatible XML file, e.g. for a CI server)
    - ConsoleOutput

How it works
------------

[](#how-it-works)

First the tool scans for all files matching the criteria defined in the config file. For each file it strips out all unnecessary stuff like comments, strings or non php content. After that it analyzes all defined classes and interfaces in your project and all used and referenced classes and interfaces in each file based on regular expressions. In the next step, it then uses this information to deduct if all classes and interfaces are referenced correctly.

Current limitations
-------------------

[](#current-limitations)

This tool is still alpha. It is certainly possible, that it does not find all errors of that it finds false positives. Additionally it can not handle importing several namespaces with one use statement and may have problems with using aliases.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance45

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~123 days

Recently: every ~259 days

Total

32

Last Release

398d ago

Major Versions

1.5.0 → 2.0.02016-11-23

2.0.4 → 3.0.02017-04-03

3.0.4 → 4.0.02018-02-12

4.0.3 → 5.0.02019-01-09

5.2.0 → 6.0.02021-11-04

PHP version history (8 changes)1.3.3PHP ^5.5 || ^7.0

2.0.0PHP ^5.5.0 || ^7.0.0

2.0.2PHP ^5.6.0 || ^7.0.0

3.0.0PHP ^7.0.0

4.0.1PHP ^7.1.0

5.1.0PHP ^7.1

6.1.0PHP ^7.3|^8.0

6.2.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3339a5bc868a2844d31d1f9941062702bb1f6e0324964e8bc5154200bc59af3e?d=identicon)[mdio](/maintainers/mdio)

![](https://www.gravatar.com/avatar/bc721d458daef6acfa87d9a3106f9c615e2aae77348d644af4270693e8c23dad?d=identicon)[grid\_rg](/maintainers/grid_rg)

---

Top Contributors

[![danez](https://avatars.githubusercontent.com/u/231804?v=4)](https://github.com/danez "danez (39 commits)")[![bashofmann](https://avatars.githubusercontent.com/u/243056?v=4)](https://github.com/bashofmann "bashofmann (17 commits)")[![mdio](https://avatars.githubusercontent.com/u/8616698?v=4)](https://github.com/mdio "mdio (8 commits)")[![rg-scheb](https://avatars.githubusercontent.com/u/249925692?v=4)](https://github.com/rg-scheb "rg-scheb (7 commits)")[![scheb](https://avatars.githubusercontent.com/u/1259952?v=4)](https://github.com/scheb "scheb (5 commits)")[![mustafah15](https://avatars.githubusercontent.com/u/6823250?v=4)](https://github.com/mustafah15 "mustafah15 (2 commits)")[![ExplodingCabbage](https://avatars.githubusercontent.com/u/2358339?v=4)](https://github.com/ExplodingCabbage "ExplodingCabbage (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rg-phpnsc/health.svg)

```
[![Health](https://phpackages.com/badges/rg-phpnsc/health.svg)](https://phpackages.com/packages/rg-phpnsc)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

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

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[phel-lang/phel-lang

Phel is a functional programming language that compiles to PHP

4743.5k10](/packages/phel-lang-phel-lang)[php-soap/wsdl

Deals with WSDLs

173.5M12](/packages/php-soap-wsdl)[php-soap/wsdl-reader

A WSDL reader in PHP

212.3M9](/packages/php-soap-wsdl-reader)

PHPackages © 2026

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