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