Passed
Push — php8 ( bd75dc...d8afb4 )
by Fabio
08:15
created

TNoUnserializeClassBehaviorTrait::dyWakeUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
/**
4
 * TNoUnserializeClassBehaviorTrait class file.
5
 *
6
 * @author Brad Anderson <[email protected]>
7
 * @link https://github.com/pradosoft/prado
8
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
9
 */
10
11
namespace Prado\Util\Behaviors;
12
13
use Prado\Util\TCallChain;
14
15
/**
16
 * TNoUnserializeClassBehaviorTrait class.
17
 *
18
 * When this trait is used by an IClassBehavior, upon the owner being unserialized
19
 * (via magic method __wakeup and dyWakeUp) this trait removes itself from its owner.
20
 *
21
 * This trait is used to deprecate serialized objects' IClassBehavior. By re-serializing
22
 * the object can be saved without the deprecated behavior.
23
 *
24
 * @author Brad Anderson <[email protected]>
25
 * @since 4.2.3
26
 */
27
trait TNoUnserializeClassBehaviorTrait
28
{
29
	/**
30
	 * This is raised when an owner is completed its unserialize() method call to
31
	 * __wakeup.  This method removes its behavior from the owner.
32
	 * @param object $owner The owner of he behavior raising the dynamic event.
33
	 * @param TCallChain $chain The chain of dynamic event method handlers.
34
	 */
35
	public function dyWakeUp(object $owner, TCallChain $chain)
36
	{
37
		if ($index = array_search($this, $owner->getBehaviors())) {
38
			$owner->detachBehavior($index);
39
		}
40
		return $chain->dyWakeUp();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $chain->dyWakeUp() targeting Prado\TComponent::dyWakeUp() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
	}
42
}
43