Completed
Branch master (4407aa)
by ANTHONIUS
03:30 queued 10s
created

UserManager   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 94
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getRepository() 0 3 1
A __construct() 0 9 1
A deleteUser() 0 4 1
A updateUser() 0 8 2
A reloadUser() 0 3 1
A findUserBy() 0 3 1
A findUsers() 0 3 1
A getClass() 0 8 2
1
<?php
0 ignored issues
show
Coding Style introduced by
Class found in ".php" file; use ".inc" extension instead
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "UserManager.php" doesn't match the expected filename "usermanager.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
4
 * This file is part of the DoyoUserBundle project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\UserBundle\Bridge\ORM;
15
16
use Doctrine\Common\Persistence\ObjectManager;
17
use Doctrine\Common\Persistence\ObjectRepository;
18
use Doyo\UserBundle\Manager\AbstractUserManager;
19
use Doyo\UserBundle\Model\UserInterface;
20
use Doyo\UserBundle\Util\CanonicalFieldsUpdaterInterface;
21
use Doyo\UserBundle\Util\PasswordUpdaterInterface;
22
23
class UserManager extends AbstractUserManager
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for class UserManager
Loading history...
24
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class UserManager
Loading history...
25
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
26
     * @var ObjectManager
27
     */
28
    private $objectManager;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
Coding Style introduced by
Private member variable "objectManager" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "objectManager" must be prefixed with an underscore
Loading history...
29
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @var string
32
     */
33
    private $class;
0 ignored issues
show
Coding Style introduced by
Private member variable "class" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "class" must be prefixed with an underscore
Loading history...
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $passwordUpdater should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $canonicalFieldsUpdater should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $manager should have a doc-comment as per coding-style.
Loading history...
36
     * UserManager constructor.
37
     *
38
     * @param string $class
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $class does not match actual variable name $passwordUpdater
Loading history...
39
     */
40 13
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
41
        PasswordUpdaterInterface $passwordUpdater,
42
        CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
43
        ObjectManager $manager,
44
        $class
45
    ) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
46 13
        $this->objectManager = $manager;
47 13
        $this->class         = $class;
48 13
        parent::__construct($passwordUpdater, $canonicalFieldsUpdater);
49
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $user should have a doc-comment as per coding-style.
Loading history...
52
     * {@inheritdoc}
53
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
54 1
    public function deleteUser(UserInterface $user)
55
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
56 1
        $this->objectManager->remove($user);
57 1
        $this->objectManager->flush();
58
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end deleteUser()
Loading history...
59
60
    /**
61
     * {@inheritdoc}
62
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
63 11
    public function getClass()
64
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
65 11
        if (false !== strpos($this->class, ':')) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
66 1
            $metadata    = $this->objectManager->getClassMetadata($this->class);
67 1
            $this->class = $metadata->getName();
68
        }
69
70 11
        return $this->class;
71
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getClass()
Loading history...
72
73
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $criteria should have a doc-comment as per coding-style.
Loading history...
74
     * {@inheritdoc}
75
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
76 8
    public function findUserBy(array $criteria)
77
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
78 8
        return $this->getRepository()->findOneBy($criteria);
79
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end findUserBy()
Loading history...
80
81
    /**
82
     * {@inheritdoc}
83
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
84 1
    public function findUsers()
85
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
86 1
        return $this->getRepository()->findAll();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getRepository()->findAll() returns the type array<mixed,object> which is incompatible with the return type mandated by Doyo\UserBundle\Manager\...rInterface::findUsers() of Traversable.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
87
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end findUsers()
Loading history...
88
89
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $user should have a doc-comment as per coding-style.
Loading history...
90
     * {@inheritdoc}
91
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
92 1
    public function reloadUser(UserInterface $user)
93
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
94 1
        $this->objectManager->refresh($user);
95
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end reloadUser()
Loading history...
96
97
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $user should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $andFlush should have a doc-comment as per coding-style.
Loading history...
98
     * {@inheritdoc}
99
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
100 5
    public function updateUser(UserInterface $user, $andFlush = true)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$andFlush" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$andFlush"; expected 0 but found 1
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
101
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
102 5
        $this->updateCanonicalFields($user);
103 5
        $this->updatePassword($user);
104
105 5
        $this->objectManager->persist($user);
106 5
        if ($andFlush) {
107 5
            $this->objectManager->flush();
108
        }
109
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end updateUser()
Loading history...
110
111
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
112
     * @return ObjectRepository
113
     */
114 9
    protected function getRepository()
115
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
116 9
        return $this->objectManager->getRepository($this->getClass());
117
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getRepository()
Loading history...
118
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
119