GetOpenAPISchemaFiles   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 14 2
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