AssociationsArgumentConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

1 Method

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