From 940c1841ffe5e9a72744d1a3375ddec07e7defe4 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 11 May 2014 22:38:33 +0700 Subject: [PATCH] Pull request review fixes --- PHPCI/Helper/BaseCommandExecutor.php | 32 +++------------------- PHPCI/Helper/CommandExecutor.php | 10 ------- PHPCI/Helper/UnixCommandExecutor.php | 35 +++++++++++++++++-------- PHPCI/Helper/WindowsCommandExecutor.php | 35 +++++++++++++++++-------- 4 files changed, 51 insertions(+), 61 deletions(-) diff --git a/PHPCI/Helper/BaseCommandExecutor.php b/PHPCI/Helper/BaseCommandExecutor.php index cc4b8ca0..08364606 100644 --- a/PHPCI/Helper/BaseCommandExecutor.php +++ b/PHPCI/Helper/BaseCommandExecutor.php @@ -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); +} \ No newline at end of file diff --git a/PHPCI/Helper/CommandExecutor.php b/PHPCI/Helper/CommandExecutor.php index 3dce9a44..633618bb 100644 --- a/PHPCI/Helper/CommandExecutor.php +++ b/PHPCI/Helper/CommandExecutor.php @@ -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 diff --git a/PHPCI/Helper/UnixCommandExecutor.php b/PHPCI/Helper/UnixCommandExecutor.php index 208ebb33..5ab0fbc0 100644 --- a/PHPCI/Helper/UnixCommandExecutor.php +++ b/PHPCI/Helper/UnixCommandExecutor.php @@ -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; diff --git a/PHPCI/Helper/WindowsCommandExecutor.php b/PHPCI/Helper/WindowsCommandExecutor.php index ad0ce236..83136d2a 100644 --- a/PHPCI/Helper/WindowsCommandExecutor.php +++ b/PHPCI/Helper/WindowsCommandExecutor.php @@ -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;