ElixirMixCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 74
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 24 2
A writeError() 0 4 1
A writeInfo() 0 4 1
A getRootDir() 0 4 1
1
<?php
2
3
namespace Iulyanp\ElixirMixBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
9
use Symfony\Component\Filesystem\Filesystem;
10
11
/**
12
 * Class ElixirMixCommand
13
 *
14
 * @package Iulyanp\ElixirMixCommand\Command
15
 */
16
class ElixirMixCommand extends ContainerAwareCommand
17
{
18
    /**
19
     * Configure.
20
     */
21
    public function configure()
22
    {
23
        $this->setName('mix:init')
24
            ->setDescription('Init the bootstrap package.json and webpack.mix.js files.');
25
    }
26
27
    /**
28
     * @param InputInterface  $input
29
     * @param OutputInterface $output
30
     *
31
     * @return void
32
     */
33
    public function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $this->writeInfo($output, 'Installing laravel mix...');
36
37
        $container = $this->getContainer();
38
        $appDir = $container->getParameter('kernel.root_dir');
39
        $rootDir = $this->getRootDir($appDir);
40
41
        try {
42
            $fs = new Filesystem();
43
44
            $packageContent = realpath(dirname(__FILE__)) . '/../package.json';
45
            $packagePath = sprintf('%s%s', $rootDir, 'package.json');
46
            $fs->copy($packageContent, $packagePath);
47
48
            $webpackMixContent = realpath(dirname(__FILE__)) . '/../webpack.mix.js.dist';
49
            $webpackMixPath = sprintf('%s%s', $rootDir, 'webpack.mix.js');
50
            $fs->copy($webpackMixContent, $webpackMixPath);
51
        } catch (IOExceptionInterface $e) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Filesy...on\IOExceptionInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
52
            $this->writeError($output, $e->getMessage());
53
        }
54
55
        $this->writeInfo($output, "You're all set. Go and build something amazing.");
56
    }
57
58
    /**
59
     * @param OutputInterface $output
60
     * @param string          $error
61
     *
62
     * @return mixed
63
     */
64
    private function writeError(OutputInterface $output, $error)
65
    {
66
        return $output->writeln('<error>' . $error . '</error>');
67
    }
68
69
    /**
70
     * @param OutputInterface $output
71
     * @param string          $message
72
     *
73
     * @return mixed
74
     */
75
    private function writeInfo(OutputInterface $output, $message)
76
    {
77
        return $output->writeln(sprintf('<info>%s</info>', $message));
78
    }
79
80
    /**
81
     * @param $appDir
82
     *
83
     * @return string
84
     */
85
    private function getRootDir($appDir)
86
    {
87
        return sprintf('%s%s%s%s', $appDir, DIRECTORY_SEPARATOR, '..', DIRECTORY_SEPARATOR);
88
    }
89
}
90