Ported from phpstan-drupal¶
These rules port checks of phpstan-drupal that need only the syntax.
drupal/discouraged-function¶
- Level: error
- Fix: none
- Source: Coder's
Drupalstandard and phpstan-drupal - Ports:
Drupal.Functions.DiscouragedFunctions.Discouraged- phpstan-drupal's
DiscouragedFunctionsRule
Coder and phpstan-drupal report calls to debug helpers and to functions that aren't always available.
Reports:
- a call to a dump helper of the devel module, such as
dpm(),dsm(),ksm()orkint(). The devel helpers are the ones listed by Coder 9. A first-class callable such asdpm(...)counts as a call; - a call to
fnmatch(), which some PHP builds don't have.
Coder 9 also lists eval, which is reported by Mago's own no-eval rule.
Compared with Coder and phpstan-drupal
- phpstan-drupal's list leaves out
ddebug_backtrace(),ddm(),kint()andksm(), and it doesn't report a first-class callable such asdpm(...). - Coder reports each call as a warning, where the rule reports an error.
drupal/render-callback¶
- Level: error
- Fix: none
- Source: phpstan-drupal
- Ports: phpstan-drupal's
RenderCallbackRule, the part that needs only the syntax
phpstan-drupal reports a render callback not trusted by
Drupal. Drupal trusts only closures, service:method strings and class methods that their class
marks as trusted.
Reports:
- a render callback that is a plain function name string, in the callbacks of:
#pre_render,#post_render,#lazy_builderand#access_callback;- the date callbacks
#date_date_callbacksand#date_time_callbacks; - the component callbacks
#propsAlterand#slotsAlter;
- a value of those keys that isn't an array literal at all, such as
'#pre_render' => $callbacks, because there isn't anything to check there.
Not reported:
#lazy_builderin core'sRendererandPlaceholderGenerator, because they pass the key througharray_intersect_key().
Example
// Reported.
$build = [
'#markup' => '',
'#pre_render' => ['example_pre_render'],
];
// Fine.
$build = [
'#markup' => '',
'#pre_render' => [static fn (array $element): array => $element],
];
Whether Drupal trusts the class method that a callback names is the analyzer's
drupal/untrusted-callback, and a
closure under these keys in a form is its
drupal/form-closure-callback. See
Render and form callbacks.
Compared with phpstan-drupal
- phpstan-drupal doesn't check the component callbacks
#propsAlterand#slotsAlter.
drupal/symfony-yaml-parse¶
- Level: warning
- Fix: none
- Source: phpstan-drupal
- Ports: phpstan-drupal's
SymfonyYamlParseRule
phpstan-drupal reports a parse with Symfony's YAML component. Drupal's own
\Drupal\Component\Serialization\Yaml::decode() picks the fast parser when it is available and
applies Drupal's parser flags.
Reports:
- a
Symfony\Component\Yaml\Yaml::parse()call.
Example
// Reported.
use Symfony\Component\Yaml\Yaml;
$data = Yaml::parse($text);
// Fine.
use Drupal\Component\Serialization\Yaml;
$data = Yaml::decode($text);
drupal/todo-current-issue¶
- Level: error
- Fix: none
- Source: phpstan-drupal
- Ports: phpstan-drupal's
TodoCommentWithIssueUrlRule
phpstan-drupal reports a @todo comment that links the drupal.org issue of the current merge
request. A merge request should resolve its own to-dos rather than land them.
Reports:
- a
@todocomment that links the issue ashttps://www.drupal.org/i/3456789,https://www.drupal.org/node/3456789orhttps://www.drupal.org/project/mymodule/issues/3456789.
Not reported:
- anything outside a GitLab merge request pipeline. The issue number comes from the variables set by
GitLab CI there: the digits at the start of
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME, as in3456789-fix-thing, or at the end ofCI_MERGE_REQUEST_SOURCE_PROJECT_PATH, as inissue/mymodule-3456789.
Outside such a pipeline the rule has nothing to compare and stays silent, so it is on by default. phpstan-drupal's rule has to be added by hand.
Compared with phpstan-drupal
- phpstan-drupal doesn't read a
https://www.drupal.org/node/3456789link as the issue. The rule does.