Skip to content

feat: add mago analyze#205

Draft
Morgy93 wants to merge 2 commits into
mainfrom
feat/mago-analyze
Draft

feat: add mago analyze#205
Morgy93 wants to merge 2 commits into
mainfrom
feat/mago-analyze

Conversation

@Morgy93

@Morgy93 Morgy93 commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

This pull request introduces a new, more efficient static analysis workflow for the project, consolidating and optimizing how static analysis tools (PHPStan and Mago) are run in CI. It removes the old PHPStan workflow and replaces it with a unified workflow that builds Magento once and reuses this build for all static analysis jobs, reducing duplication and improving performance. Additionally, there are minor improvements and consistency fixes in CLI commands and scripts, as well as configuration updates for the Mago static analyzer.

Static Analysis Workflow Improvements:

  • Added .github/workflows/static-analysis.yml, which builds a single Magento install and shares it as an artifact for both PHPStan and Mago analysis jobs. This enables parallel static analysis without redundant Magento builds, improving CI efficiency.
  • Removed the old .github/workflows/phpstan.yml workflow, which previously handled PHPStan analysis and Magento setup separately, now superseded by the new unified workflow.

Mago Integration and Configuration:

  • Enhanced .ddev/commands/web/mago to support a new analyze command that runs static analysis against the installed Magento, matching CI behavior. This ensures consistent analysis results locally and in CI. [1] [2]
  • Updated mago.toml to exclude .phtml template files from static analysis (since they rely on runtime-injected variables) and to ignore certain mixed-* warnings that are common in Magento code but not actionable.

Code Quality and CLI Consistency:

  • Standardized option filtering logic in interactive CLI prompts for theme-related commands, improving readability and consistency across commands like Theme\BuildCommand, Theme\CleanCommand, Theme\TokensCommand, and Theme\WatchCommand. [1] [2] [3] [4]
  • Ensured type consistency by casting indexes to int where necessary in theme processing loops. [1] [2]
  • Minor code quality fixes, such as using PHP_VERSION instead of phpversion(), casting results from ini_get and constants, and simplifying SQL in CheckCommand. [1] [2] [3] [4] [5]

These changes collectively streamline static analysis, improve developer experience, and ensure more reliable and consistent CI results.

Morgy93 and others added 2 commits June 24, 2026 14:16
Introduce a Static Analysis workflow that builds a full Magento install
once and runs PHPStan and `mago analyze` against it in parallel, instead
of each tool rebuilding Magento. Replaces the standalone PHPStan workflow
(the PHPStan job keeps the same "PHPStan Analysis" check name).

- static-analysis.yml: a build-magento job uploads the install as an
  artifact; the phpstan and mago-analyze jobs consume it without a live
  database (static analysis only reads code). phpstan.neon is copied into
  the install because it is export-ignored from the path-repo copy.
- mago.toml: exclude phtml templates from analysis (runtime-injected
  template scope) and ignore the Magento-idiomatic mixed-assignment /
  mixed-operand codes (PHPStan level 9 is the type gate for those).
- ddev: `ddev mago analyze` now runs against the installed Magento so it
  resolves the full class graph, matching what CI analyzes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fix the type errors mago analyze reports against a full Magento install:

- CheckCommand: cast ini_get('memory_limit') (string|false declared
  string); use the PHP_VERSION constant instead of phpversion(); read the
  MySQL version via fetchOne('SELECT VERSION()') instead of from(null).
- Type loose framework return values via inline @var (getPaths() ->
  array<string,string>, getAllBlocks() -> BlockInterface[]).
- Cast mixed operands/arguments: theme loop index, hrtime() metrics,
  stat() mode, and the getOption() flags used in a boolean expression.
- InspectorHints: widen render()'s $dictionary param to match the parent
  TemplateEngineInterface; cast the BP constant to string.
- Drop redundant (string) casts and an obsolete @var docblock.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Morgy93 Morgy93 force-pushed the feat/mago-analyze branch from f41408c to bca9b1a Compare June 24, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant