Skip to content

Commit

Permalink
Add error identifiers (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMuller authored Dec 13, 2024
1 parent 2ce1475 commit 8f5752b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
composer.lock

.idea
/.phpunit.cache
2 changes: 2 additions & 0 deletions src/Formatter/TypeCoverageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class TypeCoverageFormatter
*/
public function formatErrors(
string $message,
string $identifier,
float|int $minimalLevel,
TypeCountAndMissingTypes $typeCountAndMissingTypes
): array {
Expand Down Expand Up @@ -42,6 +43,7 @@ public function formatErrors(

foreach ($lines as $line) {
$ruleErrors[] = RuleErrorBuilder::message($errorMessage)
->identifier($identifier)
->file($filePath)
->line($line)
->build();
Expand Down
6 changes: 6 additions & 0 deletions src/Rules/ConstantTypeCoverageRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
public const ERROR_MESSAGE = 'Out of %d possible constant types, only %d - %.1f %% actually have it. Add more constant types to get over %s %%';

/**
* @var string
*/
private const IDENTIFIER = 'typeCoverage.constantTypeCoverage';

public function __construct(
private TypeCoverageFormatter $typeCoverageFormatter,
private Configuration $configuration,
Expand Down Expand Up @@ -65,6 +70,7 @@ public function processNode(Node $node, Scope $scope): array

return $this->typeCoverageFormatter->formatErrors(
self::ERROR_MESSAGE,
self::IDENTIFIER,
$this->configuration->getRequiredConstantTypeLevel(),
$typeCountAndMissingTypes
);
Expand Down
6 changes: 6 additions & 0 deletions src/Rules/ParamTypeCoverageRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
public const ERROR_MESSAGE = 'Out of %d possible param types, only %d - %.1f %% actually have it. Add more param types to get over %s %%';

/**
* @var string
*/
private const IDENTIFIER = 'typeCoverage.paramTypeCoverage';

public function __construct(
private TypeCoverageFormatter $typeCoverageFormatter,
private Configuration $configuration,
Expand Down Expand Up @@ -66,6 +71,7 @@ public function processNode(Node $node, Scope $scope): array

return $this->typeCoverageFormatter->formatErrors(
self::ERROR_MESSAGE,
self::IDENTIFIER,
$this->configuration->getRequiredParamTypeLevel(),
$typeCountAndMissingTypes
);
Expand Down
6 changes: 6 additions & 0 deletions src/Rules/PropertyTypeCoverageRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
public const ERROR_MESSAGE = 'Out of %d possible property types, only %d - %.1f %% actually have it. Add more property types to get over %s %%';

/**
* @var string
*/
private const IDENTIFIER = 'typeCoverage.propertyTypeCoverage';

public function __construct(
private TypeCoverageFormatter $typeCoverageFormatter,
private Configuration $configuration,
Expand Down Expand Up @@ -65,6 +70,7 @@ public function processNode(Node $node, Scope $scope): array

return $this->typeCoverageFormatter->formatErrors(
self::ERROR_MESSAGE,
self::IDENTIFIER,
$this->configuration->getRequiredPropertyTypeLevel(),
$typeCountAndMissingTypes
);
Expand Down
6 changes: 6 additions & 0 deletions src/Rules/ReturnTypeCoverageRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
public const ERROR_MESSAGE = 'Out of %d possible return types, only %d - %.1f %% actually have it. Add more return types to get over %s %%';

/**
* @var string
*/
private const IDENTIFIER = 'typeCoverage.returnTypeCoverage';

public function __construct(
private TypeCoverageFormatter $typeCoverageFormatter,
private Configuration $configuration,
Expand Down Expand Up @@ -65,6 +70,7 @@ public function processNode(Node $node, Scope $scope): array

return $this->typeCoverageFormatter->formatErrors(
self::ERROR_MESSAGE,
self::IDENTIFIER,
$this->configuration->getRequiredReturnTypeLevel(),
$typeCountAndMissingTypes
);
Expand Down

0 comments on commit 8f5752b

Please sign in to comment.