Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.47% |
17 / 19 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TestResultCache | |
89.47% |
17 / 19 |
|
50.00% |
2 / 4 |
10.12 | |
0.00% |
0 / 1 |
| cache | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| isCached | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
4.03 | |||
| getCached | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| clear | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace HtaccessCapabilityTester; |
| 4 | |
| 5 | use \HtaccessCapabilityTester\Testers\AbstractTester; |
| 6 | |
| 7 | /** |
| 8 | * Class caching test results |
| 9 | * |
| 10 | * @package HtaccessCapabilityTester |
| 11 | * @author Bjørn Rosell <it@rosell.dk> |
| 12 | * @since Class available since the beginning |
| 13 | */ |
| 14 | class TestResultCache |
| 15 | { |
| 16 | |
| 17 | /* @var array Array for caching */ |
| 18 | protected static $cache; |
| 19 | |
| 20 | /** |
| 21 | * |
| 22 | * @param array $cacheKeys Two keys for caching (usually: basedir and the getCacheKey() for the Tester) |
| 23 | * @param TestResult $testResult The test result to cache |
| 24 | * |
| 25 | * @return void |
| 26 | */ |
| 27 | public static function cache($cacheKeys, $testResult) |
| 28 | { |
| 29 | if (!isset(self::$cache)) { |
| 30 | self::$cache = []; |
| 31 | } |
| 32 | list($key1, $key2) = $cacheKeys; |
| 33 | if (!isset(self::$cache[$key1])) { |
| 34 | self::$cache[$key1] = []; |
| 35 | } |
| 36 | self::$cache[$key1][$key2] = $testResult; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Check if in cache. |
| 41 | * |
| 42 | * @param array $cacheKeys Keys for caching (usually: basedir and the getCacheKey() for the Tester) |
| 43 | * |
| 44 | * @return bool |
| 45 | */ |
| 46 | public static function isCached($cacheKeys) |
| 47 | { |
| 48 | if (!isset(self::$cache)) { |
| 49 | return false; |
| 50 | } |
| 51 | list($key1, $key2) = $cacheKeys; |
| 52 | if (!isset(self::$cache[$key1])) { |
| 53 | return false; |
| 54 | } |
| 55 | if (!isset(self::$cache[$key1][$key2])) { |
| 56 | return false; |
| 57 | } |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get from cache. |
| 63 | * |
| 64 | * @param array $cacheKeys Keys for caching (usually: basedir and the getCacheKey() for the Tester) |
| 65 | * |
| 66 | * @return TestResult The test result |
| 67 | */ |
| 68 | public static function getCached($cacheKeys) |
| 69 | { |
| 70 | if (!self::isCached($cacheKeys)) { |
| 71 | throw new \Exception('Not in cache'); |
| 72 | } |
| 73 | list($key1, $key2) = $cacheKeys; |
| 74 | return self::$cache[$key1][$key2]; |
| 75 | } |
| 76 | |
| 77 | public static function clear() |
| 78 | { |
| 79 | self::$cache = null; |
| 80 | } |
| 81 | } |