Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
Git | n/a |
0 / 0 |
n/a |
0 / 0 |
6 | n/a |
0 / 0 |
|||
test | n/a |
0 / 0 |
n/a |
0 / 0 |
3 | |||||
getBin | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
setBin | n/a |
0 / 0 |
n/a |
0 / 0 |
2 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Utils\Git |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Utils\Git; |
16 | |
17 | use phpOMS\System\File\PathException; |
18 | |
19 | /** |
20 | * Gray encoding class |
21 | * |
22 | * @package phpOMS\Utils\Git |
23 | * @license OMS License 2.0 |
24 | * @link https://jingga.app |
25 | * @since 1.0.0 |
26 | * @codeCoverageIgnore |
27 | */ |
28 | class Git |
29 | { |
30 | /** |
31 | * Git path. |
32 | * |
33 | * @var string |
34 | * @since 1.0.0 |
35 | */ |
36 | protected static string $bin = '/usr/bin/git'; |
37 | |
38 | /** |
39 | * Test git. |
40 | * |
41 | * @return bool |
42 | * |
43 | * @since 1.0.0 |
44 | */ |
45 | public static function test() : bool |
46 | { |
47 | $pipes = []; |
48 | $resource = \proc_open(\escapeshellarg(self::getBin()), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); |
49 | |
50 | $stdout = \stream_get_contents($pipes[1]); |
51 | $stderr = \stream_get_contents($pipes[2]); |
52 | |
53 | foreach ($pipes as $pipe) { |
54 | \fclose($pipe); |
55 | } |
56 | |
57 | return $resource !== false && \proc_close($resource) !== 127; |
58 | } |
59 | |
60 | /** |
61 | * Get git binary. |
62 | * |
63 | * @return string |
64 | * |
65 | * @since 1.0.0 |
66 | */ |
67 | public static function getBin() : string |
68 | { |
69 | return self::$bin; |
70 | } |
71 | |
72 | /** |
73 | * Set git binary. |
74 | * |
75 | * @param string $path Git path |
76 | * |
77 | * @return void |
78 | * |
79 | * @throws PathException This exception is thrown if the binary path doesn't exist |
80 | * |
81 | * @since 1.0.0 |
82 | */ |
83 | public static function setBin(string $path) : void |
84 | { |
85 | if (\realpath($path) === false) { |
86 | throw new PathException($path); |
87 | } |
88 | |
89 | self::$bin = \realpath($path); |
90 | } |
91 | } |