Passed
Push — deprecate/getLogEntriesForPage... ( 209510...c5a454 )
by Tomas Norre
09:05 queued 05:28
created

ProcessCollection   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 42.11%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 55
ccs 8
cts 19
cp 0.4211
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetGet() 0 6 2
A getProcessIds() 0 7 2
A offsetSet() 0 7 2
A append() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Domain\Model;
6
7
use AOE\Crawler\Exception\NoIndexFoundException;
8
9
/***************************************************************
10
 *  Copyright notice
11
 *
12
 *  (c) 2019 AOE GmbH <[email protected]>
13
 *
14
 *  All rights reserved
15
 *
16
 *  This script is part of the TYPO3 project. The TYPO3 project is
17
 *  free software; you can redistribute it and/or modify
18
 *  it under the terms of the GNU General Public License as published by
19
 *  the Free Software Foundation; either version 3 of the License, or
20
 *  (at your option) any later version.
21
 *
22
 *  The GNU General Public License can be found at
23
 *  http://www.gnu.org/copyleft/gpl.html.
24
 *
25
 *  This script is distributed in the hope that it will be useful,
26
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
 *  GNU General Public License for more details.
29
 *
30
 *  This copyright notice MUST APPEAR in all copies of the script!
31
 ***************************************************************/
32
33
/**
34
 * Class ProcessCollection
35
 *
36
 * @package AOE\Crawler\Domain\Model
37
 */
38
class ProcessCollection extends \ArrayObject
39
{
40
    /**
41
     * Method to retrieve an element from the collection.
42
     *
43
     * @throws NoIndexFoundException
44
     */
45
    public function offsetGet($index): Process
46
    {
47
        if (! parent::offsetExists($index)) {
48
            throw new NoIndexFoundException('Index "' . var_export($index, true) . '" for \AOE\Crawler\Domain\Model\Process are not available');
49
        }
50
        return parent::offsetGet($index);
51
    }
52
53
    /**
54
     * Method to add an element to the collection-
55
     *
56
     * @param Process $subject
57
     * @throws \InvalidArgumentException
58
     */
59 20
    public function offsetSet($index, $subject): void
60
    {
61 20
        if (! $subject instanceof Process) {
0 ignored issues
show
introduced by
$subject is always a sub-type of AOE\Crawler\Domain\Model\Process.
Loading history...
62
            throw new \InvalidArgumentException('Wrong parameter type given, "\AOE\Crawler\Domain\Model\Process" expected!');
63
        }
64
65 20
        parent::offsetSet($index, $subject);
66 20
    }
67
68
    /**
69
     * Method to append an element to the collection
70
     * @param Process $subject
71
     * @throws \InvalidArgumentException
72
     */
73 20
    public function append($subject): void
74
    {
75 20
        if (! $subject instanceof Process) {
0 ignored issues
show
introduced by
$subject is always a sub-type of AOE\Crawler\Domain\Model\Process.
Loading history...
76
            throw new \InvalidArgumentException('Wrong parameter type given, "\AOE\Crawler\Domain\Model\Process" expected!');
77
        }
78
79 20
        parent::append($subject);
80 20
    }
81
82
    /**
83
     * returns array of process ids of the current collection
84
     * @return array
85
     */
86
    public function getProcessIds()
87
    {
88
        $result = [];
89
        foreach ($this->getIterator() as $value) {
90
            $result[] = $value->getProcessId();
91
        }
92
        return $result;
93
    }
94
}
95