Completed
Push — master ( 46961e...b2acd3 )
by Axel
04:17 queued 01:11
created

JobManager   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
1
<?php
2
3
namespace Developtech\AgilityBundle\Manager;
4
5
use Doctrine\ORM\EntityManager;
6
use Developtech\AgilityBundle\Utils\Slugger;
7
8
abstract class JobManager {
9
      /** @var EntityManager **/
10
      protected $em;
11
      /** @var Slugger **/
12
      protected $slugger;
13
14
      /**
15
       * @param EntityManager $em
16
       * @param Slugger $slugger
17
       */
18 10
      public function __construct(EntityManager $em, Slugger $slugger) {
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...
19 10
          $this->em = $em;
20 10
          $this->slugger = $slugger;
21 10
      }
22
}
23