ProcessSchemaFiles   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 4

2 Methods

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