Completed
Push — master ( e5ee14...111d0a )
by Gaetano
07:17
created

RepositoryUserSetterTrait::loginUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core;
4
5
/**
6
 * NB: needs a class member 'repository'
7
 */
8
trait RepositoryUserSetterTrait
9
{
10
    /**
11
     * Helper method to log in a user that can make changes to the system.
12
     * @param int $userId
13
     * @return int id of the previously logged in user
14
     */
15
    protected function loginUser($userId)
16
    {
17
        $previousUser = $this->repository->getCurrentUser();
0 ignored issues
show
Bug introduced by
The property repository does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
19
        if ($userId != $previousUser->id) {
20
            $this->repository->setCurrentUser($this->repository->getUserService()->loadUser($userId));
21
        }
22
23
        return $previousUser->id;
24
    }
25
}
26