SaveJsonSchema::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
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