Completed
Push — issue/261 ( 1905ee )
by Stefan
14:25
created

ProcessCollection::append()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace AOE\Crawler\Domain\Model;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2017 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
/**
29
 * Class ProcessCollection
30
 *
31
 * @package AOE\Crawler\Domain\Model
32
 */
33
class ProcessCollection extends \ArrayObject
34
{
35
36
    /**
37
     * Method to retrieve an element from the collection.
38
     *
39
     * @throws \Exception
40
     * @return Process
41
     */
42 3
    public function offsetGet($index)
43
    {
44 3
        if (! parent::offsetExists($index)) {
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (offsetExists() instead of offsetGet()). Are you sure this is correct? If so, you might want to change this to $this->offsetExists().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
45 1
            throw new \Exception('Index "' . var_export($index, true) . '" for \AOE\Crawler\Domain\Model\Process are not available');
46
        }
47 2
        return parent::offsetGet($index);
48
    }
49
50
    /**
51
     * Method to add an element to the collection-
52
     *
53
     * @param mixed $index
54
     * @param Process $subject
55
     * @throws \InvalidArgumentException
56
     * @return void
57
     */
58 3
    public function offsetSet($index, $subject)
59
    {
60 3
        if (! $subject instanceof Process) {
61 1
            throw new \InvalidArgumentException('Wrong parameter type given, "\AOE\Crawler\Domain\Model\Process" expected!');
62
        }
63 2
        parent::offsetSet($index, $subject);
64 2
    }
65
66
    /**
67
     * Method to append an element to the collection
68
     * @param Process $subject
69
     * @throws \InvalidArgumentException
70
     * @return void
71
     */
72 2
    public function append($subject)
73
    {
74 2
        if (! $subject instanceof Process) {
75 1
            throw new \InvalidArgumentException('Wrong parameter type given, "\AOE\Crawler\Domain\Model\Process" expected!');
76
        }
77 1
        parent::append($subject);
78 1
    }
79
80
    /**
81
     * returns array of process ids of the current collection
82
     * @return array
83
     */
84 1
    public function getProcessIds()
85
    {
86 1
        $result = [];
87 1
        foreach ($this->getIterator() as $value) {
88 1
            $result[] = $value->getProcess_id();
89
        }
90 1
        return $result;
91
    }
92
}
93