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

Breadcrumb

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

function DataProviderHelper::processDataProvider

*

Return value

list<IdentifierRuleError> errors

File

vendor/phpstan/phpstan-phpunit/src/Rules/PHPUnit/DataProviderHelper.php, line 135

Class

DataProviderHelper

Namespace

PHPStan\Rules\PHPUnit

Code

public function processDataProvider(string $dataProviderValue, ?ClassReflection $classReflection, string $methodName, int $lineNumber, bool $checkFunctionNameCase, bool $deprecationRulesInstalled) : array {
    if ($classReflection === null) {
        return [
            RuleErrorBuilder::message(sprintf('@dataProvider %s related class not found.', $dataProviderValue))->line($lineNumber)
                ->identifier('phpunit.dataProviderClass')
                ->build(),
        ];
    }
    try {
        $dataProviderMethodReflection = $classReflection->getNativeMethod($methodName);
    } catch (MissingMethodFromReflectionException $missingMethodFromReflectionException) {
        return [
            RuleErrorBuilder::message(sprintf('@dataProvider %s related method not found.', $dataProviderValue))->line($lineNumber)
                ->identifier('phpunit.dataProviderMethod')
                ->build(),
        ];
    }
    $errors = [];
    if ($checkFunctionNameCase && $methodName !== $dataProviderMethodReflection->getName()) {
        $errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method is used with incorrect case: %s.', $dataProviderValue, $dataProviderMethodReflection->getName()))
            ->line($lineNumber)
            ->identifier('method.nameCase')
            ->build();
    }
    if (!$dataProviderMethodReflection->isPublic()) {
        $errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method must be public.', $dataProviderValue))->line($lineNumber)
            ->identifier('phpunit.dataProviderPublic')
            ->build();
    }
    if ($deprecationRulesInstalled && $this->phpunit10OrNewer && !$dataProviderMethodReflection->isStatic()) {
        $errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method must be static in PHPUnit 10 and newer.', $dataProviderValue))->line($lineNumber)
            ->identifier('phpunit.dataProviderStatic')
            ->build();
    }
    return $errors;
}

API Navigation

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