| Total Complexity | 7 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class FileSystemHash implements FileSystemHashInterface |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @inheritdoc |
||
| 16 | */ |
||
| 17 | public function hashPath($path) |
||
| 18 | { |
||
| 19 | $path = realpath($path); |
||
| 20 | $hashes = []; |
||
| 21 | |||
| 22 | if (is_dir($path)) { |
||
| 23 | $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); |
||
| 24 | |||
| 25 | /** @var SplFileInfo $file */ |
||
| 26 | foreach ($it as $file) { |
||
| 27 | if ($file->isFile()) { |
||
| 28 | $hashes[] = md5_file($file) . '-' . $this->hashPathName((string)$file); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | if (empty($hashes)) { |
||
| 33 | $hashes[] = 'null-' . $this->hashPathName($path); |
||
| 34 | } else { |
||
| 35 | sort($hashes); |
||
| 36 | } |
||
| 37 | } else { |
||
| 38 | $hashes[] = md5_file($path) . '-' . $this->hashPathName((string)$path); |
||
| 39 | } |
||
| 40 | |||
| 41 | return md5(implode('|', $hashes)); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @inheritdoc |
||
| 46 | */ |
||
| 47 | public function hashPathName($path) |
||
| 56 | } |
||
| 57 | } |
||
| 58 |