Test Failed
Pull Request — master (#9)
by Yo
02:08
created

InitRepositoryProcessor   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 19
lcom 1
cbo 4
dl 0
loc 113
ccs 0
cts 75
cp 0
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
C process() 0 42 11
A displayTemplate() 0 5 1
B processOrNot() 0 24 6
1
<?php
2
namespace Yoanm\DefaultPhpRepository\Processor;
3
4
use Symfony\Component\Console\Question\ConfirmationQuestion;
5
use Yoanm\DefaultPhpRepository\Helper\CommandHelper;
6
use Yoanm\DefaultPhpRepository\Model\FolderTemplate;
7
use Yoanm\DefaultPhpRepository\Model\Template;
8
9
/**
10
 * Class InitRepositoryProcessor
11
 */
12
class InitRepositoryProcessor
13
{
14
    /** @var CommandHelper */
15
    private $helper;
16
    /** @var bool */
17
    private $skipExisting;
18
    /** @var bool */
19
    private $forceOverride;
20
    /** @var array */
21
    private $idList = [];
22
23
    /**
24
     * @param CommandHelper $helper
25
     * @param bool          $skipExisting
26
     * @param bool          $forceOverride
27
     * @param array         $idList
28
     */
29
    public function __construct(
30
        CommandHelper $helper,
31
        $skipExisting = true,
32
        $forceOverride = false,
33
        $idList = []
34
    ) {
35
        $this->helper = $helper;
36
37
        $this->skipExisting = $skipExisting;
38
        $this->forceOverride = $forceOverride;
39
        $this->idList = $idList;
40
    }
41
42
    public function process()
43
    {
44
        $currentType = null;
45
        foreach ($this->helper->getTemplateList() as $template) {
46
            if (count($this->idList) && !in_array($template->getId(), $this->idList)) {
47
                continue;
48
            }
49
            $this->helper->displayHeader($template, $currentType);
50
51
            $currentType = $this->helper->resolveCurrentType($template);
52
53
            $this->displayTemplate($template);
54
55
            if ($template instanceof FolderTemplate) {
56
57
                $targetExist = false;
58
                $process = false;
59
60
                foreach ($template->getFileList() as $subTemplate) {
61
                    $targetExist = $this->helper->targetExist($subTemplate);
62
                    $process = $this->processOrNot($targetExist);
63
                    if (false === $process) {
64
                        break;
65
                    }
66
                }
67
68
                if (true === $process) {
69
                    foreach ($template->getFileList() as $subTemplate) {
70
                        $this->helper->dump($subTemplate);
71
                    }
72
                }
73
            } else {
74
                $targetExist = $this->helper->targetExist($template);
75
                if (true === $this->processOrNot($targetExist)) {
76
                    $this->helper->dump($template);
77
                }
78
            }
79
            if (false === $targetExist) {
80
                $this->helper->display('<info>Done</info>');
81
            }
82
        }
83
    }
84
85
    /**
86
     * @param Template $template
87
     */
88
    protected function displayTemplate(Template $template)
89
    {
90
        $this->helper->display(sprintf('<comment>%s</comment>', $template->getId()), 2, false);
91
        $this->helper->display(sprintf(' - <info>./%s</info> : ', $template->getTarget()), 0, false);
92
    }
93
94
    /**
95
     * @param Template $template
0 ignored issues
show
Bug introduced by
There is no parameter named $template. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
96
     * @param bool     $targetExist
97
     *
98
     * @return bool
99
     */
100
    protected function processOrNot($targetExist)
101
    {
102
        $process = true;
103
        if ($targetExist) {
104
            if (false === $this->forceOverride && true === $this->skipExisting) {
105
                $this->helper->display('<comment>Skipped !</comment>');
106
                $process = false;
107
            } else {
108
                $process = false;
109
                if (true === $this->forceOverride) {
110
                    $process = true;
111
                    $this->helper->display('<comment>Overriden !</comment>');
112
                } elseif (
113
                    $this->helper->ask(
114
                        new ConfirmationQuestion('<question>Overwrite ? [n]</question>', false)
115
                    )
116
                ) {
117
                    $process = true;
118
                }
119
            }
120
        }
121
122
        return $process;
123
    }
124
}
125