github carthage-software/mago 1.0.0-alpha.2
Mago 1.0.0-alpha.2

latest releases: 1.0.0-beta.10, 1.0.0-beta.9, 1.0.0-beta.8...
one month ago

Just a few hours after our first alpha, we're back with another release packed with new features, important bug fixes, and a ton of polish based on early feedback.

This release significantly enhances the analyzer's intelligence, particularly around inheritance and unused code detection.

✨ New & Noteworthy

Comprehensive Trait Validation is Here!

The analyzer is now much smarter about how it handles traits. Previously a todo comment, we now have a full suite of checks for use statements, including:

  • Invalid Usage: Mago will now report an error if you try to use a class or interface.
  • Contract Enforcement: The analyzer now correctly enforces @require-extends and @require-implements annotations on traits.
  • Inheritance Restrictions: Traits using the @inheritors tag are now correctly validated.
  • Mutability Rules: Using a @mutation-free or @external-mutation-free trait in a mutable class will now be flagged as an error.

Support for PHP 8.5's #[NoDiscard] Attribute

Looking ahead, Mago now understands and respects the new #[NoDiscard] attribute proposed for PHP 8.5. If you discard the return value of a function or method marked with this attribute, Mago will report an error, helping you write more robust and future-proof code.

🐞 Fixes & Polish

More Accurate Stubs for Built-in Functions

We've improved the stubs for several standard PHP functions, leading to more accurate type inference in your projects:

  • array_sum: Now correctly returns int if the input is an array<int>, and float otherwise (by @azjezz, closes #257).
  • in_array: The signature has been corrected to use the array's value type (V) for the $needle parameter, not the key type (by @azjezz, closes #259).
  • array_map: The return type now correctly preserves list type when appropriate (by @Nadyita in #254).
  • array_reverse: A typo in the conditional return type has been fixed (by @azjezz, closes #255).

Smarter Useless Statement Detection

The unused-statement check is now more intelligent and produces fewer false positives:

  • @must-use Fixed: The @must-use docblock tag is now parsed correctly.
  • By-Reference Parameters: Mago will no longer flag calls to @pure functions as useless if they have by-reference parameters, as they can produce side effects (by @azjezz, closes #258)

Drastically Improved Error Messages

We've overhauled the error messages for all inheritance-related checks (extends, implements, and use). The new messages are clearer, more consistent, and provide more context to help you fix issues faster.


New Contributors


Full Changelog: 1.0.0-alpha.1...1.0.0-alpha.2

Don't miss a new mago release

NewReleases is sending notifications on new releases.