# ekino/phpstan-banned-code architecture

> Architecture diagram of the GitHub repository ekino/phpstan-banned-code, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ekino/phpstan-banned-code
- Repository: https://github.com/ekino/phpstan-banned-code

## Overview

##### Main Components

a) Core Components:
- PHPStan Integration Layer
- Rule Engine
- Node Analyzer
- Configuration Handler
- Test Framework Integration

b) Key Rules Components:
- Banned Nodes Rule System
- Test Usage Detection System
- Error Builder

##### Input Layer
- PHP source code files as input
- Configuration (extension.neon) input
- Parameters configuration

##### Processing Layer
- PHPStan Core Integration (show as an external dependency)
- Rule Processing Pipeline:
- BannedNodesRule processor
- BannedUseTestRule processor
- Node Analysis System:
- Abstract Syntax Tree (AST) analysis
- Node type matching
- Function call detection

##### Output Layer
- Error reporting system
- Integration with PHPStan's error handler

Use these visual elements:

- Hexagons for decision points
- Blue: Core components
- Green: Input/Configuration
- Red: Error handling/Output
- Gray: External dependencies

Specific Implementation Details:

##### Configuration flow
- extension.neon → Configuration Handler → Rule Engine

##### Demonstrate the rule processing pipeline
- Source Code → AST Parser → Node Analyzer → Rule Processors → Error Builder

##### Supported node types from snippets
- Them by category (function calls, language constructs, etc.)
- How they feed into the node analysis system

Key Relationships to Highlight:

##### Configuration System
- How parameters.banned_code affects rule behavior
- Demonstrate configuration validation flow

##### Rule Processing
- How BannedNodesRule processes different node types
- How BannedUseTestRule handles test-related code detection

##### Error Handling
- How BannedNodesErrorBuilder creates standardized error messages
- Demonstrate integration with PHPStan's error reporting

Level of Detail:

1. Node type detection system
2. Rule processing pipeline
3. Configuration handling

Remember to:
- Version/dependency information
- PHPStan extension installer integration
- Composer package integration points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        PHP[PHP Source Code]
        Config["extension.neon"]
        click Config "https://github.com/ekino/phpstan-banned-code/blob/master/extension.neon"
        Params["parameters.banned_code"]
    end

    subgraph "Processing Layer"
        direction TB
        PHPStan["PHPStan Core"]
        click PHPStan "https://github.com/ekino/phpstan-banned-code/blob/master/phpstan.neon.dist"
        
        subgraph "Rule Engine"
            direction TB
            BNR["Banned Nodes Rule"]
            click BNR "https://github.com/ekino/phpstan-banned-code/blob/master/src/Rules/BannedNodesRule.php"
            BUTR["Banned Use Test Rule"]
            click BUTR "https://github.com/ekino/phpstan-banned-code/blob/master/src/Rules/BannedUseTestRule.php"
        end
        
        subgraph "Node Analysis"
            direction TB
            AST["AST Parser"]
            NodeMatch["Node Type Matcher"]
            
            subgraph "Supported Node Types"
                direction TB
                Backticks["Backticks"]
                click Backticks "https://github.com/ekino/phpstan-banned-code/blob/master/snippets/backticks.php"
                Debug["Debug Functions"]
                click Debug "https://github.com/ekino/phpstan-banned-code/blob/master/snippets/debug_backtrace.php"
                Dump["Dump Functions"]
                click Dump "https://github.com/ekino/phpstan-banned-code/blob/master/snippets/dump.php"
                Eval["Eval"]
                click Eval "https://github.com/ekino/phpstan-banned-code/blob/master/snippets/eval.php"
                Exec["Exec"]
                click Exec "https://github.com/ekino/phpstan-banned-code/blob/master/snippets/exec.php"
                Exit["Exit/Die"]
                click Exit "https://github.com/ekino/phpstan-banned-code/blob/master/snippets/exit.php"
                Print["Print"]
                click Print "https://github.com/ekino/phpstan-banned-code/blob/master/snippets/print.php"
                System["System"]
                click System "https://github.com/ekino/phpstan-banned-code/blob/master/snippets/system.php"
            end
        end
    end

    subgraph "Output Layer"
        ErrorBuilder["Error Builder"]
        click ErrorBuilder "https://github.com/ekino/phpstan-banned-code/blob/master/src/Rules/BannedNodesErrorBuilder.php"
        PHPStanErrors["PHPStan Error Handler"]
    end

    subgraph "Testing Framework"
        RuleTests["Rule Test Suite"]
        click RuleTests "https://github.com/ekino/phpstan-banned-code/tree/master/tests/Rules/"
        TestFramework["Test Framework Integration"]
        click TestFramework "https://github.com/ekino/phpstan-banned-code/tree/master/tests/Rules/"
    end

    %% Connections
    PHP --> AST
    Config --> PHPStan
    Params --> BNR
    Params --> BUTR
    
    AST --> NodeMatch
    NodeMatch --> BNR
    NodeMatch --> BUTR
    
    BNR --> ErrorBuilder
    BUTR --> ErrorBuilder
    ErrorBuilder --> PHPStanErrors
    
    RuleTests --> TestFramework
    TestFramework --> PHPStan

    %% Styles
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef input fill:#e1f3e1,stroke:#333,stroke-width:1px
    classDef core fill:#dae8fc,stroke:#333,stroke-width:1px
    classDef rules fill:#fff2cc,stroke:#333,stroke-width:1px
    classDef error fill:#f8cecc,stroke:#333,stroke-width:1px
    classDef test fill:#e1d5e7,stroke:#333,stroke-width:1px
    
    class PHP,Config,Params input
    class PHPStan,AST,NodeMatch core
    class BNR,BUTR,Backticks,Debug,Dump,Eval,Exec,Exit,Print,System rules
    class ErrorBuilder,PHPStanErrors error
    class RuleTests,TestFramework test
```
