Completed
Push — master ( a45cae...481637 )
by Daniel
39:55
created

DoctrineTaskExecutionListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A clearEntityManagerAfterTask() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\EventListener;
13
14
use Doctrine\ORM\EntityManagerInterface;
15
use Task\Event\TaskExecutionEvent;
16
17
/**
18
 * Listens on task-execution events.
19
 */
20
class DoctrineTaskExecutionListener
21
{
22
    /**
23
     * @var EntityManagerInterface
24
     */
25
    private $entityManager;
26
27
    /**
28
     * @param EntityManagerInterface $entityManager
29
     */
30
    public function __construct(EntityManagerInterface $entityManager = null)
31
    {
32
        $this->entityManager = $entityManager;
33
    }
34
35
    /**
36
     * This method clears the entity-manager after each task to ensure clean state before next task.
37
     *
38
     * @param TaskExecutionEvent $event
39
     */
40
    public function clearEntityManagerAfterTask(TaskExecutionEvent $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event 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...
41
    {
42
        if (!$this->entityManager) {
43
            return;
44
        }
45
46
        $this->entityManager->clear();
47
    }
48
}
49