Test Failed
Push — master ( 4bd70e...3667db )
by Grupo
04:16
created

Module::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
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 . 'UseCase,';
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
    public function __construct(string $name, string $diretorio)
56
    {
57
        $this->name = ucfirst(strtolower($name));
58
        $this->diretorio = $diretorio;
59
60
        foreach ($this->paths as &$path) {
61
            $path = $this->getDiretorio() . self::DS . self::ROOT . self::DS . $this->getName() . DIRECTORY_SEPARATOR . $path;
62
        }
63
    }
64
65
    /**
66
     * @param string $name
67
     * @param string $diretorio
68
     * @return Module
69
     */
70
    public static function create(string $name, string $diretorio): Module
71
    {
72
        $module = new self($name, $diretorio);
73
        SymfonyEventAdapter::getInstance()->publish(
74
            new \Saci\Console\Infrastructure\Domain\Events\ModuleWasCreated($module)
75
        );
76
77
        return $module;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getName(): string
84
    {
85
        return $this->name;
86
    }
87
88
89
    public function getPaths(): array
90
    {
91
        return $this->paths;
92
    }
93
94
    public function getPathModule()
95
    {
96
        return $this->getDiretorio() . self::DS . self::ROOT . self::DS . $this->getName();
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getDiretorio(): string
103
    {
104
        return $this->diretorio;
105
    }
106
}