Completed
Branch test-coverage (951e01)
by Tomas Norre
15:40 queued 13:43
created

ProcessCollection   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetGet() 0 7 2
A offsetSet() 0 7 2
A append() 0 7 2
A getProcessIds() 0 8 2
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
    public function offsetGet($index)
43
    {
44
        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
            throw new \Exception('Index "' . var_export($index, true) . '" for \AOE\Crawler\Domain\Model\Process are not available');
46
        }
47
        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
    public function offsetSet($index, $subject)
59
    {
60
        if (! $subject instanceof Process) {
61
            throw new \InvalidArgumentException('Wrong parameter type given, "\AOE\Crawler\Domain\Model\Process" expected!');
62
        }
63
        parent::offsetSet($index, $subject);
64
    }
65
66
    /**
67
     * Method to append an element to the collection
68
     * @param Process $subject
69
     * @throws \InvalidArgumentException
70
     * @return void
71
     */
72
    public function append($subject)
73
    {
74
        if (! $subject instanceof Process) {
75
            throw new \InvalidArgumentException('Wrong parameter type given, "\AOE\Crawler\Domain\Model\Process" expected!');
76
        }
77
        parent::append($subject);
78
    }
79
80
    /**
81
     * returns array of process ids of the current collection
82
     * @return array
83
     */
84
    public function getProcessIds()
85
    {
86
        $result = [];
87
        foreach ($this->getIterator() as $value) {
88
            $result[] = $value->getProcess_id();
89
        }
90
        return $result;
91
    }
92
}
93