Completed
Push — master ( d75c1f...eed677 )
by Viacheslav
12s
created

TypeOf   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toString() 0 7 3
A __construct() 0 4 1
1
<?php
2
3
namespace Swaggest\PhpCodeBuilder\Types;
4
5
use Swaggest\PhpCodeBuilder\PhpAnyType;
6
use Swaggest\PhpCodeBuilder\PhpClassTraitInterface;
7
use Swaggest\PhpCodeBuilder\PhpTemplate;
8
9
class TypeOf extends PhpTemplate
10
{
11
    /** @var PhpAnyType */
12
    private $type;
13
14
    /** @var bool */
15
    private $renderPhpDoc;
16
17
    /**
18
     * TypeOf constructor.
19
     * @param PhpAnyType $type
20
     */
21 3
    public function __construct(PhpAnyType $type, $renderPhpDoc = false)
22
    {
23 3
        $this->renderPhpDoc = $renderPhpDoc;
24 3
        $this->type = $type;
25 3
    }
26
27 3
    protected function toString()
28
    {
29 3
        if ($this->type instanceof PhpClassTraitInterface) {
30 3
            return $this->type->getReference();
31
        } else {
32 2
            $res = $this->renderPhpDoc ? $this->type->renderPhpDocType() : $this->type->renderArgumentType();
33 2
            return $res;
34
        }
35
    }
36
37
38
}