Completed
Push — master ( ac0b2b...25e509 )
by Nate
02:57
created

MetadataPropertyCollection::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Gson\Internal\Data;
8
9
use Tebru\Gson\PropertyMetadata;
10
11
/**
12
 * Class MetadataPropertyCollection
13
 *
14
 * @author Nate Brunette <[email protected]>
15
 */
16
final class MetadataPropertyCollection
17
{
18
    /**
19
     * An array of property metadata objects
20
     *
21
     * @var PropertyMetadata[]
22
     */
23
    private $properties = [];
24
25
    /**
26
     * Add a property metadata object
27
     *
28
     * @param PropertyMetadata $property
29
     */
30 2
    public function add(PropertyMetadata $property): void
31
    {
32 2
        $this->properties[$property->getName()] = $property;
33 2
    }
34
35
    /**
36
     * Get property metadata by its name, returns null if the property
37
     * doesn't exist.
38
     *
39
     * @param string $name
40
     * @return PropertyMetadata
0 ignored issues
show
Documentation introduced by
Should the return type not be PropertyMetadata|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
41
     */
42 3
    public function get(string $name): ?PropertyMetadata
43
    {
44 3
        if (!array_key_exists($name, $this->properties)) {
45 2
            return null;
46
        }
47
48 1
        return $this->properties[$name];
49
    }
50
}
51