Completed
Push — master ( e2b148...0bc0e6 )
by Derek Stephen
06:06
created

User::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0185
1
<?php
2
3
namespace Del\Collection;
4
5
use Del\Entity\User as UserEntity;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use LogicException;
8
9
class User extends ArrayCollection
10
{
11
    /**
12
     * @param UserEntity $user
13
     * @return $this
14
     */
15 1
    public function update(UserEntity $user)
16
    {
17 1
        $key = $this->findKey($user);
18 1
        if($key) {
19
20 1
            $this->offsetSet($key,$user);
21 1
            return $this;
22
23
        }
24
        throw new LogicException('User was not in the collection.');
25
    }
26
27
    /**
28
     * @param UserEntity $user
29
     */
30 4
    public function append(UserEntity $user)
31
    {
32 4
        $this->add($user);
33 4
    }
34
35
    /**
36
     * @return UserEntity|null
37
     */
38 1
    public function current()
39
    {
40 1
        return parent::current();
41
    }
42
43
    /**
44
     * @param UserEntity $user
45
     * @return bool|int
46
     */
47 2 View Code Duplication
    public function findKey(UserEntity $user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49 2
        $it = $this->getIterator();
50 2
        $it->rewind();
51 2
        while($it->valid()) {
52 2
            if($it->current()->getId() == $user->getId()) {
53 1
                return $it->key();
54
            }
55 2
            $it->next();
56
        }
57 1
        return false;
58
    }
59
60
61
62 2 View Code Duplication
    public function findById($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64 2
        $it = $this->getIterator();
65 2
        $it->rewind();
66 2
        while($it->valid()) {
67 2
            if($it->current()->getId() == $id) {
68 1
                return $it->current();
69
            }
70 2
            $it->next();
71
        }
72
73 1
        return false;
74
    }
75
76
}