OdmMetadata   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 13
lcom 2
cbo 3
dl 0
loc 112
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getMappingDocumentDirectory() 0 4 1
A getExtendedMappingDocumentDirectory() 0 4 1
A getDocumentDirectory() 0 4 1
A getExtendedDocumentDirectory() 0 4 1
A getExtendedSerializerDirectory() 0 4 1
A getDocumentMappingFiles() 0 12 2
A getDocumentNames() 0 18 3
A getRepositoryFiles() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\EasyExtendsBundle\Bundle;
15
16
use Symfony\Component\Finder\Finder;
17
18
class OdmMetadata
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $mappingDocumentDirectory;
24
25
    /**
26
     * @var string
27
     */
28
    protected $extendedMappingDocumentDirectory;
29
30
    /**
31
     * @var string
32
     */
33
    protected $documentDirectory;
34
35
    /**
36
     * @var string
37
     */
38
    protected $extendedDocumentDirectory;
39
40
    /**
41
     * @var string
42
     */
43
    protected $extendedSerializerDirectory;
44
45
    public function __construct(BundleMetadata $bundleMetadata)
46
    {
47
        $this->mappingDocumentDirectory = sprintf('%s/Resources/config/doctrine/', $bundleMetadata->getBundle()->getPath());
48
        $this->extendedMappingDocumentDirectory = sprintf('%s/Resources/config/doctrine/', $bundleMetadata->getExtendedDirectory());
49
        $this->documentDirectory = sprintf('%s/Document', $bundleMetadata->getBundle()->getPath());
50
        $this->extendedDocumentDirectory = sprintf('%s/Document', $bundleMetadata->getExtendedDirectory());
51
        $this->extendedSerializerDirectory = sprintf('%s/Resources/config/serializer', $bundleMetadata->getExtendedDirectory());
52
    }
53
54
    public function getMappingDocumentDirectory(): string
55
    {
56
        return $this->mappingDocumentDirectory;
57
    }
58
59
    public function getExtendedMappingDocumentDirectory(): string
60
    {
61
        return $this->extendedMappingDocumentDirectory;
62
    }
63
64
    public function getDocumentDirectory(): string
65
    {
66
        return $this->documentDirectory;
67
    }
68
69
    public function getExtendedDocumentDirectory(): string
70
    {
71
        return $this->extendedDocumentDirectory;
72
    }
73
74
    public function getExtendedSerializerDirectory(): string
75
    {
76
        return $this->extendedSerializerDirectory;
77
    }
78
79
    /**
80
     * @return array|\Iterator
81
     */
82
    public function getDocumentMappingFiles(): iterable
83
    {
84
        try {
85
            $f = new Finder();
86
            $f->name('*.mongodb.xml.skeleton');
87
            $f->in($this->getMappingDocumentDirectory());
88
89
            return $f->getIterator();
90
        } catch (\Exception $e) {
91
            return [];
92
        }
93
    }
94
95
    public function getDocumentNames(): array
96
    {
97
        $names = [];
98
99
        try {
100
            $f = new Finder();
101
            $f->name('*.mongodb.xml.skeleton');
102
            $f->in($this->getMappingDocumentDirectory());
103
104
            foreach ($f->getIterator() as $file) {
105
                $name = explode('.', $file->getFilename());
106
                $names[] = $name[0];
107
            }
108
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
109
        }
110
111
        return $names;
112
    }
113
114
    /**
115
     * @return array|\Iterator
116
     */
117
    public function getRepositoryFiles(): iterable
118
    {
119
        try {
120
            $f = new Finder();
121
            $f->name('*Repository.php');
122
            $f->in($this->getDocumentDirectory());
123
124
            return $f->getIterator();
125
        } catch (\Exception $e) {
126
            return [];
127
        }
128
    }
129
}
130