DeferredEntityLoaderFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Malef\Associate\DoctrineOrm\Loader;
4
5
use Malef\Associate\DoctrineOrm\Association\AssociationTree;
6
use Malef\Associate\DoctrineOrm\Loader\ArgumentConverter\AssociationsArgumentConverter;
7
use Malef\Associate\DoctrineOrm\Loader\ArgumentConverter\EntitiesArgumentConverter;
8
9
class DeferredEntityLoaderFactory
10
{
11
    /**
12
     * @var EntityLoader
13
     */
14
    protected $entityLoader;
15
16
    /**
17
     * @var AssociationsArgumentConverter
18
     */
19
    protected $associationsArgumentConverter;
20
21
    public function __construct(EntityLoader $entityLoader)
22
    {
23
        $this->entityLoader = $entityLoader;
24
        $this->associationsArgumentConverter = new AssociationsArgumentConverter();
25
    }
26
27
    /**
28
     * @param AssociationTree|string[]|string $associationTree
29
     *
30
     * @throws \Exception
31
     */
32
    public function create(
33
        $associationTree,
34
        ?string $entityClassName
35
    ): DeferredEntityLoader {
36
        return new DeferredEntityLoader(
37
            new EntitiesArgumentConverter(),
38
            $this->entityLoader,
39
            $this->associationsArgumentConverter->convertToAssociationTree($associationTree),
40
            $entityClassName
41
        );
42
    }
43
}
44