ActivateUserByCode::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php namespace Anomaly\UsersModule\User\Command;
2
3
use Anomaly\UsersModule\User\Contract\UserInterface;
4
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
5
6
7
/**
8
 * Class ActivateUserByCode
9
 *
10
 * @link          http://pyrocms.com/
11
 * @author        PyroCMS, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 */
14
class ActivateUserByCode
15
{
16
17
    /**
18
     * The user instance.
19
     *
20
     * @var UserInterface
21
     */
22
    protected $user;
23
24
    /**
25
     * The activation code.
26
     *
27
     * @var string
28
     */
29
    protected $code;
30
31
    /**
32
     * Create a new ActivateUserByCode instance.
33
     *
34
     * @param UserInterface $user
35
     * @param               $code
36
     */
37
    function __construct(UserInterface $user, $code)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
38
    {
39
        $this->user = $user;
40
        $this->code = $code;
41
    }
42
43
    /**
44
     * Handle the command.
45
     *
46
     * @param  UserRepositoryInterface $users
47
     * @return bool
48
     */
49
    public function handle(UserRepositoryInterface $users)
50
    {
51
        if (!$user = $users->findByActivationCode($this->code)) {
52
            return false;
53
        }
54
55
        if ($this->user->getId() !== $user->getId()) {
56
            return false;
57
        }
58
59
        $this->user->activated       = true;
0 ignored issues
show
Bug introduced by
Accessing activated on the interface Anomaly\UsersModule\User\Contract\UserInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
60
        $this->user->activation_code = null;
0 ignored issues
show
Bug introduced by
Accessing activation_code on the interface Anomaly\UsersModule\User\Contract\UserInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
61
62
        $users->save($this->user);
63
64
        return true;
65
    }
66
}
67