function DocBlock::requirements
@psalm-return array{ __OFFSET: array<string, int>&array{__FILE: string}, setting?: array<string, string>, extension_versions?: array<string, array{version: string, operator: string}> }&array< string, string|array{version: string, operator: string}|array{constraint: string}|array<int|string, string> >
Throws
InvalidVersionRequirementException
File
-
vendor/
phpunit/ phpunit/ src/ Metadata/ Parser/ Annotation/ DocBlock.php, line 128
Class
- DocBlock
- This is an abstraction around a PHPUnit-specific docBlock, allowing us to ask meaningful questions about a specific reflection symbol.
Namespace
PHPUnit\Metadata\Annotation\ParserCode
public function requirements() : array {
if ($this->parsedRequirements !== null) {
return $this->parsedRequirements;
}
$offset = $this->startLine;
$requires = [];
$recordedSettings = [];
$extensionVersions = [];
$recordedOffsets = [
'__FILE' => realpath($this->fileName),
];
// Trim docblock markers, split it into lines and rewind offset to start of docblock
$lines = preg_replace([
'#^/\\*{2}#',
'#\\*/$#',
], '', preg_split('/\\r\\n|\\r|\\n/', $this->docComment));
$offset -= count($lines);
foreach ($lines as $line) {
if (preg_match(self::REGEX_REQUIRES_OS, $line, $matches)) {
$requires[$matches['name']] = $matches['value'];
$recordedOffsets[$matches['name']] = $offset;
}
if (preg_match(self::REGEX_REQUIRES_VERSION, $line, $matches)) {
$requires[$matches['name']] = [
'version' => $matches['version'],
'operator' => $matches['operator'],
];
$recordedOffsets[$matches['name']] = $offset;
}
if (preg_match(self::REGEX_REQUIRES_VERSION_CONSTRAINT, $line, $matches)) {
if (!empty($requires[$matches['name']])) {
$offset++;
continue;
}
try {
$versionConstraintParser = new VersionConstraintParser();
$requires[$matches['name'] . '_constraint'] = [
'constraint' => $versionConstraintParser->parse(trim($matches['constraint'])),
];
$recordedOffsets[$matches['name'] . '_constraint'] = $offset;
} catch (PharIoVersionException $e) {
throw new InvalidVersionRequirementException($e->getMessage(), $e->getCode(), $e);
}
}
if (preg_match(self::REGEX_REQUIRES_SETTING, $line, $matches)) {
$recordedSettings[$matches['setting']] = $matches['value'];
$recordedOffsets['__SETTING_' . $matches['setting']] = $offset;
}
if (preg_match(self::REGEX_REQUIRES, $line, $matches)) {
$name = $matches['name'] . 's';
if (!isset($requires[$name])) {
$requires[$name] = [];
}
$requires[$name][] = $matches['value'];
$recordedOffsets[$matches['name'] . '_' . $matches['value']] = $offset;
if ($name === 'extensions' && !empty($matches['version'])) {
$extensionVersions[$matches['value']] = [
'version' => $matches['version'],
'operator' => $matches['operator'],
];
}
}
$offset++;
}
return $this->parsedRequirements = array_merge($requires, [
'__OFFSET' => $recordedOffsets,
], array_filter([
'setting' => $recordedSettings,
'extension_versions' => $extensionVersions,
]));
}