convertToAssociationTree()   A
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
c 1
b 0
f 0
nc 7
nop 1
dl 0
loc 23
rs 9.6111
1
<?php
2
3
namespace Malef\Associate\DoctrineOrm\Loader\ArgumentConverter;
4
5
use Malef\Associate\DoctrineOrm\Association\AssociationTree;
6
use Malef\Associate\DoctrineOrm\Association\AssociationTreeBuilder;
7
8
class AssociationsArgumentConverter
9
{
10
    /**
11
     * @param AssociationTree|string|string[] $associations
12
     *
13
     * @throws \Exception
14
     * @throws \InvalidArgumentException
15
     */
16
    public function convertToAssociationTree($associations): AssociationTree
17
    {
18
        if ($associations instanceof AssociationTree) {
19
            return $associations;
20
        }
21
22
        $associationsTreeBuilder = new AssociationTreeBuilder();
23
24
        if (is_string($associations)) {
25
            $associations = explode('.', $associations);
26
        }
27
28
        if (is_array($associations)) {
0 ignored issues
show
introduced by
The condition is_array($associations) is always true.
Loading history...
29
            foreach ($associations as $association) {
30
                $associationsTreeBuilder->associate($association);
31
            }
32
33
            return $associationsTreeBuilder->create();
34
        }
35
36
        // This code should not be reached.
37
        // @phpstan-ignore-next-line
38
        throw new \InvalidArgumentException();
39
    }
40
}
41