GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ArtifactCollection   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
eloc 23
dl 0
loc 74
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 9 2
A getRequested() 0 14 3
A hasRequired() 0 10 3
A set() 0 6 2
A __construct() 0 6 2
1
<?php
2
3
4
namespace Kami\Component\RequestProcessor;
5
6
use Closure;
7
use Doctrine\Common\Collections\ArrayCollection;
8
9
/**
10
 * Class ArtifactCollection
11
 *
12
 * @package Kami\Component\RequestProcessor
13
 */
14
class ArtifactCollection extends ArrayCollection
15
{
16
17 19
    public function __construct(array $elements = [])
18
    {
19 19
        parent::__construct([]);
20
21 19
        foreach ($elements as $element) {
22 10
            $this->set($element->getName(), $element);
23
        }
24 19
    }
25
26
    /**
27
     * @param $element
28
     *
29
     * @return void
30
     */
31 7
    public function add($element) : void
32
    {
33
34 7
        if (!$element instanceof Artifact) {
35 1
            throw new \InvalidArgumentException('You can add only Artifact to ArtifactCollection');
36
        }
37
38 6
        $this->set($element->getName(), $element);
39 6
        return;
40
    }
41
42 16
    public function set($key, $value) : void
43
    {
44 16
        if (!$value instanceof Artifact) {
45 1
            throw new \InvalidArgumentException('You can add only Artifact to ArtifactCollection');
46
        }
47 15
        parent::set($key, $value);
48 15
    }
49
50
    /**
51
     * @param array $names
52
     *
53
     * @return bool
54
     */
55 2
    public function hasRequired(array $names) : bool
56
    {
57 2
        foreach ($names as $name) {
58 2
            if (!$this->containsKey($name)) {
59
60 2
                return false;
61
            }
62
        }
63
64 1
        return true;
65
    }
66
67
    /**
68
     * @param array $requestedArtifacts
69
     *
70
     * @throws ProcessingException
71
     *
72
     * @return ArtifactCollection
73
     */
74 4
    public function getRequested(array $requestedArtifacts) : ArtifactCollection
75
    {
76 4
        $requested = [];
77 4
        foreach ($requestedArtifacts as $requestedArtifact) {
78 2
            $artifact = $this->get($requestedArtifact);
79 2
            if (!$artifact) {
80 1
                throw new ProcessingException(
81 1
                    sprintf('You don\'t have requested artifact "%s" yet', $requestedArtifact)
82
                );
83
            }
84 2
            $requested[] = $artifact;
85
        }
86
87 3
        return new ArtifactCollection($requested);
88
    }
89
90
}