Issues (138)

Classes/Domain/Model/ProcessCollection.php (2 issues)

Severity
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
 * @internal since v9.2.5
37
 */
38
class ProcessCollection extends \ArrayObject
39
{
40
    /**
41
     * Method to retrieve an element from the collection.
42
     * @param mixed $index
43
     * @throws NoIndexFoundException
44
     */
45 3
    public function offsetGet($index): Process
46
    {
47 3
        if (! parent::offsetExists($index)) {
48 1
            throw new NoIndexFoundException('Index "' . var_export($index, true) . '" for \AOE\Crawler\Domain\Model\Process are not available', 1593714823);
49
        }
50 2
        return parent::offsetGet($index);
51
    }
52
53
    /**
54
     * Method to add an element to the collection-
55
     *
56
     * @param mixed $index
57
     * @param Process $subject
58
     * @throws \InvalidArgumentException
59
     */
60 13
    public function offsetSet($index, $subject): void
61
    {
62 13
        if (! $subject instanceof Process) {
0 ignored issues
show
$subject is always a sub-type of AOE\Crawler\Domain\Model\Process.
Loading history...
63 1
            throw new \InvalidArgumentException('Wrong parameter type given, "\AOE\Crawler\Domain\Model\Process" expected!', 1593714822);
64
        }
65
66 12
        parent::offsetSet($index, $subject);
67 12
    }
68
69
    /**
70
     * Method to append an element to the collection
71
     * @param Process $subject
72
     * @throws \InvalidArgumentException
73
     */
74 12
    public function append($subject): void
75
    {
76 12
        if (! $subject instanceof Process) {
0 ignored issues
show
$subject is always a sub-type of AOE\Crawler\Domain\Model\Process.
Loading history...
77 1
            throw new \InvalidArgumentException('Wrong parameter type given, "\AOE\Crawler\Domain\Model\Process" expected!', 1593714821);
78
        }
79
80 11
        parent::append($subject);
81 11
    }
82
83
    /**
84
     * returns array of process ids of the current collection
85
     * @return array
86
     */
87 1
    public function getProcessIds()
88
    {
89 1
        $result = [];
90 1
        foreach ($this->getIterator() as $value) {
91 1
            $result[] = $value->getProcessId();
92
        }
93 1
        return $result;
94
    }
95
}
96