Completed
Push — master ( 75fca3...057bf7 )
by Fèvre
22s queued 10s
created

UserMailer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 32.73 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 9 9 1
A login() 0 9 1
A forgotPassword() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace App\Mailer;
3
4
use App\Model\Entity\User;
5
use Cake\Core\Configure;
6
use Cake\Mailer\Mailer;
7
8
class UserMailer extends Mailer
9
{
10
    /**
11
     * Register Email.
12
     *
13
     * @param User $user The user information.
14
     * @param array $viewVars The variables to pass to the view.
15
     *
16
     * @return void
17
     */
18 View Code Duplication
    public function register(User $user, $viewVars = [])
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...
19
    {
20
        $this
21
            ->emailFormat('html')
22
            ->from(['[email protected]' => __d('mail', 'Welcome on {0} !', Configure::read('Site.name'))])
23
            ->to($user->email)
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\Model\Entity\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...
24
            ->subject(__d('mail', 'Welcome on {0} !', Configure::read('Site.name')))
25
            ->set($viewVars);
26
    }
27
28
    /**
29
     * Login Email. Used when someone fail to login and his group is a staff group.
30
     *
31
     * @param array $viewVars The variables to pass to the view.
32
     *
33
     * @return void
34
     */
35
    public function login($viewVars = [])
36
    {
37
        $this
38
            ->emailFormat('html')
39
            ->from(['[email protected]' => __d('mail', 'Connexion on your account {0} !', h($viewVars['username']))])
40
            ->to($viewVars['email'])
41
            ->subject(__d('mail', 'Connexion on your account {0} !', h($viewVars['username'])))
42
            ->set($viewVars);
43
    }
44
45
    /**
46
     * ForgotPassword Email.
47
     *
48
     * @param User $user The user information.
49
     * @param array $viewVars The variables to pass to the view.
50
     *
51
     * @return void
52
     */
53 View Code Duplication
    public function forgotPassword(User $user, $viewVars = [])
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...
54
    {
55
        $this
56
            ->emailFormat('html')
57
            ->from(['[email protected]' => __d('mail', 'Forgot your Password - {0}', Configure::read('Site.name'))])
58
            ->to($user->email)
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\Model\Entity\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...
59
            ->subject(__d('mail', 'Forgot your Password - {0}', Configure::read('Site.name')))
60
            ->set($viewVars);
61
    }
62
}
63