ComposerConfigSetting::resetConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
namespace Samurai\Project\Task;
3
4
use Samurai\Project\Composer\ComposerConfigMerger;
5
use Samurai\Task\ITask;
6
use Samurai\Task\Task;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class ComposerConfigSetting
12
 * @package Samurai\Project\Task
13
 * @author Raphaël Lefebvre <[email protected]>
14
 */
15
class ComposerConfigSetting extends Task
16
{
17
    /**
18
     * @param InputInterface $input
19
     * @param OutputInterface $output
20
     * @return bool
21
     */
22 4
    public function execute(InputInterface $input, OutputInterface $output)
23
    {
24 4
        $output->writeln('<info>Initializing composer config</info>');
25
26 4
        $this->resetConfig();
27
28 4
        $hasError = false;
29 4 View Code Duplication
        if($this->getService('composer')->validateConfig($this->getService('project')->getDirectoryPath())) {
30 1
            $output->writeln('<error>Error: Composer config is not valid</error>');
31 1
            $hasError = true;
32 1
        }
33 4 View Code Duplication
        if($this->getService('composer')->dumpAutoload($this->getService('project')->getDirectoryPath())) {
34 1
            $output->writeln('<error>Error: autoload is not up-to-date. Process to "composer dump-autoload".</error>');
35 1
            $hasError = true;
36 4
        }
37
38 4
        return $hasError ? ITask::NO_ERROR_CODE : ITask::NON_BLOCKING_ERROR_CODE;
39
    }
40
41
    /**
42
     *
43
     */
44 4
    public function resetConfig()
45
    {
46 4
        $merger = new ComposerConfigMerger();
47 4
        $this->getService('composer')->setConfig(
48 4
            $merger->merge($this->retrieveCurrentConfig(), $this->getService('project')->toConfig()),
49 4
            $this->getService('project')->getDirectoryPath()
50 4
        );
51 4
        $this->getService('composer')->flushConfig($this->getService('project')->getDirectoryPath());
52 4
    }
53
54
    /**
55
     * @return array
56
     */
57 4
    public function retrieveCurrentConfig()
58
    {
59 4
        return $this->getService('composer')->getConfig($this->getService('project')->getDirectoryPath());
60
    }
61
}
62