Passed
Push — master ( 32a609...1d1a5a )
by Alexander
23:59 queued 21:37
created

SwaggerService::fetch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Swagger\Service;
6
7
use OpenApi\Annotations\OpenApi;
8
use Yiisoft\Aliases\Aliases;
9
10
use function array_map;
11
use function OpenApi\scan;
12
13
final class SwaggerService
14
{
15
    private Aliases $aliases;
16
17
    private string $viewPath;
18
    private string $viewName;
19
20 5
    public function __construct(Aliases $aliases)
21
    {
22 5
        $this->aliases = $aliases;
23 5
        $this->setupDefaults();
24 5
    }
25
26 5
    private function setupDefaults(): void
27
    {
28 5
        $this->viewPath = dirname(__DIR__, 2) . '/views';
29 5
        $this->viewName = 'swagger-ui';
30 5
    }
31
32 2
    public function getViewPath(): string
33
    {
34 2
        return $this->aliases->get($this->viewPath);
35
    }
36
37 2
    public function getViewName(): string
38
    {
39 2
        return $this->viewName;
40
    }
41
42 2
    public function fetch(array $annotationPaths): OpenApi
43
    {
44 2
        if (count($annotationPaths) === 0) {
45 1
            throw new \InvalidArgumentException('$annotationPaths cannot be empty array');
46
        }
47
48 1
        $directories = array_map(fn(string $path) => $this->aliases->get($path), $annotationPaths);
49 1
        return scan($directories);
50
    }
51
}
52