Skip to content

Commit 1ed7239

Browse files
authored
Add lint check for class autoloading PSR compliance (#845)
Fixes #844. Running `composer dump-autoload --optimize --strict-psr --strict-ambiguous` in current `master` branch yields: ``` ~ composer dump-autoload --optimize --strict-psr --strict-ambiguous Generating optimized autoload files Warning: Ambiguous class resolution, "Stringable" was found in both "<path-to-repo>/json-schema/vendor/marc-mabe/php-enum/stubs/Stringable.php" and "<path-to-repo>/json-schema/vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php", the first will be used. To resolve ambiguity in classes not under your control you can ignore them by path using exclude-files-from-classmap Class Tool\Validator\UriValidatorTest located in ./tests/Tool/Validator/UriValidatorTest.php does not comply with psr-4 autoloading standard (rule: JsonSchema\Tests\ => ./tests). Skipping. Class Tool\Validator\RelativeReferenceValidatorTest located in ./tests/Tool/Validator/RelativeReferenceValidatorTest.php does not comply with psr-4 autoloading standard (rule: JsonSchema\Tests\ => ./tests). Skipping. Generated optimized autoload files containing 1845 classes ``` The namespace of the two test files is addressed as part of this PR. The `\Stringable` ambiguity is more problematic. `symfony/polyfill-80` is a transitive dev dependency only, so it can be solved by excluding the dev dependencies. Is linting with `--no-dev` enough? Otherwise using `exclude-files-from-classmap` is an option.
1 parent ac0d369 commit 1ed7239

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ jobs:
3636
- name: "Lint PHP files"
3737
run: |
3838
parallel-lint . --checkstyle --exclude vendor --show-deprecated | cs2pr
39+
40+
- name: "Validate conforming class autoloading"
41+
run: |
42+
composer dump-autoload --no-dev --optimize --strict-psr --strict-ambiguous

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Added
10+
- Add lint check for class autoloading PSR compliance ([#845](https://github.com/jsonrainbow/json-schema/pull/845))
911

1012
## [6.5.2] - 2025-09-09
1113
### Fixed

tests/Tool/Validator/RelativeReferenceValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Tool\Validator;
5+
namespace JsonSchema\Tests\Tool\Validator;
66

77
use JsonSchema\Tool\Validator\RelativeReferenceValidator;
88
use PHPUnit\Framework\TestCase;

tests/Tool/Validator/UriValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Tool\Validator;
5+
namespace JsonSchema\Tests\Tool\Validator;
66

77
use JsonSchema\Tool\Validator\UriValidator;
88
use PHPUnit\Framework\TestCase;

0 commit comments

Comments
 (0)