Module   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 12
eloc 47
dl 0
loc 113
ccs 21
cts 30
cp 0.7
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A getPaths() 0 3 1
A __construct() 0 7 2
A getName() 0 3 1
A mappingExists() 0 3 1
A getDiretorio() 0 3 1
A getLocalFile() 0 3 1
A getLocalMapping() 0 3 1
A fileExistsInModule() 0 4 1
A getPathModule() 0 8 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: thales
5
 * Date: 24/11/2018
6
 * Time: 22:35
7
 */
8
9
namespace Saci\Console\Domain\Entity;
10
11
use Saci\Console\Infrastructure\Application\SymfonyEventAdapter;
12
13
/**
14
 * Class Module
15
 * @package Saci\Domain\Entity
16
 * @covers \Test\Domain\Entity\ModuleTest
17
 */
18
class Module
19
{
20
21
    const DS = DIRECTORY_SEPARATOR;
22
    const ROOT = 'src';
23
    const APPLICATION = self::DS . 'Application';
24
    const USE_CASE = self::DS . 'UseCases';
25
    const CONTROLLERS = self::APPLICATION . self::DS . 'Controllers';
26
    const DOMAIN = self::DS . 'Domain';
27
    const ENTITIES = self::DOMAIN . self::DS . 'Entities';
28
    const VO = self::DOMAIN . self::DS . 'ValueObjects';
29
    const EVENTS = self::DOMAIN . self::DS . 'Events';
30
    const REPOSITORIES = self::DOMAIN . self::DS . 'Repositories';
31
    const INFRASTRUCTURE =  self::DS . 'Infrastructure';
32
    const PERSISTENCE = self::INFRASTRUCTURE . self::DS . 'Persistence';
33
    const ORM = self::PERSISTENCE . self::DS . 'ORM';
34
    const DOCTRINE = self::ORM . self::DS . 'Doctrine';
35
    const MAPPING = self::DOCTRINE . self::DS . 'Mapping';
36
    const INFRASTRUCTURE_REPOSITORIES = self::DOCTRINE . self::DS . 'Repositories';
37
38
    private $name;
39
40
    private $paths = [
41
        self::CONTROLLERS,
42
        self::USE_CASE,
43
        self::ENTITIES,
44
        self::VO,
45
        self::EVENTS,
46
        self::REPOSITORIES,
47
        self::MAPPING,
48
        self::INFRASTRUCTURE_REPOSITORIES,
49
    ];
50
    /**
51
     * @var string
52
     */
53
    private $diretorio;
54
55 12
    public function __construct(string $name, string $diretorio)
56
    {
57 12
        $this->name = ucfirst(strtolower($name));
58 12
        $this->diretorio = $diretorio;
59
60 12
        foreach ($this->paths as &$path) {
61 12
            $path = $this->getDiretorio() . self::DS . self::ROOT . self::DS . $this->getName() . DIRECTORY_SEPARATOR . $path;
62
        }
63 12
    }
64
65
    /**
66
     * @param string $name
67
     * @param string $diretorio
68
     * @return Module
69
     */
70 1
    public static function create(string $name, string $diretorio): Module
71
    {
72 1
        $module = new self($name, $diretorio);
73 1
        SymfonyEventAdapter::getInstance()->publish(
74 1
            new \Saci\Console\Infrastructure\Domain\Events\ModuleWasCreated($module)
75
        );
76
77 1
        return $module;
78
    }
79
80
    /**
81
     * @return string
82
     */
83 12
    public function getName(): string
84
    {
85 12
        return $this->name;
86
    }
87
88
89 2
    public function getPaths(): array
90
    {
91 2
        return $this->paths;
92
    }
93
94 2
    public function getPathModule()
95
    {
96 2
        $path = $this->getDiretorio();
97 2
        if (strpos($this->getDiretorio(), self::DS . self::ROOT)) {
98
            $path = substr($this->getDiretorio(), 0, strpos($this->getDiretorio(), self::DS . self::ROOT));
99
        }
100
101 2
        return $path . self::DS . self::ROOT . self::DS . $this->getName();
102
    }
103
104
    /**
105
     * @return string
106
     */
107 12
    public function getDiretorio(): string
108
    {
109 12
        return $this->diretorio;
110
    }
111
112
    public function mappingExists(): bool
113
    {
114
        return $this->fileExistsInModule('Mapping');
115
    }
116
117
    private function fileExistsInModule(string $fileName): bool
118
    {
119
120
        return file_exists($this->getLocalFile($fileName));
121
    }
122
123
    public function getLocalMapping(): string
124
    {
125
        return $this->getLocalFile('Mapping');
126
    }
127
128
    private function getLocalFile(string $fileName): string
129
    {
130
        return $this->getPathModule() . self::DS . "$fileName.php";
131
    }
132
}