Pull request review fixes

This commit is contained in:
Corpsee 2014-05-11 22:38:33 +07:00
parent 2476086f7c
commit f6d1896096
4 changed files with 51 additions and 61 deletions

View file

@ -3,9 +3,8 @@
namespace PHPCI\Helper;
use \PHPCI\Logging\BuildLogger;
use Psr\Log\LogLevel;
class BaseCommandExecutor implements CommandExecutor
abstract class BaseCommandExecutor implements CommandExecutor
{
/**
* @var \PHPCI\Logging\BuildLogger
@ -98,30 +97,5 @@ class BaseCommandExecutor implements CommandExecutor
* @param string $binary
* @return null|string
*/
public function findBinary($binary)
{
$binaryPath = null;
if (is_string($binary)) {
$binary = array($binary);
}
foreach ($binary as $bin) {
$this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG);
// Check project root directory:
if (is_file($this->rootDir . $bin)) {
$this->logger->log("Found in root: " . $bin, LogLevel::DEBUG);
$binaryPath = $this->rootDir . $bin;
break;
}
// Check Composer bin dir:
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
$this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG);
$binaryPath = $this->rootDir . 'vendor/bin/' . $bin;
break;
}
}
return $binaryPath;
}
}
abstract public function findBinary($binary);
}

View file

@ -2,18 +2,8 @@
namespace PHPCI\Helper;
use \PHPCI\Logging\BuildLogger;
interface CommandExecutor
{
/**
* @param BuildLogger $logger
* @param string $rootDir
* @param bool $quiet
* @param bool $verbose
*/
public function __construct(BuildLogger $logger, $rootDir, &$quiet = false, &$verbose = false);
/**
* Executes shell commands. Accepts multiple arguments the first
* is the template and everything else is inserted in. c.f. sprintf

View file

@ -2,6 +2,8 @@
namespace PHPCI\Helper;
use Psr\Log\LogLevel;
class UnixCommandExecutor extends BaseCommandExecutor
{
/**
@ -11,21 +13,32 @@ class UnixCommandExecutor extends BaseCommandExecutor
*/
public function findBinary($binary)
{
$binaryPath = parent::findBinary($binary);
if (is_null($binaryPath)) {
$binaryPath = null;
if (is_string($binary)) {
$binary = array($binary);
if (is_string($binary)) {
$binary = array($binary);
}
foreach ($binary as $bin) {
$this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG);
if (is_file($this->rootDir . $bin)) {
$this->logger->log("Found in root: " . $bin, LogLevel::DEBUG);
$binaryPath = $this->rootDir . $bin;
break;
}
foreach ($binary as $bin) {
$findCmdResult = trim(shell_exec('which ' . $bin));
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
$this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG);
$binaryPath = $this->rootDir . 'vendor/bin/' . $bin;
break;
}
if (!empty($findCmdResult)) {
$this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG);
$binaryPath = $findCmdResult;
break;
}
$findCmdResult = trim(shell_exec('which ' . $bin));
if (!empty($findCmdResult)) {
$this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG);
$binaryPath = $findCmdResult;
break;
}
}
return $binaryPath;

View file

@ -2,6 +2,8 @@
namespace PHPCI\Helper;
use Psr\Log\LogLevel;
class WindowsCommandExecutor extends BaseCommandExecutor
{
/**
@ -11,21 +13,32 @@ class WindowsCommandExecutor extends BaseCommandExecutor
*/
public function findBinary($binary)
{
$binaryPath = parent::findBinary($binary);
if (is_null($binaryPath)) {
$binaryPath = null;
if (is_string($binary)) {
$binary = array($binary);
if (is_string($binary)) {
$binary = array($binary);
}
foreach ($binary as $bin) {
$this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG);
if (is_file($this->rootDir . $bin)) {
$this->logger->log("Found in root: " . $bin, LogLevel::DEBUG);
$binaryPath = $this->rootDir . $bin;
break;
}
foreach ($binary as $bin) {
$findCmdResult = trim(shell_exec('where ' . $bin));
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
$this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG);
$binaryPath = $this->rootDir . 'vendor/bin/' . $bin;
break;
}
if (!empty($findCmdResult)) {
$this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG);
$binaryPath = $findCmdResult;
break;
}
$findCmdResult = trim(shell_exec('where ' . $bin));
if (!empty($findCmdResult)) {
$this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG);
$binaryPath = $findCmdResult;
break;
}
}
return $binaryPath;