|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licenced under the GNU LGPL v3. |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Blast\Bundle\CoreBundle\Admin\Traits; |
|
13
|
|
|
|
|
14
|
|
|
use Blast\Bundle\CoreBundle\Tools\Reflection\ClassAnalyzer; |
|
15
|
|
|
|
|
16
|
|
|
trait PreEvents |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* function prePersist. |
|
20
|
|
|
* |
|
21
|
|
|
* @see CoreAdmin::prePersistOrUpdate() |
|
22
|
|
|
**/ |
|
23
|
|
|
public function prePersist($object) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->prePersistOrUpdate($object, 'prePersist'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* function prePersist. |
|
30
|
|
|
* |
|
31
|
|
|
* @see CoreAdmin::prePersistOrUpdate() |
|
32
|
|
|
**/ |
|
33
|
|
|
public function preUpdate($object) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->prePersistOrUpdate($object, 'preUpdate'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* function prePersistOrUpdate. |
|
40
|
|
|
* |
|
41
|
|
|
* Searches in every trait (as if they were kind of Doctrine Behaviors) some logical to be |
|
42
|
|
|
* executed during the self::prePersist() or self::preUpdate() calls |
|
43
|
|
|
* The logical is stored in the self::prePersist{TraitName}() method |
|
44
|
|
|
* |
|
45
|
|
|
* @param object $object (Entity) |
|
46
|
|
|
* @param string $method (the current called method, eg. 'preUpdate' or 'prePersist') |
|
47
|
|
|
* |
|
48
|
|
|
* @return CoreAdmin $this |
|
49
|
|
|
**/ |
|
50
|
|
|
protected function prePersistOrUpdate($object, $method) |
|
51
|
|
|
{ |
|
52
|
|
|
$analyzer = new ClassAnalyzer(); |
|
53
|
|
|
foreach ($analyzer->getTraits($this) as $traitname) { |
|
54
|
|
|
$rc = new \ReflectionClass($traitname); |
|
55
|
|
|
if (method_exists($this, $exec = $method . $rc->getShortName())) { |
|
56
|
|
|
$this->$exec($object); |
|
57
|
|
|
} // executes $this->prePersistMyTrait() or $this->preUpdateMyTrait() method |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
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.