Completed
Pull Request — develop (#147)
by
unknown
12:57
created

GitBinary::getVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * GitElephant - An abstraction layer for git written in PHP
4
 * Copyright (C) 2013  Matteo Giachino
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
18
 */
19
20
namespace GitElephant;
21
22
/**
23
 * Git binary
24
 * It contains the reference to the system git binary
25
 *
26
 * @author Matteo Giachino <[email protected]>
27
 */
28
class GitBinary
29
{
30
    /**
31
     * the path to the repository
32
     *
33
     * @var string $path
34
     */
35
    private $path;
36
37
    /**
38
     * @var float
39
     */
40
    private $version;
41
42 105
    /**
43
     * Class constructor
44 105
     *
45
     * @param null $path the physical path to the git binary
46 104
     */
47
    public function __construct(string $path = null)
48 105
    {
49 105
        if (is_null($path)) {
50
            // unix only!
51
            $path = exec('which git');
52
        }
53
        $this->setPath($path);
54
    }
55
56
    /**
57 101
     * path getter
58
     * returns the path of the binary
59 101
     *
60
     * @return mixed
61
     */
62
    public function getPath()
63
    {
64
        return $this->path;
65
    }
66
67 105
    /**
68
     * path setter
69 105
     *
70 105
     * @param string $path the path to the system git binary
71
     */
72
    public function setPath(string $path)
73
    {
74
        $this->path = $path;
75
    }
76
77
    /**
78
     * @return float|string
79
     */
80
    public function getVersion()
81
    {
82
        if (is_null($this->version)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
83
84
            // unix only!
85
            $this->version = exec('git --version | cut -d " " -f 3');
0 ignored issues
show
Documentation Bug introduced by
The property $version was declared of type double, but exec('git --version | cut -d " " -f 3') is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
86
        }
87
88
        return $this->version;
89
    }
90
}
91