mintware-de/phpstan-namespace-constraints 问题修复 & 功能扩展

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

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

mintware-de/phpstan-namespace-constraints

最新稳定版本:v1.0.3

Composer 安装命令:

composer require mintware-de/phpstan-namespace-constraints

包简介

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

README 文档

README

This repository contains the code for the namespace_constraints rule for PHPStan.

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

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

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

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

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(\\.*)?']

统计信息

  • 总下载量: 14.22k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固