Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
php-code-coverage/src/StaticAnalysis/CachingCoveredFileAnalyser.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
92 lines (68 sloc)
2.45 KB
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
<?php declare(strict_types=1); | |
/* | |
* This file is part of phpunit/php-code-coverage. | |
* | |
* (c) Sebastian Bergmann <sebastian@phpunit.de> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace SebastianBergmann\CodeCoverage\StaticAnalysis; | |
use SebastianBergmann\LinesOfCode\LinesOfCode; | |
final class CachingCoveredFileAnalyser extends Cache implements CoveredFileAnalyser | |
{ | |
/** | |
* @var CoveredFileAnalyser | |
*/ | |
private $coveredFileAnalyser; | |
public function __construct(string $directory, CoveredFileAnalyser $coveredFileAnalyser) | |
{ | |
parent::__construct($directory); | |
$this->coveredFileAnalyser = $coveredFileAnalyser; | |
} | |
public function classesIn(string $filename): array | |
{ | |
if ($this->cacheHas($filename, __METHOD__)) { | |
return $this->cacheRead($filename, __METHOD__); | |
} | |
$data = $this->coveredFileAnalyser->classesIn($filename); | |
$this->cacheWrite($filename, __METHOD__, $data); | |
return $data; | |
} | |
public function traitsIn(string $filename): array | |
{ | |
if ($this->cacheHas($filename, __METHOD__)) { | |
return $this->cacheRead($filename, __METHOD__); | |
} | |
$data = $this->coveredFileAnalyser->traitsIn($filename); | |
$this->cacheWrite($filename, __METHOD__, $data); | |
return $data; | |
} | |
public function functionsIn(string $filename): array | |
{ | |
if ($this->cacheHas($filename, __METHOD__)) { | |
return $this->cacheRead($filename, __METHOD__); | |
} | |
$data = $this->coveredFileAnalyser->functionsIn($filename); | |
$this->cacheWrite($filename, __METHOD__, $data); | |
return $data; | |
} | |
public function linesOfCodeFor(string $filename): LinesOfCode | |
{ | |
if ($this->cacheHas($filename, __METHOD__)) { | |
return $this->cacheRead($filename, __METHOD__, [LinesOfCode::class]); | |
} | |
$data = $this->coveredFileAnalyser->linesOfCodeFor($filename); | |
$this->cacheWrite($filename, __METHOD__, $data); | |
return $data; | |
} | |
public function ignoredLinesFor(string $filename): array | |
{ | |
if ($this->cacheHas($filename, __METHOD__)) { | |
return $this->cacheRead($filename, __METHOD__); | |
} | |
$data = $this->coveredFileAnalyser->ignoredLinesFor($filename); | |
$this->cacheWrite($filename, __METHOD__, $data); | |
return $data; | |
} | |
} |