Skip to content

Commit

Permalink
fixed compatibility with PHPStan (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil42Russia authored Sep 27, 2023
1 parent 4d50e14 commit 7d24078
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
name: "Tests"
name: Tests

on:
pull_request:

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
name: Tests (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 60

strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
operating-system: [ ubuntu-latest, macos-latest ]
php-versions: [ 7.4, 8.0, 8.1, 8.2 ]

steps:
- name: Fetch Sources
Expand All @@ -26,7 +22,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "${{ matrix.php-version }}"
php-version: ${{ matrix.php-versions }}
tools: composer:v2

- name: Install dependencies
Expand Down
8 changes: 7 additions & 1 deletion src/ModulitePHPStanError.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ class ModulitePHPStanError implements IdentifierRuleError, LineRuleError, FileRu

private string $message;
private string $file;
private string $fileDescription;
private int $line;

public function __construct(string $message, string $file, int $line) {
public function __construct(string $message, string $file, string $fileDescription, int $line) {
$this->message = $message;
$this->file = $file;
$this->fileDescription = $fileDescription;
$this->line = $line;
}

Expand All @@ -34,4 +36,8 @@ public function getLine(): int {
public function getMessage(): string {
return $this->message;
}

public function getFileDescription(): string {
return $this->fileDescription;
}
}
9 changes: 7 additions & 2 deletions src/ModuliteRules/ModuliteRuleBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public function processNode(Node $node, Scope $scope): array {
return [];
}

return array_map(fn($msg) => new ModulitePHPStanError($msg, $scope->getFile(), $node->getLine()), $errors);
return array_map(fn($msg) => new ModulitePHPStanError(
$msg,
$scope->getFile(),
$scope->getFileDescription(),
$node->getLine()
), $errors);
}

/**
Expand All @@ -52,7 +57,7 @@ public function processNode(Node $node, Scope $scope): array {
*/
private function convertYamlErrorsToPHPStanErrors(array $yaml_errors): array {
return array_map(function(ModuliteYamlError $err) {
return new ModulitePHPStanError($err->getMessage(), $err->getYamlFilename(), $err->getLine());
return new ModulitePHPStanError($err->getMessage(), $err->getYamlFilename(), $err->getYamlFilename(), $err->getLine());
}, $yaml_errors);
}

Expand Down

0 comments on commit 7d24078

Please sign in to comment.