Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DiscouragedFunctionsRule.php

class DiscouragedFunctionsRule

Based on Drupal_Sniffs_Functions_DiscouragedFunctionsSniff.

@implements Rule<FuncCall>

Hierarchy

  • class \mglaman\PHPStanDrupal\Rules\Drupal\Coder\DiscouragedFunctionsRule implements \PHPStan\Rules\Rule

Expanded class hierarchy of DiscouragedFunctionsRule

File

vendor/mglaman/phpstan-drupal/src/Rules/Drupal/Coder/DiscouragedFunctionsRule.php, line 18

Namespace

mglaman\PHPStanDrupal\Rules\Drupal\Coder
View source
class DiscouragedFunctionsRule implements Rule {
    public function getNodeType() : string {
        return FuncCall::class;
    }
    public function processNode(Node $node, Scope $scope) : array {
        if (!$node->name instanceof Node\Name) {
            return [];
        }
        $name = strtolower((string) $node->name);
        $discouragedFunctions = [
            // Devel module debugging functions.
'dargs',
            'dcp',
            'dd',
            'dfb',
            'dfbt',
            'dpm',
            'dpq',
            'dpr',
            'dprint_r',
            'drupal_debug',
            'dsm',
            'dvm',
            'dvr',
            'kdevel_print_object',
            'kpr',
            'kprint_r',
            'sdpm',
            // Functions which are not available on all
            // PHP builds.
'fnmatch',
            // Functions which are a security risk.
'eval',
        ];
        if (in_array($name, $discouragedFunctions, true)) {
            return [
                sprintf('Calls to function %s should not exist.', $name),
            ];
        }
        return [];
    }

}

Members

Title Sort descending Modifiers Object type Summary
DiscouragedFunctionsRule::getNodeType public function
DiscouragedFunctionsRule::processNode public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal