Description::has()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Description;
6
7
/**
8
 * Descriptive metadata for objects.
9
 */
10
class Description implements DescriptionInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $descriptors = [];
16
17
    /**
18
     * @var array
19
     */
20
    private $priorities = [];
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 View Code Duplication
    public function get($descriptorKey): DescriptorInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        if (!isset($this->descriptors[$descriptorKey])) {
28
            throw new \InvalidArgumentException(sprintf(
29
                'Descriptor "%s" is not supported',
30
                $descriptorKey,
31
                implode('", "', array_keys($this->descriptors))
32
            ));
33
        }
34
35
        return $this->descriptors[$descriptorKey];
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function has($descriptor): bool
42
    {
43
        return isset($this->descriptors[$descriptor]);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function all(): array
50
    {
51
        return $this->descriptors;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function set(string $key, DescriptorInterface $descriptor, int $priority = 0)
58
    {
59
        // do not overwrite descriptor if a lower priority is given.
60
        if (isset($this->priorities[$key])) {
61
            if ($priority < $this->priorities[$key]) {
62
                return;
63
            }
64
        }
65
66
        $this->descriptors[$key] = $descriptor;
67
        $this->priorities[$key] = $priority;
68
    }
69
}
70