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

TNoUnserializeBehaviorTrait::dyWakeUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
/**
4
 * TNoUnserializeBehaviorTrait 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
 * TNoUnserializeBehaviorTrait class.
17
 *
18
 * When this trait is used by an IBehavior, upon the owner being unserialized (via
19
 * magic method __wakeup and dyWakeUp) this trait removes itself from its owner.
20
 *
21
 * This trait is used to deprecate serialized objects' IBehavior.  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 TNoUnserializeBehaviorTrait
28
{
29
	/**
30
	 * This is raised when an owner is completed its unserialize() method call to
31
	 * __wakeup.  This method removes it behavior from the owner.
32
	 * @param TCallChain $chain The chain of dynamic event method handlers.
33
	 */
34
	public function dyWakeUp(TCallChain $chain)
35
	{
36
		$owner = $this->getOwner();
0 ignored issues
show
Bug introduced by
It seems like getOwner() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
		/** @scrutinizer ignore-call */ 
37
  $owner = $this->getOwner();
Loading history...
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