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

DestructorTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A destruct() 0 12 5
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