GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#1001)
by Paul
02:48
created

Backup_Utilities::is_exec_available()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 28
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 28
rs 8.439
cc 6
eloc 11
nc 5
nop 0
1
<?php
2
3
namespace HM\BackUpWordPress;
4
5
use Symfony\Component\Process\Process as Process;
6
7
/**
8
 * A set of Backup Utility functions
9
 */
10
class Backup_Utilities {
11
12
	/**
13
	 * Checks whether Safe Mode is currently on
14
	 *
15
	 * @param  string  $ini_get_callback By default we use `ini_get` to check for
16
	 *                                   the Safe Mode setting but this can be
17
	 *                                   overridden for testing purposes.
18
	 *
19
	 * @return boolean                   Whether Safe Mode is on or off.
20
	 */
21
	public static function is_safe_mode_on( $ini_get_callback = 'ini_get' ) {
22
23
		$safe_mode = @call_user_func( $ini_get_callback, 'safe_mode' );
24
25
		if ( $safe_mode && strtolower( $safe_mode ) !== 'off' ) {
1 ignored issue
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $safe_mode && str...($safe_mode) !== 'off';.
Loading history...
26
			return true;
27
		}
28
29
		return false;
30
31
	}
32
33
	/**
34
	 * Attempt to work out path to a cli executable.
35
	 *
36
	 * @param  array $paths An array of paths to check against.
37
	 *
38
	 * @return string|false        The path to the executable.
39
	 */
40
	public static function get_executable_path( $paths ) {
41
42
		if ( ! function_exists( 'proc_open' ) ) {
43
			return false;
44
		}
45
46
		$paths = array_map( 'wp_normalize_path', $paths );
47
48
		foreach ( $paths as $path ) {
49
50
			/**
51
			 * Attempt to call `--version` on each path, the one which works
52
			 * must be the correct path.
53
			 */
54
			 $process = new Process( $path . ' --version' );
55
56
			try {
57
				// If the command executed successfully then this must be the correct path
58
				if ( $process->isSuccessful() ) {
59
					return $path;
60
				}
61
			} catch( \Exception $e ) {
62
				return false;
63
			}
64
65
		}
66
67
		return false;
68
69
	}
70
}
71