brucegithub/namespace-protector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brucegithub/namespace-protector

Composer 安装命令:

composer require brucegithub/namespace-protector

包简介

A tool to protect your namespace

README 文档

README

A tool to validate namespace

Latest Stable Version Latest Unstable Version License Build Status Scrutinizer Code Quality codecov

Ispired by

and for fun ...

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

  • No NULL
  • No instanceof
  • No switch
  • No static

Nice to have

  • Minimize the @var annotation

todo

10/10/2021

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

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

  • Adds command to build conflicts graph

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

  • 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

with Composer

composer require --dev brucegithub/namespace-protector asciicast

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

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

vendor/bin/namespace-protector create-config

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

For now it is a lab but...

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固