|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\Files\Contract\Query; |
|
4
|
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Files\Contract\Response\ComposerFilesResponse; |
|
6
|
|
|
use PhpGitHooks\Module\Files\Domain\File; |
|
7
|
|
|
use PhpGitHooks\Module\Files\Domain\FilesCollection; |
|
8
|
|
|
|
|
9
|
|
|
class ComposerFilesExtractorHandler extends AbstractFilesExtractorQueryHandler |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @param FilesCollection $filesCollection |
|
13
|
|
|
* |
|
14
|
|
|
* @return ComposerFilesResponse |
|
15
|
|
|
*/ |
|
16
|
1 |
|
private function extract(FilesCollection $filesCollection) |
|
17
|
|
|
{ |
|
18
|
1 |
|
return new ComposerFilesResponse( |
|
19
|
1 |
|
$this->setExists($filesCollection->getFiles()), |
|
20
|
1 |
|
$this->setJsonFile($filesCollection->getFiles()), |
|
21
|
1 |
|
$this->setLockFile($filesCollection->getFiles()) |
|
22
|
|
|
); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param File[] $files |
|
27
|
|
|
* |
|
28
|
|
|
* @return bool |
|
29
|
|
|
*/ |
|
30
|
1 |
|
private function setExists(array $files) |
|
31
|
|
|
{ |
|
32
|
1 |
|
$exists = false; |
|
33
|
1 |
|
foreach ($files as $file) { |
|
34
|
1 |
|
if (true === (bool) preg_match('/^composer\.(json|lock)$/', $file->value())) { |
|
35
|
1 |
|
$exists = true; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
return $exists; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param File[] $files |
|
44
|
|
|
* |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
1 |
|
private function setJsonFile(array $files) |
|
48
|
|
|
{ |
|
49
|
1 |
|
$return = false; |
|
50
|
1 |
|
foreach ($files as $file) { |
|
51
|
1 |
|
if ('composer.json' === $file->value()) { |
|
52
|
1 |
|
$return = true; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
return $return; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param File[] $files |
|
61
|
|
|
* |
|
62
|
|
|
* @return bool |
|
63
|
|
|
*/ |
|
64
|
1 |
|
private function setLockFile(array $files) |
|
65
|
|
|
{ |
|
66
|
1 |
|
$return = false; |
|
67
|
1 |
|
foreach ($files as $file) { |
|
68
|
1 |
|
if ('composer.lock' === $file->value()) { |
|
69
|
1 |
|
$return = true; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
return $return; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param ComposerFilesExtractor $composerFilesFilesExtractorQuery |
|
78
|
|
|
* |
|
79
|
|
|
* @return ComposerFilesResponse |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function handle(ComposerFilesExtractor $composerFilesFilesExtractorQuery) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$files = $this->getFiles($composerFilesFilesExtractorQuery->getFiles()); |
|
84
|
|
|
|
|
85
|
1 |
|
return $this->extract(new FilesCollection($files)); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|