Passed
Pull Request — master (#2376)
by
unknown
04:54
created

Documentation   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getTermsOfService() 0 3 1
A getContact() 0 3 1
A __construct() 0 14 4
A getLicense() 0 3 1
A getResourceNameCollection() 0 3 1
A getVersion() 0 3 1
A getTitle() 0 3 1
A getMimeTypes() 0 5 1
A getDescription() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Documentation;
15
16
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection;
17
18
/**
19
 * Generates the API documentation.
20
 *
21
 * @author Amrouche Hamza <[email protected]>
22
 */
23
final class Documentation
24
{
25
    private $resourceNameCollection;
26
    private $info = [];
27
    private $mimeTypes = [];
28
29
    public function __construct(ResourceNameCollection $resourceNameCollection, array $info = [], array $formats = null)
30
    {
31
        $this->resourceNameCollection = $resourceNameCollection;
32
        $this->info = $info;
33
34
        if (null === $formats) {
35
            return;
36
        }
37
38
        @trigger_error(sprintf('Passing a 5th parameter to the constructor of "%s" is deprecated since API Platform 2.5', __CLASS__), E_USER_DEPRECATED);
39
40
        foreach ($formats as $mimeTypes) {
41
            foreach ($mimeTypes as $mimeType) {
42
                $this->mimeTypes[] = $mimeType;
43
            }
44
        }
45
    }
46
47
    public function getMimeTypes(): array
48
    {
49
        @trigger_error(sprintf('The method "%s" is deprecated since API Platform 2.5, use the "formats" attribute instead', __METHOD__), E_USER_DEPRECATED);
50
51
        return $this->mimeTypes;
52
    }
53
54
    public function getVersion(): string
55
    {
56
        return $this->info['version'] ?? '';
57
    }
58
59
    public function getDescription(): string
60
    {
61
        return $this->info['description'] ?? '';
62
    }
63
64
    public function getTitle(): string
65
    {
66
        return $this->info['title'] ?? '';
67
    }
68
69
    public function getContact(): array
70
    {
71
        return $this->info['contact'] ?? [];
72
    }
73
74
    public function getLicense(): array
75
    {
76
        return $this->info['license'] ?? [];
77
    }
78
79
    public function getTermsOfService(): string
80
    {
81
        return $this->info['termsOfService'] ?? '';
82
    }
83
84
    public function getResourceNameCollection(): ResourceNameCollection
85
    {
86
        return $this->resourceNameCollection;
87
    }
88
}
89