@@ 10-53 (lines=44) @@ | ||
7 | use PhpGitHooks\Module\Files\Contract\Response\JsonFilesResponse; |
|
8 | use PhpGitHooks\Module\Files\Domain\FilesCollection; |
|
9 | ||
10 | class JsonFilesExtractorHandler extends AbstractFilesExtractorQueryHandler implements QueryHandlerInterface |
|
11 | { |
|
12 | /** |
|
13 | * @param FilesCollection $filesCollection |
|
14 | * |
|
15 | * @return JsonFilesResponse |
|
16 | */ |
|
17 | private function extract(FilesCollection $filesCollection) |
|
18 | { |
|
19 | $jsonFiles = $this->getJsonFiles($filesCollection); |
|
20 | ||
21 | return new JsonFilesResponse($jsonFiles); |
|
22 | } |
|
23 | ||
24 | /** |
|
25 | * @param FilesCollection $filesCollection |
|
26 | * |
|
27 | * @return array |
|
28 | */ |
|
29 | private function getJsonFiles(FilesCollection $filesCollection) |
|
30 | { |
|
31 | $jsonFiles = []; |
|
32 | ||
33 | foreach ($filesCollection->getFiles() as $file) { |
|
34 | if (true === (bool)preg_match('/^(.*)(\.json)$/', $file->value())) { |
|
35 | $jsonFiles[] = $file->value(); |
|
36 | } |
|
37 | } |
|
38 | ||
39 | return $jsonFiles; |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * @param QueryInterface|JsonFilesExtractor $query |
|
44 | * |
|
45 | * @return JsonFilesResponse |
|
46 | */ |
|
47 | public function handle(QueryInterface $query) |
|
48 | { |
|
49 | $files = $query->getFiles(); |
|
50 | ||
51 | return $this->extract(new FilesCollection($this->getFiles($files))); |
|
52 | } |
|
53 | } |
|
54 |
@@ 10-53 (lines=44) @@ | ||
7 | use PhpGitHooks\Module\Files\Contract\Response\PhpFilesResponse; |
|
8 | use PhpGitHooks\Module\Files\Domain\FilesCollection; |
|
9 | ||
10 | class PhpFilesExtractorHandler extends AbstractFilesExtractorQueryHandler implements QueryHandlerInterface |
|
11 | { |
|
12 | /** |
|
13 | * @param FilesCollection $filesCollection |
|
14 | * |
|
15 | * @return PhpFilesResponse |
|
16 | */ |
|
17 | private function extract(FilesCollection $filesCollection) |
|
18 | { |
|
19 | $phFiles = $this->getPhpFiles($filesCollection); |
|
20 | ||
21 | return new PhpFilesResponse($phFiles); |
|
22 | } |
|
23 | ||
24 | /** |
|
25 | * @param FilesCollection $filesCollection |
|
26 | * |
|
27 | * @return array |
|
28 | */ |
|
29 | private function getPhpFiles(FilesCollection $filesCollection) |
|
30 | { |
|
31 | $phpFiles = []; |
|
32 | ||
33 | foreach ($filesCollection->getFiles() as $file) { |
|
34 | if (true === (bool) preg_match('/^(.*)(\.php)|(\.inc)$/', $file->value())) { |
|
35 | $phpFiles[] = $file->value(); |
|
36 | } |
|
37 | } |
|
38 | ||
39 | return $phpFiles; |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * @param QueryInterface|PhpFilesExtractorQuery $query |
|
44 | * |
|
45 | * @return PhpFilesResponse |
|
46 | */ |
|
47 | public function handle(QueryInterface $query) |
|
48 | { |
|
49 | $files = $this->getFiles($query->getFiles()); |
|
50 | ||
51 | return $this->extract(new FilesCollection($files)); |
|
52 | } |
|
53 | } |
|
54 |