Skip to content

Add phpcs and phpstan tooling from template-php - #22

Open
aviator-ua wants to merge 4 commits into
auto1-oss:masterfrom
aviator-ua:add-phpcs-phpstan-tooling
Open

Add phpcs and phpstan tooling from template-php#22
aviator-ua wants to merge 4 commits into
auto1-oss:masterfrom
aviator-ua:add-phpcs-phpstan-tooling

Conversation

@aviator-ua

@aviator-ua aviator-ua commented Jul 31, 2026

Copy link
Copy Markdown

Note: stacked on #21 (support-multiform-data) — the diff includes its commits until that PR merges; only the top commit (e7d22e0) belongs to this PR.

Summary

Adopts the phpcs and phpstan setup from wkda/template-php, adapted to this bundle's root-level source layout, and fixes everything needed to make both tools pass.

  • phpcs.xml.dist — same ruleset as the template: PSR-12, Generic.Arrays.DisallowLongArraySyntax, Generic.PHP.RequireStrictTypes, forbidden var_dump/die/phpinfo; file entries point at the bundle's source directories and Tests/.
  • phpstan.neon.dist — level 6. ApiDoc/ is not analysed: it integrates with the optional nelmio/api-doc-bundle, whose two supported major versions (EXSyst-based and OpenApi-annotation-based) cannot be installed together as dev dependencies.
  • composerphpstan/phpstan ^2.1 and squizlabs/php_codesniffer ^4.0 in require-dev; symfony/finder added to require — EndpointRouterCompilerPass instantiates Finder but the dependency was only ever satisfied transitively.

Code fixes

  • declare(strict_types=1) added to the legacy files missing it; explicit public visibility on EndpointRouterCompilerPass constants (implicitly public before, no BC change); phpcbf formatting fixes.
  • Value-typed array/iterable PHPDocs across the extractors, resolver, compiler passes, Response/ and Routing/ classes.
  • ServiceResponseListener::onKernelView() is now natively typed against ViewEvent: the GetResponseForControllerResultEvent branch was unreachable — that class was removed in Symfony 5, and this bundle requires ~6.4|~7.0.
  • EndpointLoader::load()/supports() signatures aligned with the Symfony 6.4 LoaderInterface (mixed $resource, ?string $type = null).

Testing

  • vendor/bin/phpcs — clean
  • vendor/bin/phpstan analyse — no errors at level 6
  • vendor/bin/phpunit — 32 tests, 41 assertions, all passing

🤖 Generated with Claude Code

- Reject invalid uploads with 400 instead of TypeError; use getPathname()
  instead of getRealPath() (also fixes macOS test failures)
- Reject non-POST methods and non-multipart content types with 400
- Check the stream factory lazily when a file is actually wrapped
- Fail container compilation when a controller-served multipart endpoint
  is registered but no PSR-17 stream factory is available
- Autoconfigure RequestDataExtractorInterface implementations with the
  request data extractor tag
- Decode "0" request bodies in DefaultRequestDataExtractor
- Move psr/http-message to require-dev, suggest nyholm/psr7
- Document multipart endpoints, custom extractors and the constructor BC
  break in README
- Extend test coverage: nested file arrays, invalid uploads, unfilled
  optional inputs, method/content-type guards, decode failures, compiler
  pass; clean up temp files in tearDown()
- DefaultRequestDataExtractor: reject scalar/null decoded bodies with a
  Serializer UnexpectedValueException so they resolve to 400 instead of
  an uncaught TypeError (500)
- MultipartRequestDataExtractor: check the real wire method so method
  overrides on a wire POST are accepted; match the Content-Type mime
  case-insensitively and also accept application/x-www-form-urlencoded;
  reject non-empty form bodies PHP failed to parse (post_max_size)
- MultipartStreamFactoryCompilerPass: read endpoints already baked into
  the registry definition by EndpointProviderCompilerPass instead of
  instantiating every tagged provider a second time; run the pass at
  negative priority to guarantee ordering; document the compile-time
  coverage boundary in the class docblock and README
- Tests: cover the new behaviors, rename CUT variables to $target,
  break multi-call chains one call per line, name the fopen mode literal
- phpcs.xml.dist / phpstan.neon.dist (level 6) adapted to the bundle's
  root-level source layout; ApiDoc/ excluded from phpstan because the
  optional nelmio/api-doc-bundle integration classes are not installable
  together as dev dependencies
- require-dev: phpstan/phpstan ^2.1, squizlabs/php_codesniffer ^4.0
- require: symfony/finder - EndpointRouterCompilerPass instantiates
  Finder but relied on it being pulled in transitively
- phpcs: add declare(strict_types=1) to legacy files, constant
  visibility, phpcbf formatting fixes
- phpstan: value-typed array/iterable PHPDocs; drop the unreachable
  Symfony <=4.4 GetResponseForControllerResultEvent branch and type
  onKernelView() against ViewEvent; align EndpointLoader::load()/
  supports() signatures with the Symfony 6.4 LoaderInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant