EntityManagerTrait::closeEntityManager()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php namespace Comodojo\Extender\Traits;
2
3
use \Doctrine\ORM\EntityManager;
4
5
/**
6
 * @package     Comodojo Extender
7
 * @author      Marco Giovinazzi <[email protected]>
8
 * @license     MIT
9
 *
10
 * LICENSE:
11
 *
12
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
 * THE SOFTWARE.
19
 */
20
21
trait EntityManagerTrait {
22
23
    /**
24
     * @var EntityManager
25
     */
26
    protected $em;
27
28
    /**
29
     * Get EntityManager
30
     *
31
     * @return EntityManager
32
     */
33
    public function getEntityManager() {
34
35
        return $this->em;
36
37
    }
38
39
    /**
40
     * Set EntityManager
41
     *
42
     * @param string $id
43
     * @return Schedule
0 ignored issues
show
Bug introduced by
The type Comodojo\Extender\Traits\Schedule was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
     */
45
    public function setEntityManager(EntityManager $em) {
46
47
        $this->em = $em;
48
49
        return $this;
50
51
    }
52
53
    public function closeEntityManager() {
54
55
        $em = $this->getEntityManager();
56
57
        if ( $em instanceof EntityManager ) {
0 ignored issues
show
introduced by
$em is always a sub-type of Doctrine\ORM\EntityManager.
Loading history...
58
            $em->getConnection()->close();
59
            $em->close();
60
        }
61
62
    }
63
64
    public function __destruct() {
65
66
        $this->closeEntityManager();
67
68
    }
69
70
}
71