for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace N98\Util;
use RuntimeException;
/**
* Class Exec
* @package N98\Util
*/
class Exec
{
* @var string
const REDIRECT_STDERR_TO_STDOUT = ' 2>&1';
* @var int (0-255)
const CODE_CLEAN_EXIT = 0;
* @param string $command
* @param string $commandOutput
$commandOutput
string|null
This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.
@param
It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.
* @param int $returnCode
$returnCode
integer|null
public static function run($command, &$commandOutput = null, &$returnCode = null)
$command = $command . self::REDIRECT_STDERR_TO_STDOUT;
exec($command, $commandOutput, $returnCode);
$commandOutput = self::parseCommandOutput($commandOutput);
if ($returnCode !== self::CODE_CLEAN_EXIT) {
throw new RuntimeException($commandOutput);
}
* Exec class is allowed to run
*
* @return bool
public static function allowed()
return function_exists('exec');
* @param $commandOutput
* @return string
private static function parseCommandOutput($commandOutput)
return implode(PHP_EOL, $commandOutput);
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.