Binary::locateBinary()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
/*
3
 * Copyright (C) 2017 by TEQneers GmbH & Co. KG
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
24
/**
25
 * Git Stream Wrapper for PHP
26
 *
27
 * @category   TQ
28
 * @package    TQ_VCS
29
 * @subpackage SVN
30
 * @copyright  Copyright (C) 2018 by TEQneers GmbH & Co. KG
31
 */
32
33
namespace TQ\Svn\Cli;
34
use TQ\Vcs\Cli\Binary as VcsBinary;
35
use TQ\Vcs\Cli\Call;
36
37
/**
38
 * Encapsulates access to th SVN command line binary
39
 *
40
 * @author     Stefan Gehrig <gehrigteqneers.de>
41
 * @category   TQ
42
 * @package    TQ_VCS
43
 * @subpackage SVN
44
 * @copyright  Copyright (C) 2018 by TEQneers GmbH & Co. KG
45
 */
46
class Binary extends VcsBinary
47
{
48
    /**
49
     * Try to find the SVN binary on the system
50
     *
51
     * @return  string
52
     */
53
    public static function locateBinary()
54
    {
55
        if (!self::isWindows()) {
56
            $result = Call::create('which svn')->execute();
57
            return $result->getStdOut();
58
        }
59
        return '';
60
    }
61
62
    /**
63
     * Creates a SVN binary interface
64
     *
65
     * If no path is given the class tries to find the correct
66
     * binary {@see locateBinary()}
67
     *
68
     * @param   string|null $path           The path to the SVN binary or NULL to auto-detect
69
     * @throws  \InvalidArgumentException   If no binary is found
70
     */
71 82
    public function __construct($path = null)
72
    {
73 82
        if (!$path) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $path of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
74
            $path  = self::locateBinary();
75
        }
76 82
        parent::__construct($path);
77 82
    }
78
}
79
80