Test Failed
Pull Request — master (#870)
by Aleksei
08:56
created

DestructorTrait::destruct()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 12
rs 9.6111
c 0
b 0
f 0
cc 5
nc 4
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Internal\Common;
6
7
/**
8
 * @internal
9
 */
10
trait DestructorTrait
11
{
12
    public function destruct(): void
13
    {
14
        $class = new \ReflectionClass($this);
15
        foreach ($class->getProperties() as $property) {
16
            $name = $property->getName();
17
            if (!isset($this->$name)) {
18
                continue;
19
            }
20
            $value = $this->$name;
21
            unset($this->$name);
22
            if (\is_object($value) && \method_exists($value, 'destruct')) {
23
                $value->destruct();
24
            }
25
        }
26
    }
27
}
28