Completed
Push — master ( e54b6a...c762b0 )
by John
03:11
created

RamlDescription::__construct()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 8
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\ApiDescriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\ApiDescriptions\Description\Standard\Raml;
10
11
use KleijnWeb\ApiDescriptions\Description\Description;
12
use KleijnWeb\ApiDescriptions\Document\Document;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 */
17
class RamlDescription extends Description
18
{
19
    /**
20
     * Description constructor.
21
     *
22
     * @param Document $document
23
     */
24
    public function __construct(Document $document)
25
    {
26
        $this->document = $document;
27
        $this->schemes  = array_map('strtolower', isset($document->protocols) ? $document->protocols : []);
28
29
        $document = clone $document;
30
31
        $document->apply(function ($definition, $attributeName, $parent, $parentAttributeName) {
32
            if (substr((string)$attributeName, 0, 1) === '/') {
33
                $pathName               = "{$parentAttributeName}{$attributeName}";
34
                $this->paths[$pathName] = new RamlPath($pathName, $definition);
35
            }
36
        });
37
    }
38
}
39