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

TypeOf::toString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
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
}