ProcessSchemaFiles::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php namespace HSkrasek\OpenAPI\Command\Stages;
2
3
use League\JsonReference\DereferencerInterface;
4
use League\JsonReference\Loader\ArrayLoader;
5
use League\Pipeline\Pipeline;
6
use League\Pipeline\StageInterface;
7
8
class ProcessSchemaFiles implements StageInterface
9
{
10
    /**
11
     * @var Pipeline
12
     */
13
    private $pipeline;
14
15
    /**
16
     * @var DereferencerInterface
17
     */
18
    private $dereferencer;
19
20
    public function __construct(Pipeline $pipeline, DereferencerInterface $dereferencer)
21
    {
22
        $this->pipeline     = $pipeline;
23
        $this->dereferencer = $dereferencer;
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function __invoke($payload)
30
    {
31
        $payload[0] = array_reduce($payload[0], function (array $carry, array $openApiSchemaFile) {
32
            $carry['/' . $openApiSchemaFile['basename']] = $this->pipeline->process($openApiSchemaFile);
33
34
            return $carry;
35
        }, []);
36
37
        $this->dereferencer->getLoaderManager()->registerLoader('file', new ArrayLoader($payload[0]));
38
39
        $payload[0] = array_map(function ($schema) {
40
            return $this->dereferencer->dereference($schema, 'file://');
41
        }, $payload[0]);
42
43
        return $payload;
44
    }
45
}
46