Skip to content

182 integrate php stan into quantum starter project#183

Merged
armanist merged 6 commits intosoftberg:masterfrom
armanist:182-Integrate-PHPStan-into-Quantum-Starter-Project
Apr 3, 2026
Merged

182 integrate php stan into quantum starter project#183
armanist merged 6 commits intosoftberg:masterfrom
armanist:182-Integrate-PHPStan-into-Quantum-Starter-Project

Conversation

@armanist
Copy link
Copy Markdown
Member

@armanist armanist commented Apr 3, 2026

Closes #182

Summary by CodeRabbit

  • Bug Fixes

    • Fixed URL routing pattern matching.
    • Post responses now omit image when required directory info is missing (avoids incorrect image URLs).
  • Chores

    • Integrated static analysis into CI and added tooling configuration.
    • Enhanced PHPDoc/type documentation across the codebase.
    • Enforced consistent line endings and configured export exclusions for distributed archives.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 60055fd3-e1db-4864-9c18-d0c5d0ca2ca3

📥 Commits

Reviewing files that changed from the base of the PR and between 66c1c06 and ad16172.

📒 Files selected for processing (2)
  • phpstan.neon.dist
  • shared/Transformers/PostTransformer.php
✅ Files skipped from review due to trivial changes (1)
  • phpstan.neon.dist
🚧 Files skipped from review as they are similar to previous changes (1)
  • shared/Transformers/PostTransformer.php

📝 Walkthrough

Walkthrough

This PR integrates PHPStan into the project (composer, config, CI), adds a .gitattributes export/line-ending policy, and refines PHPDoc/type annotations and small internal typing assignments across commands, models, services, helpers, and a transformer. No public API signatures changed.

Changes

