Completed
Push — wip-platform ( 1b7118...2b724b )
by
unknown
03:32
created

PreEvents::prePersistOrUpdate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\Bundle\CoreBundle\Admin\Traits;
14
15
use Blast\Bundle\CoreBundle\Tools\Reflection\ClassAnalyzer;
16
17
trait PreEvents
18
{
19
    /**
20
     * function prePersist.
21
     *
22
     * @see CoreAdmin::prePersistOrUpdate()
23
     **/
24
    public function prePersist($object)
25
    {
26
        $this->prePersistOrUpdate($object, 'prePersist');
27
    }
28
29
    /**
30
     * function prePersist.
31
     *
32
     * @see CoreAdmin::prePersistOrUpdate()
33
     **/
34
    public function preUpdate($object)
35
    {
36
        $this->prePersistOrUpdate($object, 'preUpdate');
37
    }
38
39
    /**
40
     * function prePersistOrUpdate.
41
     *
42
     * Searches in every trait (as if they were kind of Doctrine Behaviors) some logical to be
43
     * executed during the self::prePersist() or self::preUpdate() calls
44
     * The logical is stored in the self::prePersist{TraitName}() method
45
     *
46
     * @param object $object (Entity)
47
     * @param string $method (the current called method, eg. 'preUpdate' or 'prePersist')
48
     *
49
     * @return CoreAdmin $this
50
     **/
51
    protected function prePersistOrUpdate($object, $method)
52
    {
53
        $analyzer = new ClassAnalyzer();
54
        foreach ($analyzer->getTraits($this) as $traitname) {
55
            $rc = new \ReflectionClass($traitname);
56
            if (method_exists($this, $exec = $method . $rc->getShortName())) {
57
                $this->$exec($object);
58
            } // executes $this->prePersistMyTrait() or $this->preUpdateMyTrait() method
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
59
        }
60
61
        return $this;
62
    }
63
}
64