Completed
Pull Request — master (#34)
by Wachter
03:38
created

clearEntityManagerAfterTask()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.032
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 3
    public function __construct(EntityManagerInterface $entityManager = null)
31
    {
32 3
        $this->entityManager = $entityManager;
33 3
    }
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 3
    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 3
        if (!$this->entityManager) {
43
            return;
44
        }
45
46 3
        $this->entityManager->clear();
47 3
    }
48
}
49