Skip to content

Commit

Permalink
deploy: 2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nemorize committed Feb 13, 2025
1 parent 5ac7a75 commit 8b7e0d2
Show file tree
Hide file tree
Showing 1,337 changed files with 162,689 additions and 4 deletions.
18 changes: 14 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"name": "headercat/phpstan-extension-ide-helper",
"description": "PHPStan extension IDE helper, provides dummy PHPStan namespace classes and functions.",
"license": "MIT"
}
"name": "headercat/phpstan-extension-ide-helper",
"description": "PHPStan extension IDE helper, provides dummy PHPStan namespace classes and functions.",
"license": "MIT",
"autoload-dev": {
"psr-4": {
"PHPStan\\": "src/"
}
},
"require": {
"phpstan/phpstan": "^2.1.2",
"phpstan/php-8-stubs": "0.4.11",
"phpstan/phpdoc-parser": "2.0.1"
}
}
13 changes: 13 additions & 0 deletions src/AnalysedCodeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace PHPStan;
return;

use Exception;

abstract class AnalysedCodeException extends Exception
{

abstract public function getTip(): ?string;

}
137 changes: 137 additions & 0 deletions src/Analyser/Analyser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

namespace PHPStan\Analyser;
return;

use Closure;
use PHPStan\Collectors\CollectedData;
use PHPStan\Collectors\Registry as CollectorRegistry;
use PHPStan\Rules\Registry as RuleRegistry;
use Throwable;
use function array_fill_keys;
use function array_merge;
use function count;
use function memory_get_peak_usage;

final class Analyser
{

public function __construct(
private FileAnalyser $fileAnalyser,
private RuleRegistry $ruleRegistry,
private CollectorRegistry $collectorRegistry,
private NodeScopeResolver $nodeScopeResolver,
private int $internalErrorsCountLimit,
)
{
}

/**
* @param string[] $files
* @param Closure(string $file): void|null $preFileCallback
* @param Closure(int ): void|null $postFileCallback
* @param string[]|null $allAnalysedFiles
*/
public function analyse(
array $files,
?Closure $preFileCallback = null,
?Closure $postFileCallback = null,
bool $debug = false,
?array $allAnalysedFiles = null,
): AnalyserResult
{
if ($allAnalysedFiles === null) {
$allAnalysedFiles = $files;
}

$this->nodeScopeResolver->setAnalysedFiles($allAnalysedFiles);
$allAnalysedFiles = array_fill_keys($allAnalysedFiles, true);

/** @var list<Error> $errors */
$errors = [];
/** @var list<Error> $filteredPhpErrors */
$filteredPhpErrors = [];
/** @var list<Error> $allPhpErrors */
$allPhpErrors = [];

/** @var list<Error> $locallyIgnoredErrors */
$locallyIgnoredErrors = [];

$linesToIgnore = [];
$unmatchedLineIgnores = [];

/** @var list<CollectedData> $collectedData */
$collectedData = [];

$internalErrorsCount = 0;
$reachedInternalErrorsCountLimit = false;
$dependencies = [];
$exportedNodes = [];
foreach ($files as $file) {
if ($preFileCallback !== null) {
$preFileCallback($file);
}

try {
$fileAnalyserResult = $this->fileAnalyser->analyseFile(
$file,
$allAnalysedFiles,
$this->ruleRegistry,
$this->collectorRegistry,
null,
);
$errors = array_merge($errors, $fileAnalyserResult->getErrors());
$filteredPhpErrors = array_merge($filteredPhpErrors, $fileAnalyserResult->getFilteredPhpErrors());
$allPhpErrors = array_merge($allPhpErrors, $fileAnalyserResult->getAllPhpErrors());

$locallyIgnoredErrors = array_merge($locallyIgnoredErrors, $fileAnalyserResult->getLocallyIgnoredErrors());
$linesToIgnore[$file] = $fileAnalyserResult->getLinesToIgnore();
$unmatchedLineIgnores[$file] = $fileAnalyserResult->getUnmatchedLineIgnores();
$collectedData = array_merge($collectedData, $fileAnalyserResult->getCollectedData());
$dependencies[$file] = $fileAnalyserResult->getDependencies();

$fileExportedNodes = $fileAnalyserResult->getExportedNodes();
if (count($fileExportedNodes) > 0) {
$exportedNodes[$file] = $fileExportedNodes;
}
} catch (Throwable $t) {
if ($debug) {
throw $t;
}
$internalErrorsCount++;
$errors[] = (new Error($t->getMessage(), $file, null, $t))
->withIdentifier('phpstan.internal')
->withMetadata([
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($t),
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $t->getTraceAsString(),
]);
if ($internalErrorsCount >= $this->internalErrorsCountLimit) {
$reachedInternalErrorsCountLimit = true;
break;
}
}

if ($postFileCallback === null) {
continue;
}

$postFileCallback(1);
}

return new AnalyserResult(
$errors,
$filteredPhpErrors,
$allPhpErrors,
$locallyIgnoredErrors,
$linesToIgnore,
$unmatchedLineIgnores,
[],
$collectedData,
$internalErrorsCount === 0 ? $dependencies : null,
$exportedNodes,
$reachedInternalErrorsCountLimit,
memory_get_peak_usage(true),
);
}

}
162 changes: 162 additions & 0 deletions src/Analyser/AnalyserResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php

