Completed
Push — master ( f8a22c...480ba6 )
by ARCANEDEV
12s
created

GenerateConfirmationCode::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php namespace Arcanedev\LaravelAuth\Listeners\Users;
2
3
use Arcanedev\LaravelAuth\Events\Users\CreatingUser;
4
use Arcanedev\LaravelAuth\Services\UserConfirmator;
5
6
/**
7
 * Class     GenerateConfirmationCode
8
 *
9
 * @package  Arcanedev\LaravelAuth\Listeners\Users
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class GenerateConfirmationCode
13
{
14
    /* -----------------------------------------------------------------
15
     |  Main Methods
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * Handle the event.
21
     *
22
     * @param  \Arcanedev\LaravelAuth\Events\Users\CreatingUser  $event
23
     */
24 36
    public function handle(CreatingUser $event)
25
    {
26 36
        if (UserConfirmator::isEnabled()) {
27 36
            $event->user->confirmation_code = UserConfirmator::generateCode();
0 ignored issues
show
Bug introduced by
Accessing confirmation_code on the interface Arcanesoft\Contracts\Auth\Models\User 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...
28 12
        }
29
30 36
        return $event;
31
    }
32
}
33