SaveJsonSchema   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 17 3
1
<?php namespace HSkrasek\OpenAPI\Command\Stages;
2
3
use League\Flysystem\FilesystemInterface;
4
use League\Pipeline\StageInterface;
5
6
class SaveJsonSchema implements StageInterface
7
{
8
    /**
9
     * @var FilesystemInterface
10
     */
11
    private $filesystem;
12
13
    public function __construct(FilesystemInterface $filesystem)
14
    {
15
        $this->filesystem = $filesystem;
16
    }
17
18
    /**
19
     * @inheritDoc
20
     */
21
    public function __invoke($payload)
22
    {
23
        foreach ($payload[0] as $filename => $jsonSchema) {
24
            $schemaPath = $payload[1] . DIRECTORY_SEPARATOR . pathinfo($filename, PATHINFO_FILENAME) . '.json';
25
26
            if ($this->filesystem->has($schemaPath)) {
27
                $this->filesystem->delete($schemaPath);
28
            }
29
30
            $this->filesystem->put(
31
                $schemaPath,
32
                json_encode($jsonSchema, JSON_PRETTY_PRINT)
33
            );
34
        }
35
36
        return \count($payload[0]);
37
    }
38
}
39