TypeOf::toString()   A
last analyzed

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 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 10
c 2
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 10
    public function __construct(PhpAnyType $type, $renderPhpDoc = false)
22
    {
23 10
        $this->renderPhpDoc = $renderPhpDoc;
24 10
        $this->type = $type;
25 10
    }
26
27 10
    protected function toString()
28
    {
29 10
        if ($this->type instanceof PhpClassTraitInterface) {
30 10
            return $this->type->getReference();
31
        } else {
32 7
            $res = $this->renderPhpDoc ? $this->type->renderPhpDocType() : $this->type->renderArgumentType();
33 7
            return $res;
34
        }
35
    }
36
37
38
}