Completed
Push — master ( b9c500...b355e1 )
by Allan
03:25
created

HandleUserTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 0
dl 0
loc 33
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validates() 0 20 3
1
<?php
2
3
namespace SMG\ManagerBundle\Controller\Traits;
4
5
trait HandleUserTrait
6
{
7
    /**
8
     * Check if the information in $user is enough
9
     * and valid to create a new User in database.
10
     *
11
     * @param User   $user  user to validate
12
     * @param string $group validation group to apply
13
     *
14
     * @return array contains the error(s) list,
15
     *               empty if no error
16
     */
17 10
    private function validates($user, $group)
18
    {
19 10
        $validationRules = array($group);
20
21 10
        if (!is_null($user->getEmail())) {
22 5
            $validationRules[] = 'with_email';
23
        }
24
25 10
        if (!is_null($user->getPhoneNumber())) {
26 5
            $validationRules[] = 'with_phone';
27
        }
28
29 10
        $validator = $this->container->get('validator');
0 ignored issues
show
Bug introduced by
The property container 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...
30 10
        $errors = $validator->validate(
31
            $user,
32
            $validationRules
33
        );
34
35 10
        return $errors;
36
    }
37
}
38