namespace PHPStan\Analyser;
return;

use PHPStan\Collectors\CollectedData;
use PHPStan\Dependency\RootExportedNode;
use function usort;

/**
* @phpstan-import-type LinesToIgnore from FileAnalyserResult
*/
final class AnalyserResult
{

/** @var list<Error>|null */
private ?array $errors = null;

/**
* @param list<Error> $unorderedErrors
* @param list<Error> $filteredPhpErrors
* @param list<Error> $allPhpErrors
* @param list<Error> $locallyIgnoredErrors
* @param array<string, LinesToIgnore> $linesToIgnore
* @param array<string, LinesToIgnore> $unmatchedLineIgnores
* @param list<CollectedData> $collectedData
* @param list<InternalError> $internalErrors
* @param array<string, array<string>>|null $dependencies
* @param array<string, array<RootExportedNode>> $exportedNodes
*/
public function __construct(
private array $unorderedErrors,
private array $filteredPhpErrors,
private array $allPhpErrors,
private array $locallyIgnoredErrors,
private array $linesToIgnore,
private array $unmatchedLineIgnores,
private array $internalErrors,
private array $collectedData,
private ?array $dependencies,
private array $exportedNodes,
private bool $reachedInternalErrorsCountLimit,
private int $peakMemoryUsageBytes,
)
{
}

/**
* @return list<Error>
*/
public function getUnorderedErrors(): array
{
return $this->unorderedErrors;
}

/**
* @return list<Error>
*/
public function getErrors(): array
{
if (!isset($this->errors)) {
$this->errors = $this->unorderedErrors;
usort(
$this->errors,
static fn (Error $a, Error $b): int => [
$a->getFile(),
$a->getLine(),
$a->getMessage(),
] <=> [
$b->getFile(),
$b->getLine(),
$b->getMessage(),
],
);
}

return $this->errors;
}

/**
* @return list<Error>
*/
public function getFilteredPhpErrors(): array
{
return $this->filteredPhpErrors;
}

/**
* @return list<Error>
*/
public function getAllPhpErrors(): array
{
return $this->allPhpErrors;
}

/**
* @return list<Error>
*/
public function getLocallyIgnoredErrors(): array
{
return $this->locallyIgnoredErrors;
}

/**
* @return array<string, LinesToIgnore>
*/
public function getLinesToIgnore(): array
{
return $this->linesToIgnore;
}

/**
* @return array<string, LinesToIgnore>
*/
public function getUnmatchedLineIgnores(): array
{
return $this->unmatchedLineIgnores;
}

/**
* @return list<InternalError>
*/
public function getInternalErrors(): array
{
return $this->internalErrors;
}

/**
* @return list<CollectedData>
*/
public function getCollectedData(): array
{
return $this->collectedData;
}

/**
* @return array<string, array<string>>|null
*/
public function getDependencies(): ?array
{
return $this->dependencies;
}

/**
* @return array<string, array<RootExportedNode>>
*/
public function getExportedNodes(): array
{
return $this->exportedNodes;
}

public function hasReachedInternalErrorsCountLimit(): bool
{
return $this->reachedInternalErrorsCountLimit;
}

public function getPeakMemoryUsageBytes(): int
{
return $this->peakMemoryUsageBytes;
}

}
Loading

0 comments on commit 8b7e0d2

Please sign in to comment.