Cohort / File(s) Summary
Repo metadata
/.gitattributes
Enforce LF line endings for files and add export-ignore entries for dev/test/tooling artifacts.
CI & tooling
.github/workflows/php.yml, composer.json, phpstan.neon.dist
Add PHPStan dev dependency and composer phpstan script, add PHPStan step to CI, and supply phpstan.neon.dist (php 7.4, level 5, targeted paths and excludes).
Helper
helpers/functions.php
Escape current_lang() with preg_quote(..., '/') in url_with_lang() regex to handle / correctly.
Commands (PHPDoc)
shared/Commands/...
shared/Commands/CommentCreateCommand.php, CommentDeleteCommand.php, DemoCommand.php, PostCreateCommand.php, PostDeleteCommand.php, PostShowCommand.php, PostUpdateCommand.php, UserCreateCommand.php, UserDeleteCommand.php, UserShowCommand.php
Refined PHPDoc for $args/$options to `array<int, array<int
Models (PHPDoc)
shared/Models/Comment.php, shared/Models/Post.php, shared/Models/User.php
Narrowed $fillable docblocks to array<string> and added explicit property PHPDoc to Post.
Services
shared/Services/AuthService.php, shared/Services/CommentService.php, shared/Services/PostService.php
Introduce local variables with PHPDoc-typed annotations and refine docblock return types to aid static analysis; behavior unchanged.
Transformer
shared/Transformers/PostTransformer.php
Change PHPDoc return from mixedarray and require both image and user_directory to construct image URL (else null).

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Dev as Developer
participant Repo as Repository
participant CI as GitHub Actions
participant Composer as Composer
participant PHPStan as PHPStan
Dev->>Repo: Push PR (includes composer.json, phpstan.neon.dist, workflow)
Repo->>CI: Trigger workflow
CI->>Composer: install deps
CI->>Composer: run composer cs:check
CI->>Composer: run composer phpstan
Composer->>PHPStan: execute analysis (scan configured paths + vendor/framework)
PHPStan-->>CI: report results (exit non-zero on errors)
CI->>Composer: run test steps (env setup, tests)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • Vahram1995
  • andrey-smaelov
  • hatik92
  • live-soft

Poem

🐰 Hop, hop, I whisper with delight,
I lint and type while nibbling the night.
PHPStan scouts with steady beam,
I tidy docs and polish the seam.
A carrot for code — clear and bright! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main objective: integrating PHPStan into the Quantum starter project.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #182: PHPStan dependency added, phpstan.neon.dist configured correctly with proper paths/excludes/scanDirectories, composer script created, CI workflow updated, and all necessary type annotation improvements made throughout the codebase.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #182 objectives. Type annotation updates in Command, Model, Service, and Transformer classes are necessary refactoring to pass PHPStan level 5 analysis, which serves the integration goal.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
.github/workflows/php.yml (1)

48-49: Run PHPStan once to avoid redundant CI work.

Since this job is matrixed, Line 48–49 executes static analysis three times. You can keep tests matrixed and gate PHPStan to one PHP version to reduce build time.

⚙️ Suggested workflow tweak
     - name: Run PHPStan
+      if: matrix.php-versions == '8.1'
       run: composer phpstan
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/php.yml around lines 48 - 49, The PHPStan step ("Run
PHPStan" invoking "composer phpstan") is running for every matrix entry and
causing redundant CI runs; modify the workflow so PHPStan runs only once by
gating that step to a single PHP version (e.g., add a condition like if:
matrix.php == '8.1' for the "Run PHPStan" step) or move the "Run PHPStan" step
into a separate non-matrix job that runs once, keeping the test jobs matrixed.
phpstan.neon.dist (1)

3-3: Note: Analysis level exceeds stated objective.

The PR objectives mentioned starting at level 1, but this configuration sets level: 5. While this is commendable, ensure all team members are aware of the stricter analysis and that the codebase can maintain this level going forward.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@phpstan.neon.dist` at line 3, The PHPStan configuration in phpstan.neon.dist
sets a stricter analysis level (level: 5) than the PR objective (level 1);
change the `level` value in phpstan.neon.dist from 5 to 1 (or align it with the
agreed project standard) so CI and local tooling match the stated objective, and
if you intended to raise the teamwide level keep level: 5 but add a note in the
PR or a dedicated config change explaining the decision and coordinating with
the team.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@helpers/functions.php`:
- Around line 37-38: The regex is matching current_lang() anywhere in
route_uri(), which can replace substrings inside other path segments; update the
preg_replace call that uses preg_quote(current_lang(), '/') and route_uri() so
it only matches the language when it appears as a full path segment (i.e.,
preceded by start or '/' and followed by end or '/'), and keep the limit of 1
replacement; adjust the preg_match check similarly to use the segment-aware
pattern so current_lang() is only detected/replaced as its own path segment.

In `@phpstan.neon.dist`:
- Line 12: The excludePaths entry for "modules" in phpstan.neon.dist is treated
as required and causes CI validation to fail because the directory doesn't
exist; update the excludePaths entry that currently references the string
modules to append "(?)" so the path becomes optional per PHPStan syntax,
ensuring PHPStan will not error if the modules directory is missing.

In `@shared/Models/Post.php`:
- Around line 31-32: PostTransformer is concatenating $item->user_directory with
$item->image without a null guard, which can cause a type error; update the
output mapping (the 'image' key in PostTransformer) to only concatenate when
both $item->image and $item->user_directory are truthy (e.g., change the
conditional to require both before doing $item->user_directory . '/' .
$item->image) so it returns null otherwise.

In `@shared/Services/CommentService.php`:
- Around line 83-85: The getComment() method currently returns the result of
$this->model->criteria(...)->first() as a Comment even when the model is empty;
update getComment() to mirror AuthService::get()/update() by checking the
returned model's isEmpty() and return null for empty results (or change the
method signature to ?Comment and return null on isEmpty()), ensuring callers
receive null instead of an empty Comment instance; reference the getComment()
method and use the isEmpty() check before returning.

---

Nitpick comments:
In @.github/workflows/php.yml:
- Around line 48-49: The PHPStan step ("Run PHPStan" invoking "composer
phpstan") is running for every matrix entry and causing redundant CI runs;
modify the workflow so PHPStan runs only once by gating that step to a single
PHP version (e.g., add a condition like if: matrix.php == '8.1' for the "Run
PHPStan" step) or move the "Run PHPStan" step into a separate non-matrix job
that runs once, keeping the test jobs matrixed.

In `@phpstan.neon.dist`:
- Line 3: The PHPStan configuration in phpstan.neon.dist sets a stricter
analysis level (level: 5) than the PR objective (level 1); change the `level`
value in phpstan.neon.dist from 5 to 1 (or align it with the agreed project
standard) so CI and local tooling match the stated objective, and if you
intended to raise the teamwide level keep level: 5 but add a note in the PR or a
dedicated config change explaining the decision and coordinating with the team.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7c3e4a17-8e11-477c-b961-cf90b106c25a

📥 Commits

Reviewing files that changed from the base of the PR and between 524d742 and 66c1c06.

📒 Files selected for processing (23)
  • .gitattributes
  • .github/workflows/php.yml
  • composer.json
  • helpers/functions.php
  • phpstan.neon.dist
  • public/assets/shared/css/materialize.min.css
  • shared/Commands/CommentCreateCommand.php
  • shared/Commands/CommentDeleteCommand.php
  • shared/Commands/DemoCommand.php
  • shared/Commands/PostCreateCommand.php
  • shared/Commands/PostDeleteCommand.php
  • shared/Commands/PostShowCommand.php
  • shared/Commands/PostUpdateCommand.php
  • shared/Commands/UserCreateCommand.php
  • shared/Commands/UserDeleteCommand.php
  • shared/Commands/UserShowCommand.php
  • shared/Models/Comment.php
  • shared/Models/Post.php
  • shared/Models/User.php
  • shared/Services/AuthService.php
  • shared/Services/CommentService.php
  • shared/Services/PostService.php
  • shared/Transformers/PostTransformer.php

- Mark modules excludePath as optional in phpstan.neon.dist for CI compatibility

- Add null guard for user_directory in PostTransformer image concatenation

Made-with: Cursor
@armanist armanist merged commit 1347ec5 into softberg:master Apr 3, 2026
5 checks passed
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.

Integrate PHPStan into Quantum Starter Project

1 participant