Completed
Push — master ( ca0646...6bce0e )
by Derek Stephen
05:45
created

FieldCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 55
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findByName() 0 14 3
A removeByName() 0 21 3
A current() 0 4 1
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
    /**
34
     * @param $name
35
     * @return bool
36
     */
37 1
    public function removeByName($name): bool
38
    {
39 1
        $this->rewind();
40
41 1
        while ($this->valid()) {
42 1
            $field = $this->current();
43
44 1
            if ($field->getName() == $name) {
45 1
                $key = $this->key();
46 1
                $this->offsetUnset($key);
47 1
                $this->rewind();
48
49 1
                return true;
50
            }
51 1
            $this->next();
52
        }
53
54 1
        $this->rewind();
55
56 1
        return false;
57
    }
58
59
    /**
60
     * @return FieldInterface
61
     */
62 51
    public function current(): FieldInterface
63
    {
64 51
        return parent::current();
65
    }
66
}