ProxyGenerator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getProxyFactory() 0 3 1
A getProxyDir() 0 3 1
A getMetadataCollection() 0 3 1
A __invoke() 0 16 2
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * (c) Olivier Laviale <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace olvlvl\DoctrineGenerators\Document;
11
12
use Doctrine\ODM\MongoDB\DocumentManager;
13
use Doctrine\ODM\MongoDB\Proxy\ProxyFactory;
14
15
class ProxyGenerator
16
{
17
    use EnsureDirectory;
18
19
    /**
20
     * @var DocumentManager
21
     */
22
    private $documentManager;
23
24
    public function __construct(DocumentManager $documentManager)
25
    {
26
        $this->documentManager = $documentManager;
27
    }
28
29
    /**
30
     * @return string[]
31
     */
32
    public function __invoke(): array
33
    {
34
        $metadataCollection = $this->getMetadataCollection();
35
36
        if (count($metadataCollection) === 0) {
37
            return [];
38
        }
39
40
        $this->getProxyFactory()->generateProxyClasses(
41
            $metadataCollection,
42
            $this->ensureDirectory($this->getProxyDir())
43
        );
44
45
        return array_map(function ($metadata) {
46
            return $metadata->name;
47
        }, $metadataCollection);
48
    }
49
50
    private function getMetadataCollection(): array
51
    {
52
        return $this->documentManager->getMetadataFactory()->getAllMetadata();
53
    }
54
55
    private function getProxyDir(): string
56
    {
57
        return $this->documentManager->getConfiguration()->getProxyDir();
58
    }
59
60
    private function getProxyFactory(): ProxyFactory
61
    {
62
        return $this->documentManager->getProxyFactory();
63
    }
64
}
65