Passed
Push — master ( 04efcd...350219 )
by Andrea
17:25
created

getLocalVersionStringDetail()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 6
cp 0.6667
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3.3332
1
<?php
2
3
namespace Fi\PannelloAmministrazioneBundle\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\Finder\Finder;
9
use Symfony\Component\Process\Process;
10
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
11
12
class CheckgitversionCommand extends ContainerAwareCommand
13
{
14
15 6
    protected function configure()
16
    {
17 6
        $this
18 6
                ->setName('pannelloamministrazione:checkgitversion')
19 6
                ->setDescription('Controllo versioni bundles')
20 6
                ->setHelp('Controlla le versioni git dei bundles');
21 6
    }
22
23 1
    protected function execute(InputInterface $input, OutputInterface $output)
24
    {
25 1
        if (self::isWindows()) {
26
            $output->writeln('<info>Non previsto in ambiente windows</info>');
27
28
            return 0;
29
        }
30
31 1
        $composerbundles = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
32 1
        $papath = $this->getContainer()->get('pannelloamministrazione.projectpath');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33 1
        $composerbundlespath =  $papath->getVendorBinPath(). '/../fi';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34 1
        $findercomposerbundle = new Finder();
35 1
        $findercomposerbundle->in($composerbundlespath)->sortByName()->directories()->depth('== 0');
36
37 1
        foreach ($findercomposerbundle as $file) {
38 1
            $fullcomposerbundlepath = $composerbundlespath . DIRECTORY_SEPARATOR . $file->getBasename();
39 1
            $local = $this->getGitVersion($fullcomposerbundlepath, false);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 18 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
40 1
            $remote = $this->getGitVersion($fullcomposerbundlepath, true);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 17 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
41 1
            $style = new OutputFormatterStyle('blue', 'white', array('bold', 'blink'));
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 18 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42 1
            $output->getFormatter()->setStyle('warning', $style);
43 1
            if ($local !== $remote) {
44 1
                $remote = '<warning> * ' . $remote . ' * </warning>';
45 1
            }
46 1
            $output->writeln('<info>' . $file->getBasename() . '</info> ' . $local . ' -> ' . $remote);
47
48 1
            $composerbundles[] = array(
49 1
                'name' => $file->getBasename(),
50 1
                'path' => $fullcomposerbundlepath,
51 1
                'version' => $this->getGitVersion($fullcomposerbundlepath),
52
            );
53 1
        }
54
55 1
        return 0;
56
    }
57
58 1
    private function getGitVersion($path, $remote = false)
59
    {
60 1
        if (self::isWindows()) {
61
            return '';
62
        }
63
64 1
        if ($remote) {
65
            //Remote
66 1
            $cmd = 'cd ' . $path;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
67 1
            $remotetagscmd = "git ls-remote -t | awk '{print $2}' | cut -d '/' -f 3 | cut -d '^' -f 1 | sort --version-sort | tail -1";
68 1
            $remotetag = $cmd . ";" . $remotetagscmd;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ; does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
69 1
            $process = new Process($remotetag);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
70 1
            $process->setTimeout(60 * 100);
71 1
            $process->run();
72 1
            if ($process->isSuccessful()) {
73 1
                $versions = trim($process->getOutput());
74 1
                return $this->getRemoteVersionString($versions);
75
            }
76
            return '?';
77
        } else {
78
            //Local
79 1
            $cmd = 'cd ' . $path;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
80 1
            $process = new Process($cmd . ';git branch | ' . "grep ' * '");
81 1
            $process->setTimeout(60 * 100);
82 1
            $process->run();
83 1
            if ($process->isSuccessful()) {
84 1
                $versions = explode(chr(10), $process->getOutput());
85 1
                return $this->getLocalVersionString($versions);
86
            } else {
87
                //echo $process->getErrorOutput();
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
88
                return '?';
89
            }
90
        }
91
    }
92
93 1
    private function getLocalVersionString($versions)
94
    {
95 1
        foreach ($versions as $line) {
96 1
            if (strpos($line, '* ') !== false) {
97 1
                $version = trim(strtolower(str_replace('* ', '', $line)));
98 1
                return $this->getLocalVersionStringDetail($version);
99
            }
100
        }
101
        return '?';
102
    }
103
104 1
    private function getLocalVersionStringDetail($versions)
105
    {
106 1
        if ($versions == 'master') {
107
            return $versions;
108
        } else {
109 1
            if (preg_match('/\d+(?:\.\d+)+/', $versions, $matches)) {
110
                return $matches[0]; //returning the first match
111
            }
112
        }
113 1
        return '?';
114
    }
115
116 1
    private function getRemoteVersionString($versions)
117
    {
118 1
        if (preg_match('/\d+(?:\.\d+)+/', $versions, $matches)) {
119 1
            return $matches[0]; //returning the first match
120 1
        }
121
        return '?';
122
    }
123
124 1
    public static function isWindows()
125
    {
126 1
        if (PHP_OS == 'WINNT') {
127
            return true;
128
        } else {
129 1
            return false;
130
        }
131
    }
132
}
133