-
-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error identifiers extractor - work in progress
- Loading branch information
1 parent
efdf202
commit 11690f6
Showing
12 changed files
with
410 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions | ||
|
||
name: "Build Identifier Extractor" | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'identifier-extractor/**' | ||
- '.github/workflows/build-identifier-extractor.yml' | ||
push: | ||
branches: | ||
- "1.11.x" | ||
paths: | ||
- 'identifier-extractor/**' | ||
- '.github/workflows/build-identifier-extractor.yml' | ||
|
||
jobs: | ||
build-identifier-extractor: | ||
name: "Build Identifier Extractor" | ||
|
||
runs-on: "ubuntu-latest" | ||
timeout-minutes: 60 | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v3 | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "none" | ||
php-version: "8.1" | ||
|
||
- name: "Install Identifier Extractor dependencies" | ||
working-directory: "identifier-extractor" | ||
run: "composer install --no-interaction --no-progress" | ||
|
||
- name: "PHPStan" | ||
working-directory: "identifier-extractor" | ||
run: ../phpstan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions | ||
|
||
name: "Extract identifiers" | ||
|
||
on: | ||
push: | ||
branches: | ||
- "1.11.x" | ||
paths: | ||
- '.github/workflows/extract-identifiers.yml' | ||
- 'identifier-extractor/**' | ||
- '.phar-checksum' | ||
|
||
jobs: | ||
extract: | ||
name: "Extract identifiers" | ||
runs-on: "ubuntu-latest" | ||
|
||
strategy: | ||
matrix: | ||
repository: | ||
- "https://github.com/phpstan/phpstan-src.git" | ||
- "https://github.com/phpstan/phpstan-strict-rules.git" | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v3 | ||
|
||
- name: "Checkout" | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: ${{ matrix.repository }} | ||
path: "identifier-extractor/repo" | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "none" | ||
php-version: "8.1" | ||
|
||
- name: "Install extractor dependencies" | ||
working-directory: "identifier-extractor" | ||
run: "composer install --no-interaction --no-progress" | ||
|
||
- name: "Repository name" | ||
id: repo-name | ||
run: echo "name=$(basename -s .git "${{ matrix.repository }}")" >> $GITHUB_OUTPUT | ||
|
||
- name: "Branch name" | ||
id: branch-name | ||
working-directory: "identifier-extractor/repo" | ||
run: echo "name=$(git branch --show)" >> $GITHUB_OUTPUT | ||
|
||
- name: "Extract" | ||
working-directory: "identifier-extractor/repo" | ||
run: ../../phpstan analyse -c ../extractor.neon -a ../vendor/autoload.php > ${{ steps.repo-name.outputs.name }}.json | ||
env: | ||
REPO: ${{ matrix.repository }} | ||
BRANCH: ${{ steps.branch-name.outputs.name }} | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: identifiers | ||
path: identifier-extractor/${{ steps.repo-name.outputs.name }}.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor | ||
/repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"require": { | ||
"php": "^8.1", | ||
"nette/utils": "^4.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"IdentifierExtractor\\": "src/" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
includes: | ||
- phar://phpstan.phar/conf/bleedingEdge.neon | ||
|
||
parameters: | ||
customRulesetUsed: true | ||
errorFormat: extractor | ||
paths: | ||
- repo/src | ||
|
||
rules: | ||
- IdentifierExtractor\Rule | ||
|
||
services: | ||
errorFormatter.extractor: | ||
class: IdentifierExtractor\ErrorFormatter | ||
arguments: | ||
relativePathHelper: @simpleRelativePathHelper | ||
|
||
- | ||
class: IdentifierExtractor\RuleErrorBuilderCollector | ||
tags: | ||
- phpstan.collector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
includes: | ||
- phar://phpstan.phar/conf/bleedingEdge.neon | ||
|
||
parameters: | ||
level: 8 | ||
paths: | ||
- src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace IdentifierExtractor; | ||
|
||
use Nette\Utils\Json; | ||
use PHPStan\Command\AnalysisResult; | ||
use PHPStan\Command\ErrorFormatter\TableErrorFormatter; | ||
use PHPStan\Command\Output; | ||
use PHPStan\File\RelativePathHelper; | ||
|
||
class ErrorFormatter implements \PHPStan\Command\ErrorFormatter\ErrorFormatter | ||
{ | ||
|
||
public function __construct(private RelativePathHelper $relativePathHelper, private TableErrorFormatter $tableErrorFormatter) | ||
{ | ||
} | ||
|
||
public function formatErrors(AnalysisResult $analysisResult, Output $output): int | ||
{ | ||
if ($analysisResult->hasInternalErrors()) { | ||
return $this->tableErrorFormatter->formatErrors($analysisResult, $output); | ||
} | ||
|
||
$json = []; | ||
foreach ($analysisResult->getFileSpecificErrors() as $error) { | ||
if ($error->getIdentifier() === 'ignore.unmatchedLine') { | ||
continue; | ||
} | ||
if ($error->getIdentifier() !== 'phpstanIdentifierExtractor.data') { | ||
return $this->tableErrorFormatter->formatErrors($analysisResult, $output); | ||
} | ||
|
||
$metadata = $error->getMetadata(); | ||
var_dump($metadata); | ||
$json[] = [ | ||
'identifiers' => $metadata['identifiers'], | ||
'class' => $metadata['class'], | ||
'file' => $this->relativePathHelper->getRelativePath($metadata['file'] ?? ''), | ||
'line' => $metadata['line'], | ||
]; | ||
} | ||
|
||
$output->writeRaw(Json::encode([ | ||
'repo' => $_SERVER['REPO'], | ||
'branch' => $_SERVER['BRANCH'], | ||
'data' => $json, | ||
])); | ||
|
||
return 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace IdentifierExtractor; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Node\CollectedDataNode; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
|
||
/** | ||
* @implements \PHPStan\Rules\Rule<CollectedDataNode> | ||
*/ | ||
class Rule implements \PHPStan\Rules\Rule | ||
{ | ||
|
||
public function getNodeType(): string | ||
{ | ||
return CollectedDataNode::class; | ||
} | ||
|
||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
$errors = []; | ||
|
||
foreach ($node->get(RuleErrorBuilderCollector::class) as $rows) { | ||
foreach ($rows as $row) { | ||
$errors[] = RuleErrorBuilder::message('Metadata') | ||
->identifier('phpstanIdentifierExtractor.data') | ||
->metadata($row) | ||
->build(); | ||
} | ||
} | ||
|
||
return $errors; | ||
} | ||
|
||
} |
Oops, something went wrong.