Completed
Push — master ( a5d24e...028b40 )
by Gabriel
02:43
created

GroupRepository::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 9
loc 9
rs 9.6666
cc 2
eloc 6
nc 2
nop 3
1
<?php
2
3
namespace Sinergi\Users\Doctrine\Group;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\EntityRepository;
7
use Doctrine\ORM\Mapping\ClassMetadata;
8
use Interop\Container\ContainerInterface;
9
use Sinergi\Users\Container;
10
use Sinergi\Users\Group\GroupEntityInterface;
11
use Sinergi\Users\Group\GroupRepositoryInterface;
12
use Sinergi\Users\User\UserRepositoryInterface;
13
14
class GroupRepository extends EntityRepository implements GroupRepositoryInterface
15
{
16
    private $container;
17
18 View Code Duplication
    public function __construct(EntityManager $em, ClassMetadata $class, ContainerInterface $container)
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
        parent::__construct($em, $class);
21
        if ($container instanceof Container) {
22
            $this->container = $container;
23
        } else {
24
            $this->container = new Container($container);
25
        }
26
    }
27
28
    public function save(GroupEntityInterface $group)
29
    {
30
        $this->getEntityManager()->persist($group);
31
        $this->getEntityManager()->flush($group);
32
    }
33
34
    /** @return GroupEntityInterface|null */
35 View Code Duplication
    public function findById(int $id)
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...
36
    {
37
        $result = $this->createQueryBuilder('g')
38
            ->where('g.id = :id')
39
            ->setParameter('id', $id)
40
            ->getQuery()
41
            ->getResult();
42
43
        if ($result && $result[0]) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $result of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
44
            /** @var GroupEntityInterface $group */
45
            $group = $result[0];
46
            $group->setUserRepository(UserRepositoryInterface::class);
47
            return $group;
48
        }
49
50
        return null;
51
    }
52
}
53