VOOZH about

URL: https://deepwiki.com/guanguans/ai-commit/6.3-code-quality-tools

⇱ Code Quality Tools | guanguans/ai-commit | DeepWiki


Loading...
Menu

Code Quality Tools

This page documents the static analysis, code style, automated refactoring, and dependency analysis tools used in the ai-commit project. It covers configuration details and how to run each tool. For information about the test suite itself, see Testing Framework. For CI integration of these tools, see CI/CD Workflows.


Overview

The project enforces quality through four primary tools:

ToolPackageConfig FilePurpose
PHP-CS-Fixerfriendsofphp/php-cs-fixer.php-cs-fixer.phpCode style formatting
PHPStanphpstan/phpstanphpstan.neonStatic type analysis
Rectorrector/rectorrector.phpAutomated refactoring
composer-dependency-analysershipmonk/composer-dependency-analysercomposer-dependency-analyser.phpDependency usage audit

All four are invoked together by the checks Composer script, which also runs linting, magic number detection (phpmnd), and structural checks via rector/swiss-knife.

Tool relationships diagram:


Sources: composer.json222-242


PHP-CS-Fixer

Config file: .php-cs-fixer.php

Base Rule Set

The configuration uses ergebnis/php-cs-fixer-config as its foundation, specifically the Php82 preset from Ergebnis\PhpCsFixer\Config\RuleSet\Php82. It is instantiated via Ergebnis\PhpCsFixer\Config\Factory::fromRuleSet().

.php-cs-fixer.php27

License Header

Every scanned PHP file is checked for the MIT license header. The header is generated dynamically using Ergebnis\License\Type\MIT with the year range starting from 2023, owner guanguans<ityaozm@gmail.com>, and URL https://github.com/guanguans/ai-commit. The generated LICENSE file is also saved on each run.

.php-cs-fixer.php28-44

Custom Fixers

All non-deprecated fixers from PhpCsFixerCustomFixers\Fixers that are not already part of the Php82 rule set are automatically registered as additional fixers.

.php-cs-fixer.php45-49

PHP Migration Sets

The following PHP migration rule sets are explicitly enabled on top of the Php82 base:

Rule SetRisky Variant
@PHP70Migration@PHP70Migration:risky
@PHP71Migration@PHP71Migration:risky
@PHP73Migration
@PHP74Migration@PHP74Migration:risky
@PHP80Migration@PHP80Migration:risky
@PHP81Migration
@PHP82Migration

.php-cs-fixer.php78-96

Notable Rule Overrides

Selected custom rule behaviours:

RuleSetting
concat_spacespacing: none
final_classfalse
native_function_invocation@compiler_optimized + is_scalar, scope all
phpdoc_alignleft-aligned, spacing 1
phpdoc_line_spanconst/property: single; method: multi
php_unit_data_provider_nameprefix provide, suffix Cases
static_lambdafalse
static_private_methodfalse (Pest compatibility)

.php-cs-fixer.php97-298

Finder Scope

PHP-CS-Fixer scans:

  • app/, bootstrap/, config/, resources/, tests/
  • Root-level .php files (excluding IDE helper files and .phpstorm.meta.php)
  • The ai-commit and composer-updater bin files

Excluded directories: __snapshots__, cache/, Fixtures/, lang/

Cache is stored at .build/php-cs-fixer/.php-cs-fixer.cache.

.php-cs-fixer.php301-340

Composer Commands

composer style-lint # dry-run check
composer style-fix # apply fixes

composer.json399-400


PHPStan

Config file: phpstan.neon

Analysis Level and Scope

level: max

Analyzed paths: app/, bootstrap/, config/, resources/lang/

Temp output is written to .build/phpstan/. The editor URL format is configured for PhpStorm deep links.

phpstan.neon31-44

Extension Stack

The configuration composes a large set of PHPStan extensions:


Sources: phpstan.neon1-28

Additional dev-require extensions that are active via phpstan/extension-installer:

  • larastan/larastan
  • phpstan/phpstan-deprecation-rules
  • phpstan/phpstan-mockery
  • phpstan/phpstan-strict-rules
  • phpstan/phpstan-webmozart-assert
  • shipmonk/phpstan-baseline-per-identifier
  • tomasvotruba/cognitive-complexity
  • tomasvotruba/type-coverage
  • rector/type-perfect
  • pb30/phpstan-composer-analysis
  • yamadashy/phpstan-friendly-formatter

Sources: composer.json95-123

Type Coverage Requirements

All type coverage thresholds are set to 100%:

Coverage TargetRequired
declare100%
param_type100%
return_type100%
constant_type100%
property_type100%

phpstan.neon64-69

Cognitive Complexity Limits

ScopeLimit
Class42
Function/method8
Dependency tree150

phpstan.neon57-63

Strict Rules


treatPhpDocTypesAsCertain is set to false.

phpstan.neon52-56

type_perfect Settings

SettingValue
narrow_paramtrue
narrow_returntrue
null_over_falsetrue
no_mixedfalse
no_mixed_propertytrue
no_mixed_callerfalse

phpstan.neon70-76

Disallowed Calls

The spaze/phpstan-disallowed-calls package is loaded with four built-in profiles (dangerous, execution, insecure, loose calls).

Additionally, a custom project rule disallows env_explode() with message: use config() instead.

exec() calls in app/Commands/ThanksCommand.php and app/ConfigManager.php are explicitly allowed via ignoreErrors.

phpstan.neon5-8 phpstan.neon77-112

Baselines

