Completed
Push — utils ( 4b317d )
by Arnaud
02:09
created

Git   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A runGitCommand() 0 19 3
1
<?php
2
/*
3
 * This file is part of the Cecil/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Util;
12
13
use Symfony\Component\Process\Process;
14
15
class Git
0 ignored issues
show
Coding Style introduced by
Git does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
16
{
17
    /**
18
     * Runs a Git command on the repository.
19
     *
20
     * @param string $command The command.
21
     *
22
     * @throws \RuntimeException If the command failed.
23
     *
24
     * @return string The trimmed output from the command.
25
     */
26
    public static function runGitCommand(string $command): string
27
    {
28
        try {
29
            $process = new Process($command, __DIR__);
0 ignored issues
show
Documentation introduced by
$command is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
            if (0 === $process->run()) {
31
                return trim($process->getOutput());
32
            }
33
34
            throw new \RuntimeException(
35
                sprintf(
36
                    'The tag or commit hash could not be retrieved from "%s": %s',
37
                    __DIR__,
38
                    $process->getErrorOutput()
39
                )
40
            );
41
        } catch (\RuntimeException $exception) {
42
            throw new \RuntimeException('Process error');
43
        }
44
    }
45
}
46