class LoadIncludeBase
@template TNodeType of Node @implements Rule<TNodeType>
Hierarchy
- class \mglaman\PHPStanDrupal\Rules\Drupal\LoadIncludeBase implements \PHPStan\Rules\Rule
Expanded class hierarchy of LoadIncludeBase
File
-
vendor/
mglaman/ phpstan-drupal/ src/ Rules/ Drupal/ LoadIncludeBase.php, line 15
Namespace
mglaman\PHPStanDrupal\Rules\DrupalView source
abstract class LoadIncludeBase implements Rule {
/**
* @var \mglaman\PHPStanDrupal\Drupal\ExtensionMap
*/
protected $extensionMap;
public function __construct(ExtensionMap $extensionMap) {
$this->extensionMap = $extensionMap;
}
private function getStringArgValue(Node\Expr $expr, Scope $scope) : ?string {
$type = $scope->getType($expr);
$stringTypes = $type->getConstantStrings();
if (count($stringTypes) > 0) {
return $stringTypes[0]->getValue();
}
return null;
}
protected function parseLoadIncludeArgs(Node\Arg $module, Node\Arg $type, ?Node\Arg $name, Scope $scope) : array {
$moduleName = $this->getStringArgValue($module->value, $scope);
if ($moduleName === null) {
return [
false,
false,
];
}
$fileType = $this->getStringArgValue($type->value, $scope);
if ($fileType === null) {
return [
false,
false,
];
}
$baseName = null;
if ($name !== null) {
$baseName = $this->getStringArgValue($name->value, $scope);
if ($baseName === null) {
return [
false,
false,
];
}
}
if ($baseName === null) {
$baseName = $moduleName;
}
return [
$moduleName,
"{$baseName}.{$fileType}",
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
LoadIncludeBase::$extensionMap | protected | property | |
LoadIncludeBase::getStringArgValue | private | function | |
LoadIncludeBase::parseLoadIncludeArgs | protected | function | |
LoadIncludeBase::__construct | public | function |