code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function __construct(string $name, AbstractNode $parent, array $lineCoverageData, array $functionCoverageData, array $testData, array $classes, array $traits, array $functions, LinesOfCode $linesOfCode)
{
parent::__construct($name, $parent);
$this->lineCoverageData = $lineCoverageData;
$this->functionCoverageData = $functionCoverageData;
$this->testData = $testData;
$this->linesOfCode = $linesOfCode;
$this->calculateStatistics($classes, $traits, $functions);
}
|
@param array<int, ?list<non-empty-string>> $lineCoverageData
@param array<string, TestType> $testData
@param array<string, Class_> $classes
@param array<string, Trait_> $traits
@param array<string, Function_> $functions
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/Node/File.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Node/File.php
|
BSD-3-Clause
|
public function lineCoverageData(): array
{
return $this->lineCoverageData;
}
|
@return array<int, ?list<non-empty-string>>
|
lineCoverageData
|
php
|
sebastianbergmann/php-code-coverage
|
src/Node/File.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Node/File.php
|
BSD-3-Clause
|
private function calculateStatistics(array $classes, array $traits, array $functions): void
{
foreach (range(1, $this->linesOfCode->linesOfCode()) as $lineNumber) {
$this->codeUnitsByLine[$lineNumber] = [];
}
$this->processClasses($classes);
$this->processTraits($traits);
$this->processFunctions($functions);
foreach (range(1, $this->linesOfCode->linesOfCode()) as $lineNumber) {
if (isset($this->lineCoverageData[$lineNumber])) {
foreach ($this->codeUnitsByLine[$lineNumber] as &$codeUnit) {
$codeUnit['executableLines']++;
}
unset($codeUnit);
$this->numExecutableLines++;
if (count($this->lineCoverageData[$lineNumber]) > 0) {
foreach ($this->codeUnitsByLine[$lineNumber] as &$codeUnit) {
$codeUnit['executedLines']++;
}
unset($codeUnit);
$this->numExecutedLines++;
}
}
}
foreach ($this->traits as &$trait) {
foreach ($trait['methods'] as &$method) {
$methodLineCoverage = $method['executableLines'] > 0 ? ($method['executedLines'] / $method['executableLines']) * 100 : 100;
$methodBranchCoverage = $method['executableBranches'] > 0 ? ($method['executedBranches'] / $method['executableBranches']) * 100 : 0;
$methodPathCoverage = $method['executablePaths'] > 0 ? ($method['executedPaths'] / $method['executablePaths']) * 100 : 0;
$method['coverage'] = $methodBranchCoverage > 0 ? $methodBranchCoverage : $methodLineCoverage;
$method['crap'] = (new CrapIndex($method['ccn'], $methodPathCoverage > 0 ? $methodPathCoverage : $methodLineCoverage))->asString();
$trait['ccn'] += $method['ccn'];
}
unset($method);
$traitLineCoverage = $trait['executableLines'] > 0 ? ($trait['executedLines'] / $trait['executableLines']) * 100 : 100;
$traitBranchCoverage = $trait['executableBranches'] > 0 ? ($trait['executedBranches'] / $trait['executableBranches']) * 100 : 0;
$traitPathCoverage = $trait['executablePaths'] > 0 ? ($trait['executedPaths'] / $trait['executablePaths']) * 100 : 0;
$trait['coverage'] = $traitBranchCoverage > 0 ? $traitBranchCoverage : $traitLineCoverage;
$trait['crap'] = (new CrapIndex($trait['ccn'], $traitPathCoverage > 0 ? $traitPathCoverage : $traitLineCoverage))->asString();
if ($trait['executableLines'] > 0 && $trait['coverage'] === 100) {
$this->numTestedClasses++;
}
}
unset($trait);
foreach ($this->classes as &$class) {
foreach ($class['methods'] as &$method) {
$methodLineCoverage = $method['executableLines'] > 0 ? ($method['executedLines'] / $method['executableLines']) * 100 : 100;
$methodBranchCoverage = $method['executableBranches'] > 0 ? ($method['executedBranches'] / $method['executableBranches']) * 100 : 0;
$methodPathCoverage = $method['executablePaths'] > 0 ? ($method['executedPaths'] / $method['executablePaths']) * 100 : 0;
$method['coverage'] = $methodBranchCoverage > 0 ? $methodBranchCoverage : $methodLineCoverage;
$method['crap'] = (new CrapIndex($method['ccn'], $methodPathCoverage > 0 ? $methodPathCoverage : $methodLineCoverage))->asString();
$class['ccn'] += $method['ccn'];
}
unset($method);
$classLineCoverage = $class['executableLines'] > 0 ? ($class['executedLines'] / $class['executableLines']) * 100 : 100;
$classBranchCoverage = $class['executableBranches'] > 0 ? ($class['executedBranches'] / $class['executableBranches']) * 100 : 0;
$classPathCoverage = $class['executablePaths'] > 0 ? ($class['executedPaths'] / $class['executablePaths']) * 100 : 0;
$class['coverage'] = $classBranchCoverage > 0 ? $classBranchCoverage : $classLineCoverage;
$class['crap'] = (new CrapIndex($class['ccn'], $classPathCoverage > 0 ? $classPathCoverage : $classLineCoverage))->asString();
if ($class['executableLines'] > 0 && $class['coverage'] === 100) {
$this->numTestedClasses++;
}
}
unset($class);
foreach ($this->functions as &$function) {
$functionLineCoverage = $function['executableLines'] > 0 ? ($function['executedLines'] / $function['executableLines']) * 100 : 100;
$functionBranchCoverage = $function['executableBranches'] > 0 ? ($function['executedBranches'] / $function['executableBranches']) * 100 : 0;
$functionPathCoverage = $function['executablePaths'] > 0 ? ($function['executedPaths'] / $function['executablePaths']) * 100 : 0;
$function['coverage'] = $functionBranchCoverage > 0 ? $functionBranchCoverage : $functionLineCoverage;
$function['crap'] = (new CrapIndex($function['ccn'], $functionPathCoverage > 0 ? $functionPathCoverage : $functionLineCoverage))->asString();
if ($function['coverage'] === 100) {
$this->numTestedFunctions++;
}
}
}
|
@param array<string, Class_> $classes
@param array<string, Trait_> $traits
@param array<string, Function_> $functions
|
calculateStatistics
|
php
|
sebastianbergmann/php-code-coverage
|
src/Node/File.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Node/File.php
|
BSD-3-Clause
|
protected function renderItemTemplate(Template $template, array $data): string
{
$numSeparator = ' / ';
if (isset($data['numClasses']) && $data['numClasses'] > 0) {
$classesLevel = $this->colorLevel($data['testedClassesPercent']);
$classesNumber = $data['numTestedClasses'] . $numSeparator .
$data['numClasses'];
$classesBar = $this->coverageBar(
$data['testedClassesPercent'],
);
} else {
$classesLevel = '';
$classesNumber = '0' . $numSeparator . '0';
$classesBar = '';
$data['testedClassesPercentAsString'] = 'n/a';
}
if ($data['numMethods'] > 0) {
$methodsLevel = $this->colorLevel($data['testedMethodsPercent']);
$methodsNumber = $data['numTestedMethods'] . $numSeparator .
$data['numMethods'];
$methodsBar = $this->coverageBar(
$data['testedMethodsPercent'],
);
} else {
$methodsLevel = '';
$methodsNumber = '0' . $numSeparator . '0';
$methodsBar = '';
$data['testedMethodsPercentAsString'] = 'n/a';
}
if ($data['numExecutableLines'] > 0) {
$linesLevel = $this->colorLevel($data['linesExecutedPercent']);
$linesNumber = $data['numExecutedLines'] . $numSeparator .
$data['numExecutableLines'];
$linesBar = $this->coverageBar(
$data['linesExecutedPercent'],
);
} else {
$linesLevel = '';
$linesNumber = '0' . $numSeparator . '0';
$linesBar = '';
$data['linesExecutedPercentAsString'] = 'n/a';
}
if ($data['numExecutablePaths'] > 0) {
$pathsLevel = $this->colorLevel($data['pathsExecutedPercent']);
$pathsNumber = $data['numExecutedPaths'] . $numSeparator .
$data['numExecutablePaths'];
$pathsBar = $this->coverageBar(
$data['pathsExecutedPercent'],
);
} else {
$pathsLevel = '';
$pathsNumber = '0' . $numSeparator . '0';
$pathsBar = '';
$data['pathsExecutedPercentAsString'] = 'n/a';
}
if ($data['numExecutableBranches'] > 0) {
$branchesLevel = $this->colorLevel($data['branchesExecutedPercent']);
$branchesNumber = $data['numExecutedBranches'] . $numSeparator .
$data['numExecutableBranches'];
$branchesBar = $this->coverageBar(
$data['branchesExecutedPercent'],
);
} else {
$branchesLevel = '';
$branchesNumber = '0' . $numSeparator . '0';
$branchesBar = '';
$data['branchesExecutedPercentAsString'] = 'n/a';
}
$template->setVar(
[
'icon' => $data['icon'] ?? '',
'crap' => $data['crap'] ?? '',
'name' => $data['name'],
'lines_bar' => $linesBar,
'lines_executed_percent' => $data['linesExecutedPercentAsString'],
'lines_level' => $linesLevel,
'lines_number' => $linesNumber,
'paths_bar' => $pathsBar,
'paths_executed_percent' => $data['pathsExecutedPercentAsString'],
'paths_level' => $pathsLevel,
'paths_number' => $pathsNumber,
'branches_bar' => $branchesBar,
'branches_executed_percent' => $data['branchesExecutedPercentAsString'],
'branches_level' => $branchesLevel,
'branches_number' => $branchesNumber,
'methods_bar' => $methodsBar,
'methods_tested_percent' => $data['testedMethodsPercentAsString'],
'methods_level' => $methodsLevel,
'methods_number' => $methodsNumber,
'classes_bar' => $classesBar,
'classes_tested_percent' => $data['testedClassesPercentAsString'] ?? '',
'classes_level' => $classesLevel,
'classes_number' => $classesNumber,
],
);
return $template->render();
}
|
@param array<non-empty-string, float|int|string> $data
|
renderItemTemplate
|
php
|
sebastianbergmann/php-code-coverage
|
src/Report/Html/Renderer.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Report/Html/Renderer.php
|
BSD-3-Clause
|
private function complexity(array $classes, string $baseLink): array
{
$result = ['class' => [], 'method' => []];
foreach ($classes as $className => $class) {
foreach ($class['methods'] as $methodName => $method) {
if ($className !== '*') {
$methodName = $className . '::' . $methodName;
}
$result['method'][] = [
$method['coverage'],
$method['ccn'],
str_replace($baseLink, '', $method['link']),
$methodName,
];
}
$result['class'][] = [
$class['coverage'],
$class['ccn'],
str_replace($baseLink, '', $class['link']),
$className,
];
}
$class = json_encode($result['class']);
assert($class !== false);
$method = json_encode($result['method']);
assert($method !== false);
return ['class' => $class, 'method' => $method];
}
|
@param array<string, ProcessedClassType|ProcessedTraitType> $classes
@return array{class: non-empty-string, method: non-empty-string}
|
complexity
|
php
|
sebastianbergmann/php-code-coverage
|
src/Report/Html/Renderer/Dashboard.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Report/Html/Renderer/Dashboard.php
|
BSD-3-Clause
|
private function coverageDistribution(array $classes): array
{
$result = [
'class' => [
'0%' => 0,
'0-10%' => 0,
'10-20%' => 0,
'20-30%' => 0,
'30-40%' => 0,
'40-50%' => 0,
'50-60%' => 0,
'60-70%' => 0,
'70-80%' => 0,
'80-90%' => 0,
'90-100%' => 0,
'100%' => 0,
],
'method' => [
'0%' => 0,
'0-10%' => 0,
'10-20%' => 0,
'20-30%' => 0,
'30-40%' => 0,
'40-50%' => 0,
'50-60%' => 0,
'60-70%' => 0,
'70-80%' => 0,
'80-90%' => 0,
'90-100%' => 0,
'100%' => 0,
],
];
foreach ($classes as $class) {
foreach ($class['methods'] as $methodName => $method) {
if ($method['coverage'] === 0) {
$result['method']['0%']++;
} elseif ($method['coverage'] === 100) {
$result['method']['100%']++;
} else {
$key = floor($method['coverage'] / 10) * 10;
$key = $key . '-' . ($key + 10) . '%';
$result['method'][$key]++;
}
}
if ($class['coverage'] === 0) {
$result['class']['0%']++;
} elseif ($class['coverage'] === 100) {
$result['class']['100%']++;
} else {
$key = floor($class['coverage'] / 10) * 10;
$key = $key . '-' . ($key + 10) . '%';
$result['class'][$key]++;
}
}
$class = json_encode(array_values($result['class']));
assert($class !== false);
$method = json_encode(array_values($result['method']));
assert($method !== false);
return ['class' => $class, 'method' => $method];
}
|
@param array<string, ProcessedClassType|ProcessedTraitType> $classes
@return array{class: non-empty-string, method: non-empty-string}
|
coverageDistribution
|
php
|
sebastianbergmann/php-code-coverage
|
src/Report/Html/Renderer/Dashboard.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Report/Html/Renderer/Dashboard.php
|
BSD-3-Clause
|
private function insufficientCoverage(array $classes, string $baseLink): array
{
$leastTestedClasses = [];
$leastTestedMethods = [];
$result = ['class' => '', 'method' => ''];
foreach ($classes as $className => $class) {
foreach ($class['methods'] as $methodName => $method) {
if ($method['coverage'] < $this->thresholds->highLowerBound()) {
$key = $methodName;
if ($className !== '*') {
$key = $className . '::' . $methodName;
}
$leastTestedMethods[$key] = $method['coverage'];
}
}
if ($class['coverage'] < $this->thresholds->highLowerBound()) {
$leastTestedClasses[$className] = $class['coverage'];
}
}
asort($leastTestedClasses);
asort($leastTestedMethods);
foreach ($leastTestedClasses as $className => $coverage) {
$result['class'] .= sprintf(
' <tr><td><a href="%s">%s</a></td><td class="text-right">%d%%</td></tr>' . "\n",
str_replace($baseLink, '', $classes[$className]['link']),
$className,
$coverage,
);
}
foreach ($leastTestedMethods as $methodName => $coverage) {
[$class, $method] = explode('::', $methodName);
$result['method'] .= sprintf(
' <tr><td><a href="%s"><abbr title="%s">%s</abbr></a></td><td class="text-right">%d%%</td></tr>' . "\n",
str_replace($baseLink, '', $classes[$class]['methods'][$method]['link']),
$methodName,
$method,
$coverage,
);
}
return $result;
}
|
@param array<string, ProcessedClassType|ProcessedTraitType> $classes
@return array{class: string, method: string}
|
insufficientCoverage
|
php
|
sebastianbergmann/php-code-coverage
|
src/Report/Html/Renderer/Dashboard.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Report/Html/Renderer/Dashboard.php
|
BSD-3-Clause
|
private function projectRisks(array $classes, string $baseLink): array
{
$classRisks = [];
$methodRisks = [];
$result = ['class' => '', 'method' => ''];
foreach ($classes as $className => $class) {
foreach ($class['methods'] as $methodName => $method) {
if ($method['coverage'] < $this->thresholds->highLowerBound() && $method['ccn'] > 1) {
$key = $methodName;
if ($className !== '*') {
$key = $className . '::' . $methodName;
}
$methodRisks[$key] = $method['crap'];
}
}
if ($class['coverage'] < $this->thresholds->highLowerBound() &&
$class['ccn'] > count($class['methods'])) {
$classRisks[$className] = $class['crap'];
}
}
arsort($classRisks);
arsort($methodRisks);
foreach ($classRisks as $className => $crap) {
$result['class'] .= sprintf(
' <tr><td><a href="%s">%s</a></td><td class="text-right">%d</td></tr>' . "\n",
str_replace($baseLink, '', $classes[$className]['link']),
$className,
$crap,
);
}
foreach ($methodRisks as $methodName => $crap) {
[$class, $method] = explode('::', $methodName);
$result['method'] .= sprintf(
' <tr><td><a href="%s"><abbr title="%s">%s</abbr></a></td><td class="text-right">%d</td></tr>' . "\n",
str_replace($baseLink, '', $classes[$class]['methods'][$method]['link']),
$methodName,
$method,
$crap,
);
}
return $result;
}
|
@param array<string, ProcessedClassType|ProcessedTraitType> $classes
@return array{class: string, method: string}
|
projectRisks
|
php
|
sebastianbergmann/php-code-coverage
|
src/Report/Html/Renderer/Dashboard.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Report/Html/Renderer/Dashboard.php
|
BSD-3-Clause
|
private function renderTraitOrClassItems(array $items, Template $template, Template $methodItemTemplate): string
{
$buffer = '';
if ($items === []) {
return $buffer;
}
foreach ($items as $name => $item) {
$numMethods = 0;
$numTestedMethods = 0;
foreach ($item['methods'] as $method) {
if ($method['executableLines'] > 0) {
$numMethods++;
if ($method['executedLines'] === $method['executableLines']) {
$numTestedMethods++;
}
}
}
if ($item['executableLines'] > 0) {
$numClasses = 1;
$numTestedClasses = $numTestedMethods === $numMethods ? 1 : 0;
$linesExecutedPercentAsString = Percentage::fromFractionAndTotal(
$item['executedLines'],
$item['executableLines'],
)->asString();
$branchesExecutedPercentAsString = Percentage::fromFractionAndTotal(
$item['executedBranches'],
$item['executableBranches'],
)->asString();
$pathsExecutedPercentAsString = Percentage::fromFractionAndTotal(
$item['executedPaths'],
$item['executablePaths'],
)->asString();
} else {
$numClasses = 0;
$numTestedClasses = 0;
$linesExecutedPercentAsString = 'n/a';
$branchesExecutedPercentAsString = 'n/a';
$pathsExecutedPercentAsString = 'n/a';
}
$testedMethodsPercentage = Percentage::fromFractionAndTotal(
$numTestedMethods,
$numMethods,
);
$testedClassesPercentage = Percentage::fromFractionAndTotal(
$numTestedMethods === $numMethods ? 1 : 0,
1,
);
$buffer .= $this->renderItemTemplate(
$template,
[
'name' => $this->abbreviateClassName($name),
'numClasses' => $numClasses,
'numTestedClasses' => $numTestedClasses,
'numMethods' => $numMethods,
'numTestedMethods' => $numTestedMethods,
'linesExecutedPercent' => Percentage::fromFractionAndTotal(
$item['executedLines'],
$item['executableLines'],
)->asFloat(),
'linesExecutedPercentAsString' => $linesExecutedPercentAsString,
'numExecutedLines' => $item['executedLines'],
'numExecutableLines' => $item['executableLines'],
'branchesExecutedPercent' => Percentage::fromFractionAndTotal(
$item['executedBranches'],
$item['executableBranches'],
)->asFloat(),
'branchesExecutedPercentAsString' => $branchesExecutedPercentAsString,
'numExecutedBranches' => $item['executedBranches'],
'numExecutableBranches' => $item['executableBranches'],
'pathsExecutedPercent' => Percentage::fromFractionAndTotal(
$item['executedPaths'],
$item['executablePaths'],
)->asFloat(),
'pathsExecutedPercentAsString' => $pathsExecutedPercentAsString,
'numExecutedPaths' => $item['executedPaths'],
'numExecutablePaths' => $item['executablePaths'],
'testedMethodsPercent' => $testedMethodsPercentage->asFloat(),
'testedMethodsPercentAsString' => $testedMethodsPercentage->asString(),
'testedClassesPercent' => $testedClassesPercentage->asFloat(),
'testedClassesPercentAsString' => $testedClassesPercentage->asString(),
'crap' => $item['crap'],
],
);
foreach ($item['methods'] as $method) {
$buffer .= $this->renderFunctionOrMethodItem(
$methodItemTemplate,
$method,
' ',
);
}
}
return $buffer;
}
|
@param array<string, ProcessedClassType|ProcessedTraitType> $items
|
renderTraitOrClassItems
|
php
|
sebastianbergmann/php-code-coverage
|
src/Report/Html/Renderer/File.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Report/Html/Renderer/File.php
|
BSD-3-Clause
|
private function loadFile(string $file): array
{
if (isset(self::$formattedSourceCache[$file])) {
return self::$formattedSourceCache[$file];
}
$buffer = file_get_contents($file);
$tokens = token_get_all($buffer, TOKEN_PARSE);
$result = [''];
$i = 0;
$stringFlag = false;
$fileEndsWithNewLine = str_ends_with($buffer, "\n");
unset($buffer);
foreach ($tokens as $j => $token) {
if (is_string($token)) {
if ($token === '"' && $tokens[$j - 1] !== '\\') {
$result[$i] .= sprintf(
'<span class="string">%s</span>',
htmlspecialchars($token, self::HTML_SPECIAL_CHARS_FLAGS),
);
$stringFlag = !$stringFlag;
} else {
$result[$i] .= sprintf(
'<span class="keyword">%s</span>',
htmlspecialchars($token, self::HTML_SPECIAL_CHARS_FLAGS),
);
}
continue;
}
[$token, $value] = $token;
$value = str_replace(
["\t", ' '],
[' ', ' '],
htmlspecialchars($value, self::HTML_SPECIAL_CHARS_FLAGS),
);
if ($value === "\n") {
$result[++$i] = '';
} else {
$lines = explode("\n", $value);
foreach ($lines as $jj => $line) {
$line = trim($line);
if ($line !== '') {
if ($stringFlag) {
$colour = 'string';
} else {
$colour = 'default';
if ($this->isInlineHtml($token)) {
$colour = 'html';
} elseif ($this->isComment($token)) {
$colour = 'comment';
} elseif ($this->isKeyword($token)) {
$colour = 'keyword';
}
}
$result[$i] .= sprintf(
'<span class="%s">%s</span>',
$colour,
$line,
);
}
if (isset($lines[$jj + 1])) {
$result[++$i] = '';
}
}
}
}
if ($fileEndsWithNewLine) {
unset($result[count($result) - 1]);
}
self::$formattedSourceCache[$file] = $result;
return $result;
}
|
@param non-empty-string $file
@return list<string>
|
loadFile
|
php
|
sebastianbergmann/php-code-coverage
|
src/Report/Html/Renderer/File.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Report/Html/Renderer/File.php
|
BSD-3-Clause
|
private function documentAsString(DOMDocument $document): string
{
$xmlErrorHandling = libxml_use_internal_errors(true);
$xml = $document->saveXML();
if ($xml === false) {
// @codeCoverageIgnoreStart
$message = 'Unable to generate the XML';
foreach (libxml_get_errors() as $error) {
$message .= PHP_EOL . $error->message;
}
throw new XmlException($message);
// @codeCoverageIgnoreEnd
}
libxml_clear_errors();
libxml_use_internal_errors($xmlErrorHandling);
return $xml;
}
|
@throws XmlException
@see https://bugs.php.net/bug.php?id=79191
|
documentAsString
|
php
|
sebastianbergmann/php-code-coverage
|
src/Report/Xml/Facade.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Report/Xml/Facade.php
|
BSD-3-Clause
|
public function warmCache(string $cacheDirectory, bool $useAnnotationsForIgnoringCode, bool $ignoreDeprecatedCode, Filter $filter): array
{
$analyser = new CachingSourceAnalyser(
$cacheDirectory,
new ParsingSourceAnalyser,
);
foreach ($filter->files() as $file) {
$analyser->analyse(
$file,
file_get_contents($file),
$useAnnotationsForIgnoringCode,
$ignoreDeprecatedCode,
);
}
return [
'cacheHits' => $analyser->cacheHits(),
'cacheMisses' => $analyser->cacheMisses(),
];
}
|
@return array{cacheHits: non-negative-int, cacheMisses: non-negative-int}
|
warmCache
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/CacheWarmer.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/CacheWarmer.php
|
BSD-3-Clause
|
public function __construct(array $interfaces, array $classes, array $traits, array $functions, LinesOfCode $linesOfCode, array $executableLines, array $ignoredLines)
{
$this->interfaces = $interfaces;
$this->classes = $classes;
$this->traits = $traits;
$this->functions = $functions;
$this->linesOfCode = $linesOfCode;
$this->executableLines = $executableLines;
$this->ignoredLines = $ignoredLines;
}
|
@param array<string, Interface_> $interfaces
@param array<string, Class_> $classes
@param array<string, Trait_> $traits
@param array<string, Function_> $functions
@param LinesType $executableLines
@param LinesType $ignoredLines
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/AnalysisResult.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/AnalysisResult.php
|
BSD-3-Clause
|
public function __construct(string $name, string $namespacedName, string $namespace, string $file, int $startLine, int $endLine, ?string $parentClass, array $interfaces, array $traits, array $methods)
{
$this->name = $name;
$this->namespacedName = $namespacedName;
$this->namespace = $namespace;
$this->file = $file;
$this->startLine = $startLine;
$this->endLine = $endLine;
$this->parentClass = $parentClass;
$this->interfaces = $interfaces;
$this->traits = $traits;
$this->methods = $methods;
}
|
@param non-empty-string $name
@param non-empty-string $namespacedName
@param non-empty-string $file
@param non-negative-int $startLine
@param non-negative-int $endLine
@param ?non-empty-string $parentClass
@param list<non-empty-string> $interfaces
@param list<non-empty-string> $traits
@param array<non-empty-string, Method> $methods
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/Class_.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/Class_.php
|
BSD-3-Clause
|
public function methods(): array
{
return $this->methods;
}
|
@return array<non-empty-string, Method>
|
methods
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/Class_.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/Class_.php
|
BSD-3-Clause
|
public function __construct(string $name, string $namespacedName, string $namespace, int $startLine, int $endLine, string $signature, int $cyclomaticComplexity)
{
$this->name = $name;
$this->namespacedName = $namespacedName;
$this->namespace = $namespace;
$this->startLine = $startLine;
$this->endLine = $endLine;
$this->signature = $signature;
$this->cyclomaticComplexity = $cyclomaticComplexity;
}
|
@param non-empty-string $name
@param non-empty-string $namespacedName
@param non-negative-int $startLine
@param non-negative-int $endLine
@param non-empty-string $signature
@param positive-int $cyclomaticComplexity
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/Function_.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/Function_.php
|
BSD-3-Clause
|
public function __construct(string $name, string $namespacedName, string $namespace, int $startLine, int $endLine, array $parentInterfaces)
{
$this->name = $name;
$this->namespacedName = $namespacedName;
$this->namespace = $namespace;
$this->startLine = $startLine;
$this->endLine = $endLine;
$this->parentInterfaces = $parentInterfaces;
}
|
@param non-empty-string $name
@param non-empty-string $namespacedName
@param non-negative-int $startLine
@param non-negative-int $endLine
@param list<non-empty-string> $parentInterfaces
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/Interface_.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/Interface_.php
|
BSD-3-Clause
|
public function __construct(int $linesOfCode, int $commentLinesOfCode, int $nonCommentLinesOfCode)
{
$this->linesOfCode = $linesOfCode;
$this->commentLinesOfCode = $commentLinesOfCode;
$this->nonCommentLinesOfCode = $nonCommentLinesOfCode;
}
|
@param non-negative-int $linesOfCode
@param non-negative-int $commentLinesOfCode
@param non-negative-int $nonCommentLinesOfCode
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/LinesOfCode.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/LinesOfCode.php
|
BSD-3-Clause
|
public function __construct(string $name, int $startLine, int $endLine, string $signature, Visibility $visibility, int $cyclomaticComplexity)
{
$this->name = $name;
$this->startLine = $startLine;
$this->endLine = $endLine;
$this->signature = $signature;
$this->visibility = $visibility;
$this->cyclomaticComplexity = $cyclomaticComplexity;
}
|
@param non-empty-string $name
@param non-negative-int $startLine
@param non-negative-int $endLine
@param non-empty-string $signature
@param positive-int $cyclomaticComplexity
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/Method.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/Method.php
|
BSD-3-Clause
|
public function __construct(string $name, string $namespacedName, string $namespace, string $file, int $startLine, int $endLine, array $traits, array $methods)
{
$this->name = $name;
$this->namespacedName = $namespacedName;
$this->namespace = $namespace;
$this->file = $file;
$this->startLine = $startLine;
$this->endLine = $endLine;
$this->traits = $traits;
$this->methods = $methods;
}
|
@param non-empty-string $name
@param non-empty-string $namespacedName
@param non-empty-string $file
@param non-negative-int $startLine
@param non-negative-int $endLine
@param list<non-empty-string> $traits
@param array<non-empty-string, Method> $methods
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/Trait_.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/Trait_.php
|
BSD-3-Clause
|
public function methods(): array
{
return $this->methods;
}
|
@return array<non-empty-string, Method>
|
methods
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Value/Trait_.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Value/Trait_.php
|
BSD-3-Clause
|
public function interfaces(): array
{
return $this->interfaces;
}
|
@return array<string, \SebastianBergmann\CodeCoverage\StaticAnalysis\Interface_>
|
interfaces
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
BSD-3-Clause
|
public function classes(): array
{
return $this->classes;
}
|
@return array<string, \SebastianBergmann\CodeCoverage\StaticAnalysis\Class_>
|
classes
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
BSD-3-Clause
|
public function traits(): array
{
return $this->traits;
}
|
@return array<string, \SebastianBergmann\CodeCoverage\StaticAnalysis\Trait_>
|
traits
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
BSD-3-Clause
|
public function functions(): array
{
return $this->functions;
}
|
@return array<string, \SebastianBergmann\CodeCoverage\StaticAnalysis\Function_>
|
functions
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
BSD-3-Clause
|
private function processMethods(array $nodes): array
{
$methods = [];
foreach ($nodes as $node) {
$methods[$node->name->toString()] = new Method(
$node->name->toString(),
$node->getStartLine(),
$node->getEndLine(),
$this->signature($node),
$this->visibility($node),
$this->cyclomaticComplexity($node),
);
}
return $methods;
}
|
@param list<ClassMethod> $nodes
@return array<non-empty-string, Method>
|
processMethods
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
BSD-3-Clause
|
private function postProcessClassOrTrait(Class_|Trait_ $node, array $traits): void
{
$name = $node->namespacedName->toString();
if ($node instanceof Class_) {
assert(isset($this->classes[$name]));
$this->classes[$name] = new \SebastianBergmann\CodeCoverage\StaticAnalysis\Class_(
$this->classes[$name]->name(),
$this->classes[$name]->namespacedName(),
$this->classes[$name]->namespace(),
$this->classes[$name]->file(),
$this->classes[$name]->startLine(),
$this->classes[$name]->endLine(),
$this->classes[$name]->parentClass(),
$this->classes[$name]->interfaces(),
$traits,
$this->classes[$name]->methods(),
);
return;
}
assert(isset($this->traits[$name]));
$this->traits[$name] = new \SebastianBergmann\CodeCoverage\StaticAnalysis\Trait_(
$this->traits[$name]->name(),
$this->traits[$name]->namespacedName(),
$this->traits[$name]->namespace(),
$this->traits[$name]->file(),
$this->traits[$name]->startLine(),
$this->traits[$name]->endLine(),
$traits,
$this->traits[$name]->methods(),
);
}
|
@param list<non-empty-string> $traits
|
postProcessClassOrTrait
|
php
|
sebastianbergmann/php-code-coverage
|
src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/StaticAnalysis/Visitor/CodeUnitFindingVisitor.php
|
BSD-3-Clause
|
private function processNamespace(array &$data, string $namespace, string $file, int $startLine, int $endLine): void
{
$parts = explode('\\', $namespace);
foreach (range(1, count($parts)) as $i) {
$this->process($data, implode('\\', array_slice($parts, 0, $i)), $file, $startLine, $endLine);
}
}
|
@param TargetMapPart $data
@param non-empty-string $namespace
@param non-empty-string $file
@param positive-int $startLine
@param positive-int $endLine
@param-out TargetMapPart $data
|
processNamespace
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/MapBuilder.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/MapBuilder.php
|
BSD-3-Clause
|
private function process(array &$data, string $unit, string $file, int $startLine, int $endLine): void
{
if (!isset($data[$unit])) {
$data[$unit] = [];
}
if (!isset($data[$unit][$file])) {
$data[$unit][$file] = [];
}
$data[$unit][$file] = array_merge(
$data[$unit][$file],
range($startLine, $endLine),
);
}
|
@param TargetMapPart $data
@param non-empty-string $unit
@param non-empty-string $file
@param positive-int $startLine
@param positive-int $endLine
@param-out TargetMapPart $data
|
process
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/MapBuilder.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/MapBuilder.php
|
BSD-3-Clause
|
private function parentClasses(array $classDetails, Class_ $class): array
{
if (!$class->hasParent()) {
return [];
}
if (!isset($classDetails[$class->parentClass()])) {
return [];
}
return array_merge(
[$classDetails[$class->parentClass()]],
$this->parentClasses($classDetails, $classDetails[$class->parentClass()]),
);
}
|
@param array<non-empty-string, Class_> $classDetails
@return array<Class_>
|
parentClasses
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/MapBuilder.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/MapBuilder.php
|
BSD-3-Clause
|
public function mapTargets(TargetCollection $targets): array
{
$result = [];
foreach ($targets as $target) {
foreach ($this->mapTarget($target) as $file => $lines) {
if (!isset($result[$file])) {
$result[$file] = $lines;
continue;
}
$result[$file] = array_unique(array_merge($result[$file], $lines));
}
}
return $result;
}
|
@return array<non-empty-string, list<positive-int>>
|
mapTargets
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/Mapper.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/Mapper.php
|
BSD-3-Clause
|
public function mapTarget(Target $target): array
{
if (isset($this->map[$target->key()][$target->target()])) {
return $this->map[$target->key()][$target->target()];
}
foreach (array_keys($this->map[$target->key()]) as $key) {
if (strcasecmp($key, $target->target()) === 0) {
return $this->map[$target->key()][$key];
}
}
throw new InvalidCodeCoverageTargetException($target);
}
|
@throws InvalidCodeCoverageTargetException
@return array<non-empty-string, list<positive-int>>
|
mapTarget
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/Mapper.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/Mapper.php
|
BSD-3-Clause
|
public function lookup(string $file, int $line): string
{
$key = $file . ':' . $line;
if (isset($this->map['reverseLookup'][$key])) {
return $this->map['reverseLookup'][$key];
}
return $key;
}
|
@param non-empty-string $file
@param positive-int $line
@return non-empty-string
|
lookup
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/Mapper.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/Mapper.php
|
BSD-3-Clause
|
protected function __construct(string $className, string $methodName)
{
$this->className = $className;
$this->methodName = $methodName;
}
|
@param class-string $className
@param non-empty-string $methodName
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/Method.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/Method.php
|
BSD-3-Clause
|
public static function forMethod(string $className, string $methodName): Method
{
return new Method($className, $methodName);
}
|
@param class-string $className
@param non-empty-string $methodName
|
forMethod
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/Target.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/Target.php
|
BSD-3-Clause
|
protected function __construct(string $message)
{
$this->message = $message;
}
|
@param non-empty-string $message
@noinspection PhpMissingParentConstructorInspection
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/ValidationFailure.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/ValidationFailure.php
|
BSD-3-Clause
|
public function isSuccess(): bool
{
return false;
}
|
@phpstan-assert-if-true ValidationSuccess $this
|
isSuccess
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/ValidationResult.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/ValidationResult.php
|
BSD-3-Clause
|
public function isFailure(): bool
{
return false;
}
|
@phpstan-assert-if-true ValidationFailure $this
|
isFailure
|
php
|
sebastianbergmann/php-code-coverage
|
src/Target/ValidationResult.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Target/ValidationResult.php
|
BSD-3-Clause
|
public function isKnown(): bool
{
return false;
}
|
@phpstan-assert-if-true Known $this
|
isKnown
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestSize/TestSize.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestSize/TestSize.php
|
BSD-3-Clause
|
public function isUnknown(): bool
{
return false;
}
|
@phpstan-assert-if-true Unknown $this
|
isUnknown
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestSize/TestSize.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestSize/TestSize.php
|
BSD-3-Clause
|
public function isSmall(): bool
{
return false;
}
|
@phpstan-assert-if-true Small $this
|
isSmall
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestSize/TestSize.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestSize/TestSize.php
|
BSD-3-Clause
|
public function isMedium(): bool
{
return false;
}
|
@phpstan-assert-if-true Medium $this
|
isMedium
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestSize/TestSize.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestSize/TestSize.php
|
BSD-3-Clause
|
public function isLarge(): bool
{
return false;
}
|
@phpstan-assert-if-true Large $this
|
isLarge
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestSize/TestSize.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestSize/TestSize.php
|
BSD-3-Clause
|
public function isKnown(): bool
{
return false;
}
|
@phpstan-assert-if-true Known $this
|
isKnown
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestStatus/TestStatus.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestStatus/TestStatus.php
|
BSD-3-Clause
|
public function isUnknown(): bool
{
return false;
}
|
@phpstan-assert-if-true Unknown $this
|
isUnknown
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestStatus/TestStatus.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestStatus/TestStatus.php
|
BSD-3-Clause
|
public function isSuccess(): bool
{
return false;
}
|
@phpstan-assert-if-true Success $this
|
isSuccess
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestStatus/TestStatus.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestStatus/TestStatus.php
|
BSD-3-Clause
|
public function isFailure(): bool
{
return false;
}
|
@phpstan-assert-if-true Failure $this
|
isFailure
|
php
|
sebastianbergmann/php-code-coverage
|
src/TestStatus/TestStatus.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/TestStatus/TestStatus.php
|
BSD-3-Clause
|
public function testLineDataFromStandardXDebugFormat(): void
{
$lineDataFromDriver = [
'/some/path/SomeClass.php' => [
8 => 1,
9 => -2,
13 => -1,
],
];
$dataObject = RawCodeCoverageData::fromXdebugWithoutPathCoverage($lineDataFromDriver);
$this->assertEquals($lineDataFromDriver, $dataObject->lineCoverage());
}
|
In the standard XDebug format, there is only line data. Therefore output should match input.
|
testLineDataFromStandardXDebugFormat
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Data/RawCodeCoverageDataTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Data/RawCodeCoverageDataTest.php
|
BSD-3-Clause
|
public function testLineDataFromPathCoverageXDebugFormat(): void
{
$rawDataFromDriver = [
'/some/path/SomeClass.php' => [
'lines' => [
8 => 1,
9 => -2,
13 => -1,
],
'functions' => [
],
],
'/some/path/justAScript.php' => [
'lines' => [
18 => 1,
19 => -2,
113 => -1,
],
'functions' => [
],
],
];
$lineData = [
'/some/path/SomeClass.php' => [
8 => 1,
9 => -2,
13 => -1,
],
'/some/path/justAScript.php' => [
18 => 1,
19 => -2,
113 => -1,
],
];
$dataObject = RawCodeCoverageData::fromXdebugWithPathCoverage($rawDataFromDriver);
$this->assertEquals($lineData, $dataObject->lineCoverage());
}
|
In the path-coverage XDebug format, the line data exists inside a "lines" array key.
|
testLineDataFromPathCoverageXDebugFormat
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Data/RawCodeCoverageDataTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Data/RawCodeCoverageDataTest.php
|
BSD-3-Clause
|
public function testTraitFunctionNamesDecodedPathCoverageXDebugFormat(): void
{
$rawDataFromDriver = [
'/some/path/FooTrait.php' => [
'lines' => [
11 => 1,
12 => -1,
15 => 1,
16 => -2,
18 => 1,
],
'functions' => [
'App\\FooTrait->returnsTrue{trait-method:/some/path/FooTrait.php:9-16}' => [
'branches' => [
0 => [
'op_start' => 0,
'op_end' => 5,
'line_start' => 11,
'line_end' => 11,
'hit' => 1,
'out' => [
0 => 6,
1 => 8,
],
'out_hit' => [
0 => 0,
1 => 1,
],
],
6 => [
'op_start' => 6,
'op_end' => 7,
'line_start' => 12,
'line_end' => 12,
'hit' => 0,
'out' => [
0 => 2147483645,
],
'out_hit' => [
0 => 0,
],
],
8 => [
'op_start' => 8,
'op_end' => 12,
'line_start' => 15,
'line_end' => 16,
'hit' => 1,
'out' => [
],
'out_hit' => [
],
],
],
'paths' => [
0 => [
'path' => [
0 => 0,
1 => 6,
],
'hit' => 0,
],
1 => [
'path' => [
0 => 0,
1 => 8,
],
'hit' => 1,
],
],
],
'{main}' => [
'branches' => [
0 => [
'op_start' => 0,
'op_end' => 2,
'line_start' => 3,
'line_end' => 18,
'hit' => 1,
'out' => [
0 => 2147483645,
],
'out_hit' => [
0 => 0,
],
],
],
'paths' => [
0 => [
'path' => [
0 => 0,
],
'hit' => 1,
],
],
],
],
],
];
$functionData = [
'/some/path/FooTrait.php' => [
'App\\FooTrait->returnsTrue' => [
'branches' => [
0 => [
'op_start' => 0,
'op_end' => 5,
'line_start' => 11,
'line_end' => 11,
'hit' => 1,
'out' => [
0 => 6,
1 => 8,
],
'out_hit' => [
0 => 0,
1 => 1,
],
],
6 => [
'op_start' => 6,
'op_end' => 7,
'line_start' => 12,
'line_end' => 12,
'hit' => 0,
'out' => [
0 => 2147483645,
],
'out_hit' => [
0 => 0,
],
],
8 => [
'op_start' => 8,
'op_end' => 12,
'line_start' => 15,
'line_end' => 16,
'hit' => 1,
'out' => [
],
'out_hit' => [
],
],
],
'paths' => [
0 => [
'path' => [
0 => 0,
1 => 6,
],
'hit' => 0,
],
1 => [
'path' => [
0 => 0,
1 => 8,
],
'hit' => 1,
],
],
],
'{main}' => [
'branches' => [
0 => [
'op_start' => 0,
'op_end' => 2,
'line_start' => 3,
'line_end' => 18,
'hit' => 1,
'out' => [
0 => 2147483645,
],
'out_hit' => [
0 => 0,
],
],
],
'paths' => [
0 => [
'path' => [
0 => 0,
],
'hit' => 1,
],
],
],
],
];
$dataObject = RawCodeCoverageData::fromXdebugWithPathCoverage($rawDataFromDriver);
$this->assertEquals($functionData, $dataObject->functionCoverage());
}
|
Xdebug annotates function names inside trait classes.
|
testTraitFunctionNamesDecodedPathCoverageXDebugFormat
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Data/RawCodeCoverageDataTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Data/RawCodeCoverageDataTest.php
|
BSD-3-Clause
|
private function assertAndValidate(string $expectationFile, string $cloverXml): void
{
$this->assertStringMatchesFormatFile($expectationFile, $cloverXml);
libxml_use_internal_errors(true);
$document = new DOMDocument;
$document->loadXML($cloverXml);
if (!$document->schemaValidate(__DIR__ . '/../../_files/Report/OpenClover/clover.xsd')) {
$buffer = 'Generated XML document does not validate against Clover schema:' . PHP_EOL . PHP_EOL;
foreach (libxml_get_errors() as $error) {
$buffer .= sprintf(
'- Line %d: %s' . PHP_EOL,
$error->line,
trim($error->message),
);
}
$buffer .= PHP_EOL;
}
libxml_clear_errors();
if (isset($buffer)) {
$this->fail($buffer);
}
}
|
@param non-empty-string $expectationFile
@param non-empty-string $cloverXml
|
assertAndValidate
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Report/OpenCloverTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Report/OpenCloverTest.php
|
BSD-3-Clause
|
private function class(?string $parentClass = null, array $interfaces = [], array $traits = [], array $methods = []): Class_
{
return new Class_(
'Example',
'example\Example',
'example',
'file.php',
1,
2,
$parentClass,
$interfaces,
$traits,
$methods,
);
}
|
@param list<non-empty-string> $interfaces
@param list<non-empty-string> $traits
@param array<non-empty-string, Method> $methods
|
class
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/StaticAnalysis/Value/ClassTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/StaticAnalysis/Value/ClassTest.php
|
BSD-3-Clause
|
private function interface(array $parentInterfaces = []): Interface_
{
return new Interface_(
'Example',
'example\Example',
'example',
1,
2,
$parentInterfaces,
);
}
|
@param list<non-empty-string> $parentInterfaces
|
interface
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/StaticAnalysis/Value/InterfaceTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/StaticAnalysis/Value/InterfaceTest.php
|
BSD-3-Clause
|
private function trait(array $traits = [], array $methods = []): Trait_
{
return new Trait_(
'Example',
'example\Example',
'example',
'file.php',
1,
2,
$traits,
$methods,
);
}
|
@param list<non-empty-string> $traits
@param array<non-empty-string, Method> $methods
|
trait
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/StaticAnalysis/Value/TraitTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/StaticAnalysis/Value/TraitTest.php
|
BSD-3-Clause
|
public static function provider(): array
{
$file = realpath(__DIR__ . '/../../_files/source_with_interfaces_classes_traits_functions.php');
$traitOne = realpath(__DIR__ . '/../../_files/Target/TraitOne.php');
$traitTwo = realpath(__DIR__ . '/../../_files/Target/TraitTwo.php');
$twoTraits = realpath(__DIR__ . '/../../_files/Target/two_traits.php');
$enum = realpath(__DIR__ . '/../../_files/Target/TargetEnumeration.php');
$grandParentClass = realpath(__DIR__ . '/../../_files/Target/GrandParentClass.php');
$parentClass = realpath(__DIR__ . '/../../_files/Target/ParentClass.php');
$childClass = realpath(__DIR__ . '/../../_files/Target/ChildClass.php');
return [
'generic' => [
[
'namespaces' => [
'SebastianBergmann' => [
$file => array_merge(
range(19, 24),
range(26, 31),
range(33, 52),
range(54, 56),
),
],
'SebastianBergmann\\CodeCoverage' => [
$file => array_merge(
range(19, 24),
range(26, 31),
range(33, 52),
range(54, 56),
),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis' => [
$file => array_merge(
range(19, 24),
range(26, 31),
range(33, 52),
range(54, 56),
),
],
],
'traits' => [
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\T' => [
$file => range(19, 24),
],
],
'classes' => [
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ParentClass' => [
$file => range(26, 31),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass' => [
$file => array_merge(
range(33, 52),
range(19, 24),
range(26, 31),
),
],
],
'classesThatExtendClass' => [
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ParentClass' => [
$file => range(33, 52),
],
],
'classesThatImplementInterface' => [
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\A' => [
$file => range(33, 52),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\B' => [
$file => range(33, 52),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\C' => [
$file => range(26, 31),
],
],
'methods' => [
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\T::four' => [
$file => range(21, 23),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ParentClass::five' => [
$file => range(28, 30),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass::six' => [
$file => range(37, 39),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass::one' => [
$file => range(41, 43),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass::two' => [
$file => range(45, 47),
],
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass::three' => [
$file => range(49, 51),
],
],
'functions' => [
'SebastianBergmann\\CodeCoverage\\StaticAnalysis\\f' => [
$file => range(54, 56),
],
],
'reverseLookup' => [
$file . ':21' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\T::four',
$file . ':22' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\T::four',
$file . ':23' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\T::four',
$file . ':28' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ParentClass::five',
$file . ':29' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ParentClass::five',
$file . ':30' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ParentClass::five',
$file . ':37' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::six',
$file . ':38' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::six',
$file . ':39' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::six',
$file . ':41' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::one',
$file . ':42' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::one',
$file . ':43' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::one',
$file . ':45' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::two',
$file . ':46' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::two',
$file . ':47' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::two',
$file . ':49' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::three',
$file . ':50' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::three',
$file . ':51' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\ChildClass::three',
$file . ':54' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\f',
$file . ':55' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\f',
$file . ':56' => 'SebastianBergmann\CodeCoverage\StaticAnalysis\f',
],
],
[$file],
],
'trait using trait declared in another file' => [
[
'namespaces' => [
'SebastianBergmann' => [
$traitOne => range(4, 9),
$traitTwo => range(4, 11),
],
'SebastianBergmann\\CodeCoverage' => [
$traitOne => range(4, 9),
$traitTwo => range(4, 11),
],
'SebastianBergmann\\CodeCoverage\\TestFixture' => [
$traitOne => range(4, 9),
$traitTwo => range(4, 11),
],
'SebastianBergmann\\CodeCoverage\\TestFixture\\Target' => [
$traitOne => range(4, 9),
$traitTwo => range(4, 11),
],
],
'traits' => [
TraitOne::class => [
$traitOne => range(4, 9),
],
TraitTwo::class => [
$traitTwo => range(4, 11),
$traitOne => range(4, 9),
],
],
'classes' => [
],
'classesThatExtendClass' => [
],
'classesThatImplementInterface' => [
],
'methods' => [
TraitOne::class . '::one' => [
$traitOne => range(6, 8),
],
TraitTwo::class . '::two' => [
$traitTwo => range(8, 10),
],
],
'functions' => [
],
'reverseLookup' => [
$traitOne . ':6' => TraitOne::class . '::one',
$traitOne . ':7' => TraitOne::class . '::one',
$traitOne . ':8' => TraitOne::class . '::one',
$traitTwo . ':8' => TraitTwo::class . '::two',
$traitTwo . ':9' => TraitTwo::class . '::two',
$traitTwo . ':10' => TraitTwo::class . '::two',
],
],
[
$traitOne,
$traitTwo,
],
],
'trait using trait declared in same file' => [
[
'namespaces' => [
'SebastianBergmann' => [
$twoTraits => array_merge(
range(4, 9),
range(11, 18),
),
],
'SebastianBergmann\\CodeCoverage' => [
$twoTraits => array_merge(
range(4, 9),
range(11, 18),
),
],
'SebastianBergmann\\CodeCoverage\\TestFixture' => [
$twoTraits => array_merge(
range(4, 9),
range(11, 18),
),
],
'SebastianBergmann\\CodeCoverage\\TestFixture\\Target' => [
$twoTraits => array_merge(
range(4, 9),
range(11, 18),
),
],
],
'traits' => [
T1::class => [
$twoTraits => range(4, 9),
],
T2::class => [
$twoTraits => array_merge(
range(11, 18),
range(4, 9),
),
],
],
'classes' => [
],
'classesThatExtendClass' => [
],
'classesThatImplementInterface' => [
],
'methods' => [
T1::class . '::one' => [
$twoTraits => range(6, 8),
],
T2::class . '::two' => [
$twoTraits => range(15, 17),
],
],
'functions' => [
],
'reverseLookup' => [
$twoTraits . ':6' => T1::class . '::one',
$twoTraits . ':7' => T1::class . '::one',
$twoTraits . ':8' => T1::class . '::one',
$twoTraits . ':15' => T2::class . '::two',
$twoTraits . ':16' => T2::class . '::two',
$twoTraits . ':17' => T2::class . '::two',
],
],
[
$twoTraits,
],
],
'enumeration' => [
[
'namespaces' => [
'SebastianBergmann' => [
$enum => range(4, 8),
],
'SebastianBergmann\\CodeCoverage' => [
$enum => range(4, 8),
],
'SebastianBergmann\\CodeCoverage\\TestFixture' => [
$enum => range(4, 8),
],
'SebastianBergmann\\CodeCoverage\\TestFixture\\Target' => [
$enum => range(4, 8),
],
],
'traits' => [
],
'classes' => [
TargetEnumeration::class => [
$enum => range(4, 8),
],
],
'classesThatExtendClass' => [
],
'classesThatImplementInterface' => [
],
'methods' => [
],
'functions' => [
],
'reverseLookup' => [
],
],
[
$enum,
],
],
'class with parent classes' => [
[
'namespaces' => [
'SebastianBergmann' => [
$grandParentClass => range(4, 9),
$parentClass => range(4, 9),
$childClass => range(4, 9),
],
'SebastianBergmann\CodeCoverage' => [
$grandParentClass => range(4, 9),
$parentClass => range(4, 9),
$childClass => range(4, 9),
],
'SebastianBergmann\CodeCoverage\TestFixture' => [
$grandParentClass => range(4, 9),
$parentClass => range(4, 9),
$childClass => range(4, 9),
],
'SebastianBergmann\CodeCoverage\TestFixture\Target' => [
$grandParentClass => range(4, 9),
$parentClass => range(4, 9),
$childClass => range(4, 9),
],
],
'traits' => [
],
'classes' => [
GrandParentClass::class => [
$grandParentClass => range(4, 9),
],
ParentClass::class => [
$parentClass => range(4, 9),
$grandParentClass => range(4, 9),
],
ChildClass::class => [
$childClass => range(4, 9),
$parentClass => range(4, 9),
$grandParentClass => range(4, 9),
],
],
'classesThatExtendClass' => [
GrandParentClass::class => [
$parentClass => range(4, 9),
$childClass => range(4, 9),
],
ParentClass::class => [
$childClass => range(4, 9),
],
],
'classesThatImplementInterface' => [
],
'methods' => [
GrandParentClass::class . '::one' => [
$grandParentClass => range(6, 8),
],
ParentClass::class . '::two' => [
$parentClass => range(6, 8),
],
ChildClass::class . '::three' => [
$childClass => range(6, 8),
],
],
'functions' => [
],
'reverseLookup' => [
$grandParentClass . ':6' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\GrandParentClass::one',
$grandParentClass . ':7' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\GrandParentClass::one',
$grandParentClass . ':8' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\GrandParentClass::one',
$parentClass . ':6' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\ParentClass::two',
$parentClass . ':7' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\ParentClass::two',
$parentClass . ':8' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\ParentClass::two',
$childClass . ':6' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\ChildClass::three',
$childClass . ':7' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\ChildClass::three',
$childClass . ':8' => 'SebastianBergmann\CodeCoverage\TestFixture\Target\ChildClass::three',
],
],
[
$grandParentClass,
$parentClass,
$childClass,
],
],
];
}
|
@return non-empty-array<non-empty-string, array{0: TargetMap, 1: non-empty-list<non-empty-string>}>
|
provider
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/MapBuilderTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/MapBuilderTest.php
|
BSD-3-Clause
|
private function map(array $files): array
{
$filter = new Filter;
$filter->includeFiles($files);
return (new MapBuilder)->build(
$filter,
new FileAnalyser(
new ParsingSourceAnalyser,
false,
false,
),
);
}
|
@param list<string> $files
@return TargetMap
|
map
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/MapBuilderTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/MapBuilderTest.php
|
BSD-3-Clause
|
public static function provider(): array
{
$file = realpath(__DIR__ . '/../../_files/source_with_interfaces_classes_traits_functions.php');
return [
'class' => [
[
$file => array_merge(
range(33, 52),
range(19, 24),
range(26, 31),
),
],
TargetCollection::fromArray(
[
Target::forClass('SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass'),
],
),
],
'class (which uses traits)' => [
[
realpath(__DIR__ . '/../../_files/Target/ClassUsingTraitUsingTrait.php') => range(4, 11),
realpath(__DIR__ . '/../../_files/Target/TraitTwo.php') => range(4, 11),
realpath(__DIR__ . '/../../_files/Target/TraitOne.php') => range(4, 9),
],
TargetCollection::fromArray(
[
Target::forClass('SebastianBergmann\\CodeCoverage\\TestFixture\\Target\\ClassUsingTraitUsingTrait'),
],
),
],
'classes that extend class (parent and child)' => [
[
$file => range(33, 52),
],
TargetCollection::fromArray(
[
Target::forClassesThatExtendClass('SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ParentClass'),
],
),
],
'classes that extend class (grand parent, parent, and child)' => [
[
realpath(__DIR__ . '/../../_files/Target/GrandParentClass.php') => range(4, 9),
realpath(__DIR__ . '/../../_files/Target/ParentClass.php') => range(4, 9),
realpath(__DIR__ . '/../../_files/Target/ChildClass.php') => range(4, 9),
],
TargetCollection::fromArray(
[
Target::forClass(GrandParentClass::class),
Target::forClassesThatExtendClass(GrandParentClass::class),
],
),
],
'classes that implement interface' => [
[
$file => range(26, 31),
],
TargetCollection::fromArray(
[
Target::forClassesThatImplementInterface('SebastianBergmann\\CodeCoverage\\StaticAnalysis\\C'),
],
),
],
'trait' => [
[
realpath(__DIR__ . '/../../_files/Target/TraitOne.php') => range(4, 9),
],
TargetCollection::fromArray(
[
Target::forTrait(TraitOne::class),
],
),
],
'function' => [
[
$file => range(54, 56),
],
TargetCollection::fromArray(
[
Target::forFunction('SebastianBergmann\\CodeCoverage\\StaticAnalysis\\f'),
],
),
],
'method of class' => [
[
$file => range(37, 39),
],
TargetCollection::fromArray(
[
Target::forMethod('SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass', 'six'),
],
),
],
'methods of class' => [
[
$file => array_merge(range(37, 39), range(41, 43)),
],
TargetCollection::fromArray(
[
Target::forMethod('SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass', 'six'),
Target::forMethod('SebastianBergmann\\CodeCoverage\\StaticAnalysis\\ChildClass', 'one'),
],
),
],
'method of trait' => [
[
$file => range(21, 23),
],
TargetCollection::fromArray(
[
Target::forMethod('SebastianBergmann\\CodeCoverage\\StaticAnalysis\\T', 'four'),
],
),
],
'namespace' => [
[
$file => array_merge(
range(19, 24),
range(26, 31),
range(33, 52),
range(54, 56),
),
],
TargetCollection::fromArray(
[
Target::forNamespace('SebastianBergmann\\CodeCoverage\\StaticAnalysis'),
],
),
],
'enumeration' => [
[
realpath(__DIR__ . '/../../_files/Target/TargetEnumeration.php') => range(4, 8),
],
TargetCollection::fromArray(
[
Target::forClass(TargetEnumeration::class),
],
),
],
];
}
|
@return non-empty-array<non-empty-string, array{0: array<non-empty-string, non-empty-list<positive-int>>, 1: TargetCollection}>
|
provider
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/MapperTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/MapperTest.php
|
BSD-3-Clause
|
public static function invalidProvider(): array
{
return [
'class' => [
'Class DoesNotExist is not a valid target for code coverage',
TargetCollection::fromArray(
[
/** @phpstan-ignore argument.type */
Target::forClass('DoesNotExist'),
],
),
],
'classes that extend class' => [
'Classes that extend class DoesNotExist is not a valid target for code coverage',
TargetCollection::fromArray(
[
/** @phpstan-ignore argument.type */
Target::forClassesThatExtendClass('DoesNotExist'),
],
),
],
'classes that implement interface' => [
'Classes that implement interface DoesNotExist is not a valid target for code coverage',
TargetCollection::fromArray(
[
/** @phpstan-ignore argument.type */
Target::forClassesThatImplementInterface('DoesNotExist'),
],
),
],
'function' => [
'Function does_not_exist is not a valid target for code coverage',
TargetCollection::fromArray(
[
Target::forFunction('does_not_exist'),
],
),
],
'method' => [
'Method DoesNotExist::doesNotExist is not a valid target for code coverage',
TargetCollection::fromArray(
[
/** @phpstan-ignore argument.type */
Target::forMethod('DoesNotExist', 'doesNotExist'),
],
),
],
'namespace' => [
'Namespace DoesNotExist is not a valid target for code coverage',
TargetCollection::fromArray(
[
Target::forNamespace('DoesNotExist'),
],
),
],
];
}
|
@return non-empty-array<non-empty-string, array{0: non-empty-string, 1: TargetCollection}>
|
invalidProvider
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/MapperTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/MapperTest.php
|
BSD-3-Clause
|
#[DataProvider('provider')]
#[TestDox('Maps TargetCollection with $_dataName to source locations')]
public function testMapsTargetValueObjectsToSourceLocations(array $expected, TargetCollection $targets): void
{
$this->assertSame(
$expected,
$this->mapper(array_keys($expected))->mapTargets($targets),
);
}
|
@param array<non-empty-string, non-empty-list<positive-int>> $expected
|
testMapsTargetValueObjectsToSourceLocations
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/MapperTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/MapperTest.php
|
BSD-3-Clause
|
private function mapper(array $files): Mapper
{
return new Mapper($this->map($files));
}
|
@param list<non-empty-string> $files
|
mapper
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/MapperTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/MapperTest.php
|
BSD-3-Clause
|
private function map(array $files): array
{
$filter = new Filter;
$filter->includeFiles($files);
return (new MapBuilder)->build(
$filter,
new FileAnalyser(
new ParsingSourceAnalyser,
false,
false,
),
);
}
|
@param list<non-empty-string> $files
@return TargetMap
|
map
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/MapperTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/MapperTest.php
|
BSD-3-Clause
|
private function mapper(array $files): Mapper
{
return new Mapper($this->map($files));
}
|
@param list<non-empty-string> $files
|
mapper
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/TargetCollectionValidatorTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/TargetCollectionValidatorTest.php
|
BSD-3-Clause
|
private function map(array $files): array
{
$filter = new Filter;
$filter->includeFiles($files);
return (new MapBuilder)->build(
$filter,
new FileAnalyser(
new ParsingSourceAnalyser,
false,
false,
),
);
}
|
@param list<non-empty-string> $files
@return TargetMap
|
map
|
php
|
sebastianbergmann/php-code-coverage
|
tests/tests/Target/TargetCollectionValidatorTest.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tests/tests/Target/TargetCollectionValidatorTest.php
|
BSD-3-Clause
|
public function getClassMap()
{
return $this->classMap;
}
|
@return array<string, string> Array of classname => path
|
getClassMap
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
|
@param array<string, string> $classMap Class to filename map
@return void
|
addClassMap
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function add($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
$paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
$paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
$paths
);
}
}
|
Registers a set of PSR-0 directories for a given prefix, either
appending or prepending to the ones previously set for this prefix.
@param string $prefix The prefix
@param list<string>|string $paths The PSR-0 root directories
@param bool $prepend Whether to prepend the directories
@return void
|
add
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function addPsr4($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
$paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
$paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
$paths
);
}
}
|
Registers a set of PSR-4 directories for a given namespace, either
appending or prepending to the ones previously set for this namespace.
@param string $prefix The prefix/namespace, with trailing '\\'
@param list<string>|string $paths The PSR-4 base directories
@param bool $prepend Whether to prepend the directories
@throws \InvalidArgumentException
@return void
|
addPsr4
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
|
Registers a set of PSR-0 directories for a given prefix,
replacing any others previously set for this prefix.
@param string $prefix The prefix
@param list<string>|string $paths The PSR-0 base directories
@return void
|
set
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
|
Registers a set of PSR-4 directories for a given namespace,
replacing any others previously set for this namespace.
@param string $prefix The prefix/namespace, with trailing '\\'
@param list<string>|string $paths The PSR-4 base directories
@throws \InvalidArgumentException
@return void
|
setPsr4
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
|
Turns on searching the include path for class files.
@param bool $useIncludePath
@return void
|
setUseIncludePath
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function getUseIncludePath()
{
return $this->useIncludePath;
}
|
Can be used to check if the autoloader uses the include path to check
for classes.
@return bool
|
getUseIncludePath
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
|
Turns off searching the prefix and fallback directories for classes
that have not been registered with the class map.
@param bool $classMapAuthoritative
@return void
|
setClassMapAuthoritative
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
|
Should class lookup fail if not found in the current class map?
@return bool
|
isClassMapAuthoritative
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
|
APCu prefix to use to cache found/not-found classes, if the extension is enabled.
@param string|null $apcuPrefix
@return void
|
setApcuPrefix
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
|
The APCu prefix in use, or null if APCu caching is not enabled.
@return string|null
|
getApcuPrefix
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
|
Registers this instance as an autoloader.
@param bool $prepend Whether to prepend the autoloader or not
@return void
|
register
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
|
Unregisters this instance as an autoloader.
@return void
|
unregister
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
$includeFile = self::$includeFile;
$includeFile($file);
return true;
}
return null;
}
|
Loads the given class or interface.
@param string $class The name of the class
@return true|null True if loaded, null otherwise
|
loadClass
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
|
Finds the path to the file where the class is defined.
@param string $class The name of the class
@return string|false The path if found, false otherwise
|
findFile
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
|
Returns the currently registered loaders keyed by their corresponding vendor directories.
@return array<string, self>
|
getRegisteredLoaders
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
|
@param string $class
@param string $ext
@return string|false
|
findFileWithExtension
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/ClassLoader.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/ClassLoader.php
|
BSD-3-Clause
|
public static function getInstalledPackages()
{
$packages = array();
foreach (self::getInstalled() as $installed) {
$packages[] = array_keys($installed['versions']);
}
if (1 === \count($packages)) {
return $packages[0];
}
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
}
|
Returns a list of all package names which are present, either by being installed, replaced or provided
@return string[]
@psalm-return list<string>
|
getInstalledPackages
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getInstalledPackagesByType($type)
{
$packagesByType = array();
foreach (self::getInstalled() as $installed) {
foreach ($installed['versions'] as $name => $package) {
if (isset($package['type']) && $package['type'] === $type) {
$packagesByType[] = $name;
}
}
}
return $packagesByType;
}
|
Returns a list of all package names with a specific type e.g. 'library'
@param string $type
@return string[]
@psalm-return list<string>
|
getInstalledPackagesByType
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function isInstalled($packageName, $includeDevRequirements = true)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
}
}
return false;
}
|
Checks whether the given package is installed
This also returns true if the package name is provided or replaced by another package
@param string $packageName
@param bool $includeDevRequirements
@return bool
|
isInstalled
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function satisfies(VersionParser $parser, $packageName, $constraint)
{
$constraint = $parser->parseConstraints((string) $constraint);
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
return $provided->matches($constraint);
}
|
Checks whether the given package satisfies a version constraint
e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
@param VersionParser $parser Install composer/semver to have access to this class and functionality
@param string $packageName
@param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
@return bool
|
satisfies
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getVersionRanges($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
$ranges = array();
if (isset($installed['versions'][$packageName]['pretty_version'])) {
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
}
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
}
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
}
if (array_key_exists('provided', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
}
return implode(' || ', $ranges);
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
Returns a version constraint representing all the range(s) which are installed for a given package
It is easier to use this via isInstalled() with the $constraint argument if you need to check
whether a given version of a package is installed, and not just whether it exists
@param string $packageName
@return string Version constraint usable with composer/semver
|
getVersionRanges
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['version'])) {
return null;
}
return $installed['versions'][$packageName]['version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
@param string $packageName
@return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
getVersion
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getPrettyVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
return null;
}
return $installed['versions'][$packageName]['pretty_version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
@param string $packageName
@return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
getPrettyVersion
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getReference($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['reference'])) {
return null;
}
return $installed['versions'][$packageName]['reference'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
@param string $packageName
@return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
|
getReference
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getInstallPath($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
|
@param string $packageName
@return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
|
getInstallPath
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getRootPackage()
{
$installed = self::getInstalled();
return $installed[0]['root'];
}
|
@return array
@psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
|
getRootPackage
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getRawData()
{
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
return self::$installed;
}
|
Returns the raw installed.php data for custom implementations
@deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
@return array[]
@psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
|
getRawData
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function getAllRawData()
{
return self::getInstalled();
}
|
Returns the raw data of all installed.php which are currently loaded for custom implementations
@return array[]
@psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
getAllRawData
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public static function reload($data)
{
self::$installed = $data;
self::$installedByVendor = array();
// when using reload, we disable the duplicate protection to ensure that self::$installed data is
// always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
// so we have to assume it does not, and that may result in duplicate data being returned when listing
// all installed packages for example
self::$installedIsLocalDir = false;
}
|
Lets you reload the static array from another file
This is only useful for complex integrations in which a project needs to use
this class but then also needs to execute another project's autoloader in process,
and wants to ensure both projects have access to their version of installed.php.
A typical case would be PHPUnit, where it would need to make sure it reads all
the data it needs from this class, then call reload() with
`require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
the project in which it runs can then also use this class safely, without
interference between PHPUnit's dependencies and the project's dependencies.
@param array[] $data A vendor/composer/installed.php data set
@return void
@psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
|
reload
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
private static function getInstalled()
{
if (null === self::$canGetVendors) {
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
}
$installed = array();
$copiedLocalDir = false;
if (self::$canGetVendors) {
$selfDir = self::getSelfDir();
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
$vendorDir = strtr($vendorDir, '\\', '/');
if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
self::$installedByVendor[$vendorDir] = $required;
$installed[] = $required;
if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
self::$installed = $required;
self::$installedIsLocalDir = true;
}
}
if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
$copiedLocalDir = true;
}
}
}
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
} else {
self::$installed = array();
}
}
if (self::$installed !== array() && !$copiedLocalDir) {
$installed[] = self::$installed;
}
return $installed;
}
|
@return array[]
@psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
getInstalled
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/composer/InstalledVersions.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/composer/InstalledVersions.php
|
BSD-3-Clause
|
public function isNullableTypeDeclaration($typeDeclaration): bool
{
if ($typeDeclaration instanceof Node\NullableType) {
return true;
}
if ($typeDeclaration instanceof Node\UnionType) {
foreach ($typeDeclaration->types as $type) {
if (
$type instanceof Node\Identifier
&& 'null' === $type->toLowerString()
) {
return true;
}
if (
$type instanceof Node\Name\FullyQualified
&& $type->hasAttribute('originalName')
) {
$originalName = $type->getAttribute('originalName');
if (
$originalName instanceof Node\Name
&& 'null' === $originalName->toLowerString()
) {
return true;
}
}
}
}
return false;
}
|
@param null|Node\ComplexType|Node\Identifier|Node\Name $typeDeclaration
|
isNullableTypeDeclaration
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/ergebnis/phpstan-rules/src/Analyzer.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/ergebnis/phpstan-rules/src/Analyzer.php
|
BSD-3-Clause
|
public function __construct(
Reflection\ReflectionProvider $reflectionProvider,
array $interfacesImplementedByContainers,
array $methodsAllowedToUseContainerTypeDeclarations
) {
$this->reflectionProvider = $reflectionProvider;
$this->interfacesImplementedByContainers = \array_values(\array_filter(
\array_map(static function (string $interfaceImplementedByContainers): string {
return $interfaceImplementedByContainers;
}, $interfacesImplementedByContainers),
static function (string $interfaceImplementedByContainer): bool {
return \interface_exists($interfaceImplementedByContainer);
},
));
$this->methodsAllowedToUseContainerTypeDeclarations = $methodsAllowedToUseContainerTypeDeclarations;
}
|
@param list<string> $interfacesImplementedByContainers
@param list<string> $methodsAllowedToUseContainerTypeDeclarations
|
__construct
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/ergebnis/phpstan-rules/src/Methods/NoParameterWithContainerTypeDeclarationRule.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/ergebnis/phpstan-rules/src/Methods/NoParameterWithContainerTypeDeclarationRule.php
|
BSD-3-Clause
|
public function &__get(string $name)
{
$class = static::class;
if ($prop = ObjectHelpers::getMagicProperties($class)[$name] ?? null) { // property getter
if (!($prop & 0b0001)) {
throw new MemberAccessException("Cannot read a write-only property $class::\$$name.");
}
$m = ($prop & 0b0010 ? 'get' : 'is') . ucfirst($name);
if ($prop & 0b10000) {
$trace = debug_backtrace(0, 1)[0]; // suppose this method is called from __call()
$loc = isset($trace['file'], $trace['line'])
? " in $trace[file] on line $trace[line]"
: '';
trigger_error("Property $class::\$$name is deprecated, use $class::$m() method$loc.", E_USER_DEPRECATED);
}
if ($prop & 0b0100) { // return by reference
return $this->$m();
} else {
$val = $this->$m();
return $val;
}
} else {
ObjectHelpers::strictGet($class, $name);
}
}
|
@return mixed
@throws MemberAccessException if the property is not defined.
|
__get
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/SmartObject.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/SmartObject.php
|
BSD-3-Clause
|
public function __set(string $name, mixed $value): void
{
$class = static::class;
if (ObjectHelpers::hasProperty($class, $name)) { // unsetted property
$this->$name = $value;
} elseif ($prop = ObjectHelpers::getMagicProperties($class)[$name] ?? null) { // property setter
if (!($prop & 0b1000)) {
throw new MemberAccessException("Cannot write to a read-only property $class::\$$name.");
}
$m = 'set' . ucfirst($name);
if ($prop & 0b10000) {
$trace = debug_backtrace(0, 1)[0]; // suppose this method is called from __call()
$loc = isset($trace['file'], $trace['line'])
? " in $trace[file] on line $trace[line]"
: '';
trigger_error("Property $class::\$$name is deprecated, use $class::$m() method$loc.", E_USER_DEPRECATED);
}
$this->$m($value);
} else {
ObjectHelpers::strictSet($class, $name);
}
}
|
@throws MemberAccessException if the property is not defined or is read-only
|
__set
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/SmartObject.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/SmartObject.php
|
BSD-3-Clause
|
public static function __callStatic(string $name, array $args): mixed
{
Utils\ObjectHelpers::strictStaticCall(static::class, $name);
}
|
Call to undefined static method.
@throws MemberAccessException
|
__callStatic
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/StaticClass.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/StaticClass.php
|
BSD-3-Clause
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.