Mago 1.0.0-beta.28
This release is packed with significant correctness fixes for the analyzer, focusing on advanced type system features like enums, generics, and traits. The formatter also receives critical bug fixes for operator precedence and brace placement.
A massive thank you to our community for driving this release forward with their contributions: @bendavies, @yankewei, @dragosprotung, and @muro3r!
🚀 Analyzer Correctness Fixes
The analyzer's accuracy has been substantially improved with fixes for several fundamental type system and control flow bugs.
-
Enum Method Analysis (#546): The analyzer now synthetically generates full metadata for built-in enum methods (
from
,tryFrom
,cases
). This provides precise parameter and return types, enabling correct analysis of first-class callables likeCategory::from(...)
. -
Template & Type System Correctness:
- Inherited Templates (#535): Template types defined via
extends
orimplements
on an interface or class are now correctly resolved and applied. enum_exists
Narrowing (#541): Fixed a bug where intersecting a specific class with a generic type would incorrectly discard the more specific class information, improving type narrowing after checks likeenum_exists()
.count()
Assertions (#540): Assertions fromcount()
calls (e.g.,if (count($arr) > 0)
) are now correctly applied, allowing the analyzer to understand that an array is non-empty.
- Inherited Templates (#535): Template types defined via
-
Flow PHP Types Support (#527): Added special handling for the
flow-php/types
library, including support for itstype_structure()
function. (Thanks, @bendavies!) -
Imagick Support (#543): The analyzer now has stubs for
Imagick
class constants, improving type safety when working with the Imagick extension. (Thanks, @dragosprotung!)
💅 Formatter Fixes
-
Operator Precedence with
clone
(#536): Fixed a critical bug where the formatter would incorrectly remove parentheses from a ternary expression inside aclone()
call, which would change the code's behavior. The logic is now more robust for other unary constructs as well. -
Brace Placement (#545): Corrected an issue where the opening brace for functions or methods with long signatures but short parameter lists was being placed on the same line, violating the
NextLine
brace style.
✨ Linter Updates
-
yoda-conditions
Rule Disabled by Default (#505): In response to community feedback, theyoda-conditions
rule is now disabled by default. It was found to be too noisy for many projects, and its primary goal of preventing accidental assignments is already covered by theno-assign-in-condition
rule. Teams that prefer this style can still enable it in theirmago.toml
. -
New Rule:
no-variable-variable
: A new rule has been added to disallow the use of variable-variables (e.g.,$$foo
), which can make code difficult to understand and analyze. -
no-redundant-use
Improvements: This rule has been improved to understand Tempest view classes, reducing false positives in projects using this framework. (#532)
🤝 New Contributors
- @muro3r made their first contribution in #544
- @dragosprotung made their first contribution in #543
- @yankewei made their first contribution in #547
Full Changelog: 1.0.0-beta.27...1.0.0-beta.28