diff --git a/.gitattributes b/.gitattributes index 5789b266e..4e9eca84d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,7 +7,7 @@ /.gitignore export-ignore /.php-cs-fixer.dist.php export-ignore /composer-unused.php export-ignore -/deptrac.yml export-ignore +/structarmed.php export-ignore /infection.json.dist export-ignore /mkdocs.yml export-ignore /phpstan-baseline.php export-ignore diff --git a/.github/workflows/deptrac.yml b/.github/workflows/deptrac.yml deleted file mode 100644 index a41e15d0e..000000000 --- a/.github/workflows/deptrac.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Deptrac - -on: - pull_request: - branches: - - develop - paths: - - '**.php' - - 'composer.*' - - 'deptrac.yaml' - - '.github/workflows/deptrac.yml' - push: - branches: - - develop - paths: - - '**.php' - - 'composer.*' - - 'deptrac.yaml' - - '.github/workflows/deptrac.yml' - -jobs: - deptrac: - uses: codeigniter4/.github/.github/workflows/deptrac.yml@CI47 diff --git a/.github/workflows/structarmed.yml b/.github/workflows/structarmed.yml new file mode 100644 index 000000000..b849dd2c2 --- /dev/null +++ b/.github/workflows/structarmed.yml @@ -0,0 +1,78 @@ +name: StructArmed + +on: + pull_request: + branches: + - develop + paths: + - '**.php' + - 'composer.*' + - 'structarmed.php' + - '.github/workflows/structarmed.yml' + push: + branches: + - develop + paths: + - '**.php' + - 'composer.*' + - 'structarmed.php' + - '.github/workflows/structarmed.yml' + workflow_call: + inputs: + php-version: + required: false + type: string + default: '8.2' + +permissions: + contents: read + +jobs: + build: + name: Dependency Tracing + runs-on: ubuntu-latest + if: (! contains(github.event.head_commit.message, '[ci skip]')) + + steps: + - name: Checkout + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + + - name: Set up PHP + uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2.37.1 + with: + php-version: ${{ inputs['php-version'] }} + tools: composer + extensions: intl, json, mbstring, xml + coverage: none + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get composer cache directory + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV + + - name: Cache composer dependencies + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5 + with: + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: | + if [ -f composer.lock ]; then + composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader + else + composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader + fi + + - name: Structarmed Cache + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: /tmp/structarmed + key: ${{ runner.os }}-structarmed-${{ github.run_id }} + restore-keys: ${{ runner.os }}-structarmed- + + - run: mkdir -p /tmp/structarmed + + - name: Run static analysis + run: vendor/bin/structarmed analyze diff --git a/README.md b/README.md index 5d10c9f31..abc83085f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![PHP-CS-Fixer](https://github.com/codeigniter4/shield/actions/workflows/phpcsfixer.yml/badge.svg)](https://github.com/codeigniter4/shield/actions/workflows/phpcsfixer.yml) [![Rector](https://github.com/codeigniter4/shield/actions/workflows/rector.yml/badge.svg)](https://github.com/codeigniter4/shield/actions/workflows/rector.yml) [![Psalm](https://github.com/codeigniter4/shield/actions/workflows/psalm.yml/badge.svg)](https://github.com/codeigniter4/shield/actions/workflows/psalm.yml) -[![Architecture](https://github.com/codeigniter4/shield/workflows/Deptrac/badge.svg)](https://github.com/codeigniter4/shield/actions/workflows/deptrac.yml) +[![Architecture](https://github.com/codeigniter4/shield/workflows/StructArmed/badge.svg)](https://github.com/codeigniter4/shield/actions/workflows/structarmed.yml) [![Coverage Status](https://coveralls.io/repos/github/codeigniter4/shield/badge.svg?branch=develop)](https://coveralls.io/github/codeigniter4/shield?branch=develop) Shield is the official authentication and authorization framework for CodeIgniter 4. diff --git a/composer.json b/composer.json index 80c17fba2..3bca2a191 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "codeigniter4/settings": "^2.1" }, "require-dev": { + "boundwize/structarmed": "^0.11.0", "codeigniter/phpstan-codeigniter": "^1.3", "codeigniter4/devkit": "^1.3", "codeigniter4/framework": ">=4.3.5 <4.5.0 || ^4.5.1", @@ -86,7 +87,7 @@ "cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff", "cs-fix": "php-cs-fixer fix --ansi --verbose --diff", "deduplicate": "phpcpd app/ src/ --exclude src/Database/Migrations/2020-12-28-223112_create_auth_tables.php --exclude src/Authentication/Authenticators/HmacSha256.php", - "inspect": "deptrac analyze --cache-file=build/deptrac.cache", + "inspect": "vendor/bin/structarmed analyze", "mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit", "sa": "@analyze", "style": "@cs-fix", diff --git a/deptrac.yaml b/deptrac.yaml deleted file mode 100644 index 96bc842ea..000000000 --- a/deptrac.yaml +++ /dev/null @@ -1,158 +0,0 @@ -deptrac: - paths: - - ./src/ - - ./vendor/codeigniter4/framework/system/ - - ./vendor/codeigniter4/settings/src/ - exclude_files: - - '#.*test.*#i' - layers: - - name: Model - collectors: - - type: bool - must: - - type: class - value: .*[A-Za-z]+Model$ - must_not: - - type: directory - value: vendor/.* - - name: Vendor Model - collectors: - - type: bool - must: - - type: class - value: .*[A-Za-z]+Model$ - - type: directory - value: vendor/.* - - name: Controller - collectors: - - type: bool - must: - - type: class - value: .*\/Controllers\/.* - must_not: - - type: directory - value: vendor/.* - - name: Vendor Controller - collectors: - - type: bool - must: - - type: class - value: .*\/Controllers\/.* - - type: directory - value: vendor/.* - - name: Config - collectors: - - type: bool - must: - - type: directory - value: src/Config/.* - must_not: - - type: class - value: .*Services - - type: directory - value: vendor/.* - - name: Vendor Config - collectors: - - type: bool - must: - - type: directory - value: vendor/.*/Config/.* - must_not: - - type: class - value: .*Services - - name: Entity - collectors: - - type: bool - must: - - type: directory - value: src/Entities/.* - must_not: - - type: directory - value: vendor/.* - - name: Vendor Entity - collectors: - - type: bool - must: - - type: directory - value: vendor/.*/Entities/.* - - name: View - collectors: - - type: bool - must: - - type: directory - value: src/Views/.* - must_not: - - type: directory - value: vendor/.* - - name: Vendor View - collectors: - - type: bool - must: - - type: directory - value: vendor/.*/Views/.* - - name: Service - collectors: - - type: class - value: .*Services.* - ruleset: - Entity: - - Config - - Model - - Service - - Vendor Config - - Vendor Entity - - Vendor Model - Config: - - Model - - Service - - Vendor Config - Model: - - Config - - Entity - - Service - - Vendor Config - - Vendor Entity - - Vendor Model - Service: - - Config - - Vendor Config - - # Ignore anything in the Vendor layers - Vendor Model: - - Config - - Service - - Vendor Config - - Vendor Controller - - Vendor Entity - - Vendor Model - - Vendor View - Vendor Controller: - - Service - - Vendor Config - - Vendor Controller - - Vendor Entity - - Vendor Model - - Vendor View - Vendor Config: - - Config - - Service - - Vendor Config - - Vendor Controller - - Vendor Entity - - Vendor Model - - Vendor View - Vendor Entity: - - Service - - Vendor Config - - Vendor Controller - - Vendor Entity - - Vendor Model - - Vendor View - Vendor View: - - Service - - Vendor Config - - Vendor Controller - - Vendor Entity - - Vendor Model - - Vendor View - skip_violations: [] diff --git a/structarmed.php b/structarmed.php new file mode 100644 index 000000000..aab05444b --- /dev/null +++ b/structarmed.php @@ -0,0 +1,27 @@ +skip([ + Psr4Preset::CLASSES_MUST_MATCH_COMPOSER => [ + __DIR__ . '/src/Database/Migrations', + ], + ]) + ->cacheDirectory(is_dir('/tmp') ? '/tmp/structarmed' : null) + ->withPreset(Preset::PSR4()) + ->layerPattern('Model', '/^CodeIgniter\\\\Shield\\\\.*Model$/') + ->layerPattern('Controller', '/^CodeIgniter\\\\Shield\\\\Controllers\\\\.*$/') + ->layerPattern('Config', '/^CodeIgniter\\\\Shield\\\\Config\\\\.*$/', '/^.*Services$/') + ->layerPattern('Entity', '/^CodeIgniter\\\\Shield\\\\Entities\\\\.*$/') + ->layerPattern('Service', '/^.*Services$/') + ->ruleset([ + 'Entity' => ['Config', 'Model', 'Service'], + 'Config' => ['Model', 'Service'], + 'Model' => ['Config', 'Entity', 'Service'], + 'Service' => ['Config'], + ]);