Passed
Push — master ( 3f95f4...2f7c15 )
by Mickael
06:15 queued 11s
created

SearcherTrait::namespaceExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace ComposerLockParser;
4
5
use ComposerLockParser\Package\Package;
6
7
trait SearcherTrait {
8
9
    /**
10
     * @param string $name
11
     *
12
     * @return Package
13
     */
14
    public function getByName(string $name): Package
15
    {
16
        if (!$this->nameExists($name)) {
17
            throw new \UnexpectedValueException(sprintf('Sorry, Package %s not found !', $name));
18
        }
19
        return $this->getIndexedByName()[$name];
0 ignored issues
show
Bug introduced by
It seems like getIndexedByName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        return $this->/** @scrutinizer ignore-call */ getIndexedByName()[$name];
Loading history...
20
    }
21
22
    /**
23
     * @param string $namespace
24
     *
25
     * @return Package
26
     */
27
    public function getByNamespace(string $namespace): Package
28
    {
29
        if (!$this->namespaceExists($namespace)) {
30
            throw new \UnexpectedValueException(sprintf('Sorry, namespace %s not found !', $namespace));
31
        }
32
        return $this->getIndexedByNamespace()[$namespace];
0 ignored issues
show
Bug introduced by
It seems like getIndexedByNamespace() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        return $this->/** @scrutinizer ignore-call */ getIndexedByNamespace()[$namespace];
Loading history...
33
    }
34
35
    /**
36
     * @param string $name
37
     *
38
     * @return bool
39
     */
40
    public function nameExists(string $name): bool
41
    {
42
        return array_key_exists($name, $this->getIndexedByName());
43
    }
44
45
    /**
46
     * @param string $namespace
47
     *
48
     * @return bool
49
     */
50
    public function namespaceExists($namespace): bool
51
    {
52
        return array_key_exists($namespace, $this->getIndexedByNamespace());
53
    }
54
}
55