PHPackages                             brucegithub/namespace-protector - 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. brucegithub/namespace-protector

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

brucegithub/namespace-protector
===============================

A tool to protect your namespace

0.1.0(4y ago)461[1 PRs](https://github.com/BruceGitHub/namespace-protector/pulls)MITPHPPHP ^8

Since Apr 11Pushed 1y ago2 watchersCompare

[ Source](https://github.com/BruceGitHub/namespace-protector)[ Packagist](https://packagist.org/packages/brucegithub/namespace-protector)[ RSS](/packages/brucegithub-namespace-protector/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (13)Versions (3)Used By (0)

namespace-protector
===================

[](#namespace-protector)

A tool to validate namespace

[![Latest Stable Version](https://camo.githubusercontent.com/13af92975c668e5189991a988703e8f5b7188792260389e39092400e39849637/68747470733a2f2f706f7365722e707567782e6f72672f62727563656769746875622f6e616d6573706163652d70726f746563746f722f76)](//packagist.org/packages/brucegithub/namespace-protector) [![Latest Unstable Version](https://camo.githubusercontent.com/37b954e127989b771e23f8009262f602faeecc50c423c5fd580c7f16da294b47/68747470733a2f2f706f7365722e707567782e6f72672f62727563656769746875622f6e616d6573706163652d70726f746563746f722f762f756e737461626c65)](//packagist.org/packages/brucegithub/namespace-protector) [![License](https://camo.githubusercontent.com/2c1c8a1feac404458520cdffe56d653271db9bc1e6745f786a37a95810e71116/68747470733a2f2f706f7365722e707567782e6f72672f62727563656769746875622f6e616d6573706163652d70726f746563746f722f6c6963656e7365)](//packagist.org/packages/brucegithub/namespace-protector) [![Build Status](https://camo.githubusercontent.com/4cfcb0bad8f08b65de6fbbf989f487dc8f81963ae632f7e751806d4e2685dd73/68747470733a2f2f7472617669732d63692e6f72672f42727563654769744875622f6e616d6573706163652d70726f746563746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/BruceGitHub/namespace-protector) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/f686eefea5960783a057651be412e56227c50623b0696adfc8cdd040c8917ae1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f42727563654769744875622f6e616d6573706163652d70726f746563746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/BruceGitHub/namespace-protector/?branch=master) [![codecov](https://camo.githubusercontent.com/6febbe1dd256ce80b0062cf37c79edfc0e97fc46dfe7caea828ed8ebe3e50801/68747470733a2f2f636f6465636f762e696f2f67682f42727563654769744875622f6e616d6573706163652d70726f746563746f722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/BruceGitHub/namespace-protector)

Ispired by
==========

[](#ispired-by)

-
- .
-

and for fun ...

Motivation
==========

[](#motivation)

Allow to improve the information hiding at level of namespace Like C#/Java pubblic/private class. The idea is that namespace in some situations can be private at all except for a specific entry point. For example the namespace of third parts lib.

The Design of this project follows this rules
=============================================

[](#the-design-of-this-project-follows-this-rules)

- No NULL
- No instanceof
- No switch
- No static

Nice to have
------------

[](#nice-to-have)

- Minimize the @var annotation

todo
====

[](#todo)

### 10/10/2021

[](#10102021)

- \[\] Review the db namespace
- \[\] Remove psalm-suppress
- \[\] Remove psalm minor issues

### Waiting

[](#waiting)

- \[\] Adds mode DISCOVER\_CONFIG, so for each lib that in the `extra` node of composer.json declares the visibility settings of the namespace lib, it can perform the validity in autonomy

### Done

[](#done)

- Adds command to build conflicts graph

Minimal config
==============

[](#minimal-config)

Trought the json configuration it's possible define

```
{
  "version": "0.1.0",
  "start-path": "src",
  "composer-json-path": "./",
  "public-entries": [],
  "private-entries": [],
  "mode": "MODE_MAKE_VENDOR_PRIVATE"
}
```

Fast because each ast it's cached and reused until the target file change
=========================================================================

[](#fast-because-each-ast-its-cached-and-reused-until-the-target-file-change)

- mode `public` default mode, in this setup only a private namespace it's validated
- mode `private vendor` in which each access of vendor namespace trigger a violation if was not added public namespace.

Install and Run
===============

[](#install-and-run)

with Composer
-------------

[](#with-composer)

`composer require --dev brucegithub/namespace-protector`[![asciicast](https://camo.githubusercontent.com/b5b3bc00c680f5cea0e91a3562bcff1a5d32a45bd8d64523c391707296e84fe6/68747470733a2f2f61736369696e656d612e6f72672f612f3431313332352e737667)](https://asciinema.org/a/411325)

with Phar
---------

[](#with-phar)

Adds this to composer.json

```
"repositories": [{
  "type": "vcs",
  "url": "https://github.com/brucegithub/namespace-protector-phar.git"
}],
```

composer require --dev brucegithub/namespace-protector-phar --no-cache "dev-main" [![asciicast](https://camo.githubusercontent.com/77c66f525e946c1259659dca1991c802a7f21217c255bd9abe92288b5e171573/68747470733a2f2f61736369696e656d612e6f72672f612f3431313332362e737667)](https://asciinema.org/a/411326)

with Docker
-----------

[](#with-docker)

```
docker run  --rm -it -v $(pwd):/namespace-protector brucedockerhub/namespace-protector:0.1.0 create-config
docker run  --rm -it -v $(pwd):/namespace-protector brucedockerhub/namespace-protector:0.1.0 validate-namespace

```

setup
-----

[](#setup)

`vendor/bin/namespace-protector create-config`

run
---

[](#run)

`vendor/bin/namespace-protector validate-namespace`

```
➜  namespace-protector git:(master) ✗ vendor/bin/namespace-protector validate-namespace
|Dump config:
|> Version: 0.1.0
|> Cache: FALSE
|> Plotter: plotter-terminal
|> Path start: tests/Stub/RealProject/src
|> Composer Json path: ./
|> Mode: PUBLIC
|> Private entries:
|       >NamespaceProtector\Common\
|       >NamespaceProtector\Scanner\
|       >PhpParser

|
|> Public entries:

Load data...
Loaded 3 files to validate
Loaded 5031 built in symbols
Start analysis...

Processed file: tests/Stub/RealProject/src/NamespaceProtectorProcessorFactory.php
	 > ERROR Line: 7 of use PhpParser\NodeTraverser
	 > ERROR Line: 8 of use PhpParser\ParserFactory
	 > ERROR Line: 14 of use NamespaceProtector\Scanner\ComposerJson
	 > ERROR Line: 16 of use NamespaceProtector\Common\FileSystemPath
	 > ERROR Line: 19 of use NamespaceProtector\Scanner\FileSystemScanner

Processed file: tests/Stub/RealProject/src/Analyser.php
	 > ERROR Line: 8 of use NamespaceProtector\Common\PathInterface

Processed file: tests/Stub/RealProject/src/EnvironmentDataLoader.php
	 > ERROR Line: 8 of use NamespaceProtector\Scanner\ComposerJson
Total files: 3
Total errors: 7
Elapsed time: 0.68148
```

```
Example of output in png format.
➜  vendord/bin/namespace-protector validate-namespace plotter-png
```

[![example output](https://github.com/BruceGitHub/namespace-protector/raw/master/img/example_output.png)](https://github.com/BruceGitHub/namespace-protector/blob/master/img/example_output.png)

For now it is a lab but...

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

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

Unknown

Total

1

Last Release

1498d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b3d93b14b3fa6dab68b198f3195ca749befb244b0a55e0f3cd919f502d294a1?d=identicon)[BrucePackagist](/maintainers/BrucePackagist)

---

Top Contributors

[![BruceGitHub](https://avatars.githubusercontent.com/u/5399875?v=4)](https://github.com/BruceGitHub "BruceGitHub (53 commits)")

---

Tags

checknamespacenamespace-protectorphpprivatepublictool

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/brucegithub-namespace-protector/health.svg)

```
[![Health](https://phpackages.com/badges/brucegithub-namespace-protector/health.svg)](https://phpackages.com/packages/brucegithub-namespace-protector)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[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.2k26.2M1.8k](/packages/infection-infection)[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[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)

PHPackages © 2026

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