Completed
Push — master ( 973c28...6528f3 )
by Derek Stephen
08:47
created

FieldCollection::removeByName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 2
cts 2
cp 1
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
/**
3
 * User: delboy1978uk
4
 * Date: 19/11/2016
5
 * Time: 12:18
6
 */
7
8
namespace Del\Form\Collection;
9
10
use Del\Form\Field\FieldInterface;
11
12
class FieldCollection extends AbstractCollection implements CollectionInterface
13
{
14
    /**
15
     * @param $name
16
     * @return FieldInterface|null
17
     */
18 4
    public function findByName($name)
19
    {
20 4
        $this->rewind();
21 4
        while ($this->valid()) {
22
            /** @var FieldInterface $field */
23 3
            $field = $this->current();
24 3
            if ($field->getName() == $name) {
25 3
                return $field;
26
            }
27 1
            $this->next();
28
        }
29 1
        $this->rewind();
30 1
        return null;
31
    }
32
    /**
33
     * @param $name
34
     * @return FieldInterface|null
35
     */
36 50
    public function removeByName($name): bool
37
    {
38 50
        $this->rewind();
39
40
        while ($this->valid()) {
41
            $field = $this->current();
42
43
            if ($field->getName() == $name) {
44
                $key = $this->key();
45
                $this->offsetUnset($key);
46
                $this->rewind();
47
48
                $result = true;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
            }
50
        }
51
52
        $this->rewind();
53
54
        return false;
55
    }
56
57
    /**
58
     * @return FieldInterface
59
     */
60
    public function current(): FieldInterface
61
    {
62
        return parent::current();
63
    }
64
}