OrmMetadata::getEntityMappingFiles()   A
last analyzed

Complexity

Conditions 2
Paths 6

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 6
nop 0
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 OrmMetadata
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $mappingEntityDirectory;
24
25
    /**
26
     * @var string
27
     */
28
    protected $extendedMappingEntityDirectory;
29
30
    /**
31
     * @var string
32
     */
33
    protected $entityDirectory;
34
35
    /**
36
     * @var string
37
     */
38
    protected $extendedEntityDirectory;
39
40
    /**
41
     * @var string
42
     */
43
    protected $extendedSerializerDirectory;
44
45
    public function __construct(BundleMetadata $bundleMetadata)
46
    {
47
        $this->mappingEntityDirectory = sprintf('%s/Resources/config/doctrine/', $bundleMetadata->getBundle()->getPath());
48
        $this->extendedMappingEntityDirectory = sprintf('%s/Resources/config/doctrine/', $bundleMetadata->getExtendedDirectory());
49
        $this->entityDirectory = sprintf('%s/Entity', $bundleMetadata->getBundle()->getPath());
50
        $this->extendedEntityDirectory = sprintf('%s/Entity', $bundleMetadata->getExtendedDirectory());
51
        $this->extendedSerializerDirectory = sprintf('%s/Resources/config/serializer', $bundleMetadata->getExtendedDirectory());
52
    }
53
54
    public function getMappingEntityDirectory(): string
55
    {
56
        return $this->mappingEntityDirectory;
57
    }
58
59
    public function getExtendedMappingEntityDirectory(): string
60
    {
61
        return $this->extendedMappingEntityDirectory;
62
    }
63
64
    public function getEntityDirectory(): string
65
    {
66
        return $this->entityDirectory;
67
    }
68
69
    public function getExtendedEntityDirectory(): string
70
    {
71
        return $this->extendedEntityDirectory;
72
    }
73
74
    public function getExtendedSerializerDirectory(): string
75
    {
76
        return $this->extendedSerializerDirectory;
77
    }
78
79
    /**
80
     * @return array|\Iterator
81
     */
82
    public function getEntityMappingFiles(): iterable
83
    {
84
        try {
85
            $f = new Finder();
86
            $f->name('*.orm.xml.skeleton');
87
            $f->name('*.orm.yml.skeleton');
88
            $f->in($this->getMappingEntityDirectory());
89
90
            return $f->getIterator();
91
        } catch (\Exception $e) {
92
            return [];
93
        }
94
    }
95
96
    public function getEntityNames(): array
97
    {
98
        $names = [];
99
100
        try {
101
            $f = new Finder();
102
            $f->name('*.orm.xml.skeleton');
103
            $f->name('*.orm.yml.skeleton');
104
            $f->in($this->getMappingEntityDirectory());
105
106
            foreach ($f->getIterator() as $file) {
107
                $name = explode('.', $file->getFilename());
108
                $names[] = $name[0];
109
            }
110
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
111
        }
112
113
        return $names;
114
    }
115
116
    /**
117
     * @return array|\Iterator
118
     */
119
    public function getRepositoryFiles(): iterable
120
    {
121
        try {
122
            $f = new Finder();
123
            $f->name('*Repository.php');
124
            $f->in($this->getEntityDirectory());
125
126
            return $f->getIterator();
127
        } catch (\Exception $e) {
128
            return [];
129
        }
130
    }
131
}
132