Completed
Push — master ( d8e2a0...679457 )
by Mahmoud
04:23
created

GenerateEmailConfirmationUrlTask   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 23 2
1
<?php
2
3
namespace App\Containers\Email\Tasks;
4
5
use App\Containers\Email\Exceptions\UserEmailNotFoundException;
6
use App\Containers\User\Models\User;
7
use App\Port\Task\Abstracts\Task;
8
use Illuminate\Support\Facades\Cache;
9
use Illuminate\Support\Facades\URL;
10
11
/**
12
 * Class GenerateEmailConfirmationUrlTask.
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16
class GenerateEmailConfirmationUrlTask extends Task
17
{
18
19
    /**
20
     * How long to keep the validation code on the memory (valid)
21
     *
22
     * default: 48 hours (2880 minutes)
23
     */
24
    const CONFIRMATION_CODE_VALIDATE_TIME = 2880;
25
26
    /**
27
     * @param $email
28
     * @param $password
29
     *
30
     * @return mixed
31
     */
32
    public function run(User $user)
33
    {
34
        // check if email exist on the user
35
        if (!$user->email) {
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\Containers\User\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
36
            throw new UserEmailNotFoundException;
37
        }
38
39
        // generate random unique token
40
        $confirmationCode = sha1(time() . $user->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Containers\User\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
41
42
        // 3. set token next to user id in the memory (redis)
43
        Cache::put('user:email-confirmation-code:' . $user->id, $confirmationCode,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Containers\User\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
44
            self::CONFIRMATION_CODE_VALIDATE_TIME);
45
46
        // set user status not confirmed (in case the user is updating his email)
47
        $user->confirmed = false;
0 ignored issues
show
Documentation introduced by
The property confirmed does not exist on object<App\Containers\User\Models\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
48
        $user->save();
49
50
        // build the url email confirmation URL with the confirmation code and user id
51
        $confirmationUrl = URL::to('/') . '/users/' . $user->id . '/email/confirmation/' . $confirmationCode;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Containers\User\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
52
53
        return $confirmationUrl;
54
    }
55
}
56