PHPStan baselines are split per identifier under the baselines/ directory. The entry point baselines/loader.neon includes per-identifier baseline files. Currently the project has 1 baseline error (method.notFound).

baselines/loader.neon1-3

Composer Commands

composer phpstan # run analysis
composer phpstan-baseline # regenerate single baseline
composer phpstan-split-baseline # split baseline per identifier

composer.json342-348


Rector

Config file: rector.php

Target PHP Version and Paths

Rector targets PHP 8.2 (PhpVersion::PHP_82) and runs on:

  • app/, bootstrap/, resources/, tests/
  • Root-level .php files (glob {*,.*}.php)
  • ai-commit and composer-updater bin files

Cache is stored at .build/rector/. Parallel execution is enabled.

Skipped paths: **.blade.php, **/__snapshots__/*, **/Fixtures/*, bootstrap/providers.php, and rector.php itself.

rector.php72-93

Enabled Sets


Sources: rector.php100-132

Explicitly Added Rules

Rule ClassPurpose
AddSeeTestAnnotationRectorAdds @see annotations linking test classes
ArraySpreadInsteadOfArrayMergeRectorReplaces array_merge with spread operator
JsonThrowOnErrorRectorAdds JSON_THROW_ON_ERROR to json_* calls
SimplifyListIndexRectorSimplifies list index access
SortAssociativeArrayByKeyRectorSorts associative arrays by key
StaticArrowFunctionRectorMakes arrow functions static
StaticClosureRectorMakes closures static
All instantiable RectorLaravel\Rector rulesAll applicable Laravel-specific rules

rector.php133-146

Configured Rules

Several rules have specific configuration applied:

  • AddNoinspectionsDocCommentToDeclareRector: injects PhpStorm noinspection hints for several common warnings
  • NewExceptionToNewAnonymousExtendsExceptionImplementsRector: exceptions implement ThrowableContract
  • RemoveNamespaceRector: removes Tests namespace from test files
  • RemoveAnnotationRector: strips inheritDoc, phpstan-ignore, phpstan-ignore-next-line, psalm-suppress
  • RenameClassRector: renames Carbon\Carbon to Illuminate\Support\Carbon
  • StaticCallToFuncCallRector: rewrites Str::of() calls to str()
  • RenameFunctionRector: renames fakerfake, testit, and several app helpers to namespaced form (App\Support\classes, App\Support\make)
  • ChangeMethodVisibilityRector: changes private trait methods (except final) to protected

rector.php147-205

Skipped Rules

Notable rules that are disabled project-wide:

Skipped RuleReason
DisallowedEmptyRuleFixerRector
FunctionLikeToFirstClassCallableRector
EncapsedStringsToSprintfRector
ExplicitBoolCompareRector
ContainerBindConcreteWithClosureOnlyRectorLaravel-specific
ThrowIfRectorLaravel-specific
StaticArrowFunctionRectorSkipped in tests/
StaticClosureRectorSkipped in tests/
SortAssociativeArrayByKeyRectorSkipped in app/, bootstrap/, resources/, tests/
CompleteDynamicPropertiesRectorSkipped in app/Clients/AbstractClient.php
JsonThrowOnErrorRectorSkipped in app/Generators/
ReplaceFakerInstanceWithHelperRector

rector.php230-296

Composer Commands

composer rector # apply refactorings
composer rector-dry-run # preview changes without applying
composer rector-list-rules # list all active rules

composer.json361-367


composer-dependency-analyser

Config file: composer-dependency-analyser.php

This tool (package shipmonk/composer-dependency-analyser) verifies that:

  • All used classes are backed by declared require / require-dev dependencies
  • No shadow dependencies (used but not directly declared)
  • No unused declared dependencies
  • Dev-only dependencies are not used in production paths

Scan Configuration

Scanned paths (production + dev): app/, bootstrap/, config/, resources/, tests/

Excluded from scan: tests/ directory

composer-dependency-analyser.php18-31

Ignored Errors

Unused dependencies (packages present in require but with no detected direct class usage):

PackageReason
laminas/laminas-textUsed indirectly
laravel-lang/commonLanguage files only
laravel-zero/phar-updaterRuntime usage pattern

Shadow dependencies (used classes whose package is not in direct require):

Package
composer/xdebug-handler
guzzlehttp/psr7
laravel-lang/config
laravel-lang/locale-list
laravel-lang/routes
laravel-zero/foundation
nunomaduro/laravel-console-summary
psr/http-message
psr/log
symfony/console
symfony/process

Dev-dependency-in-prod:

PackageNotes
intonate/tinker-zeroOptional development tool

composer-dependency-analyser.php32-71

Composer Command

composer composer-dependency-analyser

composer.json249


Additional Structural Checks (swiss-knife)

The rector/swiss-knife tool (sk scripts) provides several structural validation commands run as part of checks:

ScriptCommandWhat it checks
sk-check-conflictssk check-conflicts app/ bootstrap/ config/ resources/ tests/Git merge conflict markers left in code
sk-check-commented-codesk check-commented-code ... --line-limit=6Commented-out code blocks (max 6 lines)
sk-finalize-classes-dry-runsk finalize-classes app/ --dry-runClasses that can be marked final
sk-spot-lazy-traitssk spot-lazy-traits app/Traits used by only one class

Sources: composer.json384-398


Full Checks Pipeline

The composer checks script orchestrates all tools in order:


Sources: composer.json222-242

Git hooks (via brainmaestro/composer-git-hooks) run composer checks automatically on pre-commit and post-merge. See Development Environment Setup for hook installation details.

composer.json176-183