Skip to content

Commit

Permalink
LinterOutput implement Countable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Feb 22, 2023
1 parent 12e8ea1 commit 111359b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Changed-20230222-085614.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Changed
body: LinterOutput implement Countable interface
time: 2023-02-22T08:56:14.33882874Z
17 changes: 15 additions & 2 deletions src/Output/LinterOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Overtrue\PHPLint\Output;

use Countable;
use LogicException;
use Overtrue\PHPLint\Configuration\Resolver;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Finder\Finder;
Expand All @@ -27,7 +29,7 @@
* @author Laurent Laville
* @since Release 9.0.0
*/
final class LinterOutput
final class LinterOutput implements Countable
{
private Finder $finder;
private array $context;
Expand All @@ -45,6 +47,11 @@ public function __construct(array $results, Finder $finder)
$this->misses = $results['misses'] ?? [];
}

public function count(): int
{
return count($this->hits) + count($this->misses);
}

public function getContext(): array
{
return $this->context;
Expand All @@ -65,11 +72,17 @@ public function setContext(Resolver $configResolver, float $startTime): void
$cacheMisses > 1 ? 'es' : ''
);

try {
$fileCount = count($this->finder);
} catch (LogicException) {
$fileCount = 0;
}

$this->context = [
'time_usage' => $timeUsage,
'memory_usage' => $memUsage,
'cache_usage' => $cacheUsage,
'files_count' => count($this->finder),
'files_count' => $fileCount,
'options_used' => $configResolver->getOptions(),
];
}
Expand Down

0 comments on commit 111359b

Please sign in to comment.