Completed
Pull Request — master (#10)
by
unknown
05:51 queued 02:49
created

InMemoryUserRepository::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\User;
4
5
/**
6
 * Class InMemoryUserRepository
7
 */
8
class InMemoryUserRepository implements UserRepository
9
{
10
    /** @var array */
11
    private $users = [];
12
13
    public function __construct()
14
    {
15
        $this->users[] = new User(
16
            'wouter',
17
            'test',
18
            'Wouter Sioen'
19
        );
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function findByUsername($username)
26
    {
27
        foreach ($this->users as $user) {
28
            if ($user->getUsername() === $username) {
29
                return $user;
30
            }
31
        }
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function supportsClass($class)
38
    {
39
        return $class === User::class;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function add(User $user, $save = true)
46
    {
47
        $this->users[] = $user;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function save(User $user = null)
54
    {
55
        if ($user === null) {
56
            return;
57
        }
58
59
        $this->users[] = $user;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 View Code Duplication
    public function update(User $userToUpdate, User $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...
66
    {
67
        foreach ($this->users as $key => $row) {
68
            if ($row->getUserName() === $user->getUserName()) {
69
                $this->users[$key] = $user;
70
                break;
71
            }
72
        }
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 View Code Duplication
    public function delete(User $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...
79
    {
80
        foreach ($this->users as $key => $row) {
81
            if ($row->getUserName() === $user->getUserName()) {
82
                unset($this->users[$key]);
83
                break;
84
            }
85
        }
86
    }
87
}
88