carthage-software/mago
Mago is an extremely fast PHP linter, formatter, and static analyzer written in Rust. It brings Rust-inspired speed and reliability to PHP projects with a modern toolchain and great developer experience, plus multiple install options (script, Homebrew, Composer).
This document details the rules available in the Deprecation category.
| Rule | Code |
|---|---|
| Deprecated Cast | deprecated-cast |
| Deprecated Shell Execute String | deprecated-shell-execute-string |
| Deprecated Switch Semicolon | deprecated-switch-semicolon |
| Explicit Nullable Param | explicit-nullable-param |
| No Underscore Class | no-underscore-class |
| No Void Reference Return | no-void-reference-return |
| Optional Parameter Before Required | optional-param-order |
deprecated-castDetect the usage of deprecated type casts in PHP code.
In PHP 8.5, the following type casts have been deprecated:
(integer): The integer cast has been deprecated in favor of (int).(boolean): The boolean cast has been deprecated in favor of (bool).(double): The double cast has been deprecated in favor of (float).(binary): The binary cast has been deprecated in favor of (string).8.5.0| Option | Type | Default |
|---|---|---|
enabled |
boolean |
true |
level |
string |
"error" |
<?php
(int) $value;
<?php
(integer) $value;
deprecated-shell-execute-stringDetect the usage of deprecated shell execute strings in PHP code.
In PHP 8.5, the shell execute string syntax (enclosed in backticks, e.g., `ls -l`) has been deprecated.
This rule identifies instances of shell execute strings and provides guidance on how to replace them with safer alternatives,
such as using the shell_exec() function or other appropriate methods for executing shell commands.
8.5.0| Option | Type | Default |
|---|---|---|
enabled |
boolean |
true |
level |
string |
"error" |
<?php
shell_exec('ls -l');
<?php
`ls -l`;
deprecated-switch-semicolonDetect the usage of semicolon as a switch case separator.
In PHP 8.5, the use of a semicolon (;) as a case separator in switch statements has been deprecated.
Instead, the colon (:) should be used to separate case statements.
8.5.0| Option | Type | Default |
|---|---|---|
enabled |
boolean |
true |
level |
string |
"error" |
<?php
switch ($value) {
case 1:
// code for case 1
break;
case 2:
// code for case 2
break;
default:
// default case
break;
}
<?php
switch ($value) {
case 1;
// code for case 1
break;
case 2;
// code for case 2
break;
default;
// default case
break;
}
explicit-nullable-paramDetects parameters that are implicitly nullable and rely on a deprecated feature.
Such parameters are considered deprecated; an explicit nullable type hint is recommended.
8.4.0| Option | Type | Default |
|---|---|---|
enabled |
boolean |
true |
level |
string |
"warning" |
<?php
function foo(?string $param) {}
function bar(null|string $param) {}
function baz(null|object $param = null) {}
<?php
function foo(string $param = null) {}
function bar(string $param = NULL) {}
function baz(object $param = null) {}
no-underscore-classDetects class, interface, trait, or enum declarations named _.
Such names are considered deprecated; a more descriptive identifier is recommended.
8.4.0| Option | Type | Default |
|---|---|---|
enabled |
boolean |
true |
level |
string |
"warning" |
<?php
class MyService {}
<?php
class _ {}
no-void-reference-returnDetects functions, methods, closures, arrow functions, and set property hooks that return by reference from a void function. Such functions are considered deprecated; returning by reference from a void function is deprecated since PHP 8.0.
8.2.0| Option | Type | Default |
|---|---|---|
enabled |
boolean |
true |
level |
string |
"warning" |
<?php
function &foo(): string {
// ...
}
<?php
function &foo(): void {
// ...
}
optional-param-order Detects optional parameters defined before required parameters in function-like declarations.
Such parameter order is considered deprecated; required parameters should precede optional parameters.
8.0.0| Option | Type | Default |
|---|---|---|
enabled |
boolean |
true |
level |
string |
"warning" |
<?php
function foo(string $required, ?string $optional = null): void {}
<?php
function foo(?string $optional = null, string $required): void {}
How can I help you explore Laravel packages today?