| Total Complexity | 8 |
| Total Lines | 107 |
| Duplicated Lines | 0 % |
| Coverage | 84% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class VersionService |
||
| 13 | { |
||
| 14 | 1 | use CanUseDotPath; |
|
| 15 | |||
| 16 | /** |
||
| 17 | * Undocumented variable |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | private $default = Versions::VERSION_1_0; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Undocumented variable |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $version; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Undocumented variable |
||
| 32 | * |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | private $cache = []; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Create a new instance |
||
| 39 | * |
||
| 40 | * @param string|null $version The version of the JSON:API specification |
||
| 41 | * |
||
| 42 | * @return void |
||
| 43 | */ |
||
| 44 | 777 | public function __construct(string $version = null) |
|
| 47 | 777 | } |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Set the version of the JSON:API specification |
||
| 51 | * |
||
| 52 | * @param string $version |
||
| 53 | * |
||
| 54 | * @return static |
||
| 55 | */ |
||
| 56 | 777 | public function setVersion(string $version) |
|
| 57 | { |
||
| 58 | 777 | $this->version = $version; |
|
| 59 | 777 | $this->createCache(); |
|
| 60 | |||
| 61 | 777 | return $this; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the version of the JSON:API specification |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | public function getVersion(): string |
||
| 70 | { |
||
| 71 | return $this->version; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Undocumented function |
||
| 76 | * |
||
| 77 | * @param string $path |
||
| 78 | * |
||
| 79 | * @return mixed |
||
| 80 | * @throws \VGirol\JsonApiStructure\Exception\DotPathException |
||
| 81 | */ |
||
| 82 | 441 | public function getRule(string $path) |
|
| 83 | { |
||
| 84 | 441 | return $this->retrieve($path, $this->cache); |
|
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Undocumented function |
||
| 89 | * |
||
| 90 | * @return array |
||
| 91 | */ |
||
| 92 | 777 | protected function getRulesFileContent(): array |
|
| 93 | { |
||
| 94 | 777 | return include __DIR__ . '/VersionRules.php'; |
|
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Undocumented function |
||
| 99 | * |
||
| 100 | * @return void |
||
| 101 | */ |
||
| 102 | 777 | private function createCache(): void |
|
| 119 | 777 | } |
|
| 120 | } |
||
| 121 |