Completed
Push — develop ( 1e7bd2...15a723 )
by greg
03:25
created

Invitation::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
namespace PlaygroundGame\Mapper;
3
4
use Doctrine\ORM\EntityManager;
5
use PlaygroundGame\Options\ModuleOptions;
6
use PlaygroundUser\Entity\EmailVerification as Model;
7
use Zend\Stdlib\Hydrator\HydratorInterface;
8
use ZfcBase\EventManager\EventProvider;
9
10
class Invitation
11
{
12
    /**
13
     * @var \Doctrine\ORM\EntityManager
14
     */
15
    protected $em;
16
17
    /**
18
     * @var \PlaygroundUser\Options\ModuleOptions
19
     */
20
    protected $options;
21
22
    public function __construct(EntityManager $em, ModuleOptions $options)
0 ignored issues
show
Bug introduced by
You have injected the EntityManager via parameter $em. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
23
    {
24
        $this->em      = $em;
25
        $this->options = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options of type object<PlaygroundGame\Options\ModuleOptions> is incompatible with the declared type object<PlaygroundUser\Options\ModuleOptions> of property $options.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26
    }
27
28
    public function findByUser($user)
29
    {
30
        return $this->getEntityRepository()->findBy(array('user'=>$user));
31
    }
32
33
    public function findByRequestKey($key)
34
    {
35
        return $this->getEntityRepository()->findBy(array('requestKey'=>$key));
36
    }
37
38
    /**
39
     * @param string $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40
     * @return \Heineken\Entity\Invitation
41
     */
42
    public function findByGame($game)
43
    {
44
        return $this->getEntityRepository()->findBy(array('game'=>$game));
45
    }
46
47
    /**
48
     * @param string $id
49
     * @return \Heineken\Entity\Invitation
50
     */
51
    public function findById($id)
52
    {
53
        return $this->getEntityRepository()->find($id);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getEntityRepository()->find($id); of type object|null adds the type object to the return on line 53 which is incompatible with the return type documented by PlaygroundGame\Mapper\Invitation::findById of type Heineken\Entity\Invitation|null.
Loading history...
54
    }
55
56
    public function findBy($filter, $order = null, $limit = null, $offset = null)
57
    {
58
        return $this->getEntityRepository()->findBy($filter, $order, $limit, $offset);
59
    }
60
    
61
    /**
62
     * @return \Heineken\Entity\Invitation
63
     */
64
    public function findOneBy($array, $sortBy = array())
65
    {
66
        return $this->getEntityRepository()->findOneBy($array, $sortBy);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getEntityReposito...OneBy($array, $sortBy); of type object|null adds the type object to the return on line 66 which is incompatible with the return type documented by PlaygroundGame\Mapper\Invitation::findOneBy of type Heineken\Entity\Invitation|null.
Loading history...
67
    }
68
69
    /**
70
     * @return \Heineken\Entity\Invitation
71
     */
72
    public function insert($entity, $tableName = null, \Zend\Stdlib\Hydrator\HydratorInterface $hydrator = null)
0 ignored issues
show
Unused Code introduced by
The parameter $tableName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $hydrator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
    {
74
        return $this->persist($entity);
75
    }
76
77
    /**
78
     * @return \Heineken\Entity\Invitation
79
     */
80
    public function update($entity, $tableName = null, \Zend\Stdlib\Hydrator\HydratorInterface $hydrator = null)
0 ignored issues
show
Unused Code introduced by
The parameter $tableName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $hydrator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82
        return $this->persist($entity);
83
    }
84
85
    protected function persist($entity)
86
    {
87
        $this->em->persist($entity);
88
        $this->em->flush();
89
        return $entity;
90
    }
91
92
    public function findAll()
93
    {
94
        return $this->findBy(array(), array('createdAt' => 'DESC'));
95
    }
96
97
    public function remove($entity)
98
    {
99
        $this->em->remove($entity);
100
        $this->em->flush();
101
    }
102
103
    public function getEntityRepository()
104
    {
105
        return $this->em->getRepository('PlaygroundGame\Entity\Invitation');
106
    }
107
}
108