Completed
Push — master ( dbdf9d...5ad886 )
by Jaap
02:58 queued 10s
created

Collection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 37
ccs 5
cts 11
cp 0.4545
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getFqsen() 0 4 1
A __toString() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of phpDocumentor.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @link      http://phpdoc.org
12
 */
13
14
namespace phpDocumentor\Reflection\Types;
15
16
use phpDocumentor\Reflection\Fqsen;
17
use phpDocumentor\Reflection\Type;
18
19
/**
20
 * Represents a collection type as described in the PSR-5, the PHPDoc Standard.
21
 *
22
 * A collection can be represented in two forms:
23
 *
24
 * 1. `ACollectionObject<aValueType>`
25
 * 2. `ACollectionObject<aValueType,aKeyType>`
26
 *
27
 * - ACollectionObject can be 'array' or an object that can act as an array
28
 * - aValueType and aKeyType can be any type expression
29
 */
30
final class Collection extends AbstractList
31
{
32
    /** @var Fqsen|null */
33
    private $fqsen;
34
35
    /**
36
     * Initializes this representation of an array with the given Type or Fqsen.
37
     */
38
    public function __construct(?Fqsen $fqsen, Type $valueType, ?Type $keyType = null)
39
    {
40
        parent::__construct($valueType, $keyType);
41
42
        $this->fqsen = $fqsen;
43
    }
44
45
    /**
46
     * Returns the FQSEN associated with this object.
47
     */
48
    public function getFqsen() : ?Fqsen
49
    {
50
        return $this->fqsen;
51
    }
52
53
    /**
54
     * Returns a rendered output of the Type as it would be used in a DocBlock.
55
     */
56 4
    public function __toString() : string
57
    {
58 4
        $objectType = (string) ($this->fqsen ?? 'object');
59
60 4
        if ($this->keyType === null) {
61 2
            return $objectType . '<' . $this->valueType . '>';
62
        }
63
64 2
        return $objectType . '<' . $this->keyType . ',' . $this->valueType . '>';
65
    }
66
}
67