Completed
Push — master ( bca24d...1b0d8b )
by John
03:18
created

VisiteeMixin::accept()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 4
nop 1
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Descriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace KleijnWeb\PhpApi\Descriptions\Description\Visitor;
9
10
/**
11
 * @author John Kleijn <[email protected]>
12
 */
13
trait VisiteeMixin
14
{
15
    /**
16
     * @param Visitor $visitor
17
     *
18
     * @return void
19
     */
20
    public function accept(Visitor $visitor)
21
    {
22
        foreach ($this as $attribute => $value) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<KleijnWeb\PhpApi\De...n\Visitor\VisiteeMixin> is not traversable.
Loading history...
23
            foreach ($this->isTraversable($value) ? $value : [$value] as $element) {
24
                if ($element instanceof Visitee) {
25
                    $element->accept($visitor);
26
                }
27
            }
28
        }
29
30
        /** @noinspection PhpParamsInspection */
31
        $visitor->visit($this);
32
    }
33
34
    /**
35
     * @param mixed $value
36
     *
37
     * @return bool
38
     */
39
    private function isTraversable($value): bool
40
    {
41
        return is_array($value) || $value instanceof \stdClass || $value instanceof \Traversable;
42
    }
43
}
44