PHPackages                             mintware-de/phpstan-namespace-constraints - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mintware-de/phpstan-namespace-constraints

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mintware-de/phpstan-namespace-constraints
=========================================

A PHPStan rule for restricting namespace usings to control dependency inheritance.

v1.0.3(2y ago)213.4k↓35.2%1MITPHPPHP ^7.1 || ^8.0

Since Mar 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mintware-de/phpstan-namespace-constraints)[ Packagist](https://packagist.org/packages/mintware-de/phpstan-namespace-constraints)[ RSS](/packages/mintware-de-phpstan-namespace-constraints/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

PHPStan Namespace Constraints Rule
==================================

[](#phpstan-namespace-constraints-rule)

This repository contains the code for the namespace\_constraints rule for PHPStan.

Why?
----

[](#why)

In the most architectures you should not depend on everything. With this rule you can ensure that a source namespace (RegEx Pattern) can only depend on code that lives in the target namespaces.

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

[](#installation)

```
$ composer require --dev mintware-de/phpstan-namespace-constraints
```

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

[](#configuration)

Add this to your `phpstan.neon`

```
# phpstan.neon
includes:
    - vendor/mintware-de/phpstan-namespace-constraints/src/Rules/rules.neon

parameters:
    namespace_constraints:
        constraints:
            - from: 'App\\SourceNamespace(\\.*)?' # Everything inside this namespace has access to
              to: ['App\\SourceNamespace(\\.*)?'] # this namespace
```

Examples
--------

[](#examples)

### Simple

[](#simple)

 ```
graph TD;
    App\Data-->App\Core;
    App\UserInterface-->App\Data;
```

      Loading ```
# phpstan.neon
includes:
    - vendor/mintware-de/phpstan-namespace-constraints/src/Rules/rules.neon

parameters:
    namespace_constraints:
        constraints:
            - from: 'App\\Core(\\.*)?'
              to: ['App\\Core(\\.*)?']
            - from: 'App\\Data(\\.*)?'
              to:
                - 'App\\Core(\\.*)?'
                - 'App\\Data(\\.*)?'
            - from: 'App\\UserInterface(\\.*)?'
              to:
                - 'App\\Core(\\.*)?'
                - 'App\\Data(\\.*)?'
                - 'App\\UserInterface(\\.*)?'
```

### Advanced

[](#advanced)

 ```
graph TD;
    App\User\Core-->App\Shared\Core
    App\Blog\Core-->App\Shared\Core
    App\*\Core-->App\Shared\Core
```

      Loading ```
# phpstan.neon
includes:
    - vendor/mintware-de/phpstan-namespace-constraints/src/Rules/rules.neon

parameters:
    namespace_constraints:
        constraints:
            # App\User Constraints
            - from: 'App\\User\\Core(\\.*)?'
              to: ['App\\User\\Core(\\.*)?']
            # App\\Blog\ Constraints
            - from: 'App\\Blog\\Core(\\.*)?'
              to: ['App\\Blog\\Core(\\.*)?']
            # App\*\Core -> App\Shared\Core
            - from: 'App\\(\w+)\\Core(\\.*)?'
              to: ['App\\Shared\\Core(\\.*)?']
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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 ~250 days

Total

4

Last Release

783d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2362734?v=4)[Julian Finkler](/maintainers/Devtronic)[@devtronic](https://github.com/devtronic)

---

Top Contributors

[![devtronic](https://avatars.githubusercontent.com/u/2362734?v=4)](https://github.com/devtronic "devtronic (7 commits)")[![kaiwa](https://avatars.githubusercontent.com/u/319268?v=4)](https://github.com/kaiwa "kaiwa (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/mintware-de-phpstan-namespace-constraints/health.svg)

```
[![Health](https://phpackages.com/badges/mintware-de-phpstan-namespace-constraints/health.svg)](https://phpackages.com/packages/mintware-de-phpstan-namespace-constraints)
```

###  Alternatives

[roave/backward-compatibility-check

Tool to compare two revisions of a public API to check for BC breaks

5953.3M56](/packages/roave-backward-compatibility-check)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4723.6M20](/packages/coenjacobs-mozart)[recca0120/laravel-erd

Laravel ERD automatically generates Entity-Relationship Diagrams from your Laravel models and displays them using Vuerd.

36072.0k](/packages/recca0120-laravel-erd)[ticketswap/phpstan-error-formatter

A minimalistic error formatter for PHPStan

87578.8k35](/packages/ticketswap-phpstan-error-formatter)[ondrejmirtes/better-reflection

Better Reflection - an improved code reflection API

136.2M4](/packages/ondrejmirtes-better-reflection)[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27241.1k1](/packages/drupal-code-builder-drupal-code-builder)

PHPackages © 2026

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