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

User   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 36.76 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 96.3%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 25
loc 68
ccs 26
cts 27
cp 0.963
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A append() 0 4 1
A current() 0 4 1
A findKey() 12 12 3
A findById() 13 13 3
A update() 0 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}