| Conditions | 6 |
| Paths | 5 |
| Total Lines | 28 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | $process->run(); |
||
| 56 | |||
| 57 | // If the command executed successfully then this must be the correct path |
||
| 58 | if ( $process->isSuccessful() ) { |
||
| 59 | return $path; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | return false; |
||
| 64 | |||
| 67 |