| Total Complexity | 4 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class DefaultHashToPathMapper implements HashToPathMapperInterface |
||
| 13 | { |
||
| 14 | /** @var int */ |
||
| 15 | protected $NumberOfDirectories; |
||
| 16 | |||
| 17 | /** @var int */ |
||
| 18 | protected $CharsPerDirectory; |
||
| 19 | |||
| 20 | /** @var string */ |
||
| 21 | protected $DirectorySeparator; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param int $numberOfDirectories |
||
| 25 | * @param int $charsPerDirectory |
||
| 26 | * @param string $directorySeparator |
||
| 27 | */ |
||
| 28 | 4 | public function __construct($numberOfDirectories = 3, $charsPerDirectory = 2, $directorySeparator = '/') |
|
| 29 | { |
||
| 30 | 4 | $this->NumberOfDirectories = $numberOfDirectories; |
|
| 31 | 4 | $this->CharsPerDirectory = $charsPerDirectory; |
|
| 32 | 4 | $this->DirectorySeparator = $directorySeparator; |
|
| 33 | 4 | } |
|
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $hash |
||
| 37 | * @return string file path |
||
| 38 | */ |
||
| 39 | 4 | public function hashToPath($hash) |
|
| 40 | { |
||
| 41 | 4 | $prefix = ''; |
|
| 42 | |||
| 43 | 4 | for ($i = 0; $i < $this->NumberOfDirectories; ++$i) { |
|
| 44 | 4 | $prefix .= substr($hash, $i * $this->CharsPerDirectory, $this->CharsPerDirectory).$this->DirectorySeparator; |
|
| 45 | } |
||
| 46 | |||
| 47 | 4 | return $prefix.$hash; |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $filePath |
||
| 52 | * @return string hash |
||
| 53 | */ |
||
| 54 | 3 | public function pathToHash($filePath) |
|
| 59 | } |
||
| 60 | } |
||
| 61 |