GetOpenAPISchemaFiles::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php namespace HSkrasek\OpenAPI\Command\Stages;
2
3
use HSkrasek\OpenAPI\Exceptions\NoSchemaFilesFoundException;
4
use League\Flysystem\FilesystemInterface;
5
use League\Pipeline\StageInterface;
6
7
class GetOpenAPISchemaFiles implements StageInterface
8
{
9
    /**
10
     * @var FilesystemInterface
11
     */
12
    private $filesystem;
13
14
    public function __construct(FilesystemInterface $filesystem)
15
    {
16
        $this->filesystem = $filesystem;
17
    }
18
19
    /**
20
     * @inheritDoc
21
     * @throws \HSkrasek\OpenAPI\Exceptions\NoSchemaFilesFoundException
22
     */
23
    public function __invoke($payload)
24
    {
25
        $schemaFiles = array_filter($this->filesystem->listFiles($payload[0]), function (array $file) {
26
            return \in_array($file['extension'], ['json', 'yml', 'yaml'], true);
27
        });
28
29
        if (empty($schemaFiles)) {
30
            throw new NoSchemaFilesFoundException("No schema files found in $payload");
31
        }
32
33
        $payload[0] = $schemaFiles;
34
35
        return $payload;
36
    }
37
}
38