| Total Complexity | 5 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class FileCachePathBuilder |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * FileCachePathBuilder constructor. |
||
| 16 | * |
||
| 17 | * @param FileCacheManager $fileManager |
||
| 18 | * @param string $baseDir |
||
| 19 | */ |
||
| 20 | public function __construct(private FileCacheManager $fileManager, private string $baseDir) |
||
| 21 | { |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Builds the full path for a cache item based on its key and namespace. |
||
| 26 | * |
||
| 27 | * @param string $cacheKey |
||
| 28 | * @param string $namespace |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | public function build(string $cacheKey, string $namespace = '') |
||
| 32 | { |
||
| 33 | $dir = $this->namespaceDir($namespace); |
||
| 34 | if (!empty($namespace)) { |
||
| 35 | $this->fileManager->createDirectory($dir); |
||
| 36 | } |
||
| 37 | return $dir . md5($cacheKey) . '.cache'; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Builds the directory path for a given namespace. |
||
| 42 | * |
||
| 43 | * @param string $namespace |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | public function namespaceDir(string $namespace = '') |
||
| 51 | } |
||
| 52 | } |
||
| 53 |