From d1ae05b006c5f1454c2d7652a8b2962e97a6764c Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Fri, 11 Jul 2014 14:07:27 +0100 Subject: [PATCH] PHPCS Cleanup --- PHPCI/Helper/BaseCommandExecutor.php | 13 +++++---- PHPCI/Helper/Github.php | 2 +- PHPCI/Plugin/PhpCpd.php | 4 +-- PHPCI/Plugin/Xmpp.php | 40 +++++++++++----------------- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/PHPCI/Helper/BaseCommandExecutor.php b/PHPCI/Helper/BaseCommandExecutor.php index 0a586fb4..554d9083 100644 --- a/PHPCI/Helper/BaseCommandExecutor.php +++ b/PHPCI/Helper/BaseCommandExecutor.php @@ -108,9 +108,11 @@ abstract class BaseCommandExecutor implements CommandExecutor /** * Find a binary required by a plugin. * @param string $binary + * @param null $buildPath * @return null|string */ - public function findBinary($binary, $buildPath = null) { + public function findBinary($binary, $buildPath = null) + { $binaryPath = null; $composerBin = $this->getComposerBinDir(realpath($buildPath)); @@ -154,7 +156,7 @@ abstract class BaseCommandExecutor implements CommandExecutor * @param string $binary * @return null|string */ - abstract protected function findGlobalBinary($bin); + abstract protected function findGlobalBinary($binary); /** * Try to load the composer.json file in the building project @@ -162,12 +164,13 @@ abstract class BaseCommandExecutor implements CommandExecutor * @param string $path Current build path * @return string|null */ - public function getComposerBinDir($path) { + public function getComposerBinDir($path) + { if (is_dir($path)) { $composer = $path.'/composer.json'; - if( is_file($composer) ) { + if (is_file($composer)) { $json = json_decode(file_get_contents($composer)); - if( isset($json->config->{"bin-dir"}) ) { + if (isset($json->config->{"bin-dir"})) { return $path.'/'.$json->config->{"bin-dir"}; } } diff --git a/PHPCI/Helper/Github.php b/PHPCI/Helper/Github.php index d9aa976a..015d8d0e 100644 --- a/PHPCI/Helper/Github.php +++ b/PHPCI/Helper/Github.php @@ -32,7 +32,7 @@ class Github * * @return array */ - public function makeRecursiveRequest($url, $params, $results=[]) + public function makeRecursiveRequest($url, $params, $results = array()) { $http = new HttpClient('https://api.github.com'); $res = $http->get($url, $params); diff --git a/PHPCI/Plugin/PhpCpd.php b/PHPCI/Plugin/PhpCpd.php index 0c247d85..39b6e046 100644 --- a/PHPCI/Plugin/PhpCpd.php +++ b/PHPCI/Plugin/PhpCpd.php @@ -90,7 +90,8 @@ class PhpCpd implements \PHPCI\Plugin $tmpfilename = tempnam('/tmp', 'phpcpd'); - $success = $this->phpci->executeCommand($phpcpd . ' --log-pmd="%s" %s "%s"', $tmpfilename, $ignore, $this->path); + $cmd = $phpcpd . ' --log-pmd="%s" %s "%s"'; + $success = $this->phpci->executeCommand($cmd, $tmpfilename, $ignore, $this->path); print $this->phpci->getLastOutput(); @@ -134,4 +135,3 @@ class PhpCpd implements \PHPCI\Plugin return array($warnings, $data); } } - diff --git a/PHPCI/Plugin/Xmpp.php b/PHPCI/Plugin/Xmpp.php index 5de3106b..8614e208 100644 --- a/PHPCI/Plugin/Xmpp.php +++ b/PHPCI/Plugin/Xmpp.php @@ -81,10 +81,10 @@ class XMPP implements \PHPCI\Plugin /* * Set recipients list */ - if(!empty($options['recipients'])) { - if(is_string($options['recipients'])) { + if (!empty($options['recipients'])) { + if (is_string($options['recipients'])) { $this->recipients = array($options['recipients']); - } elseif(is_array($options['recipients'])) { + } elseif (is_array($options['recipients'])) { $this->recipients = $options['recipients']; } } @@ -99,8 +99,7 @@ class XMPP implements \PHPCI\Plugin */ protected function setOptions($options) { - foreach (array('username', 'password', 'alias', 'tls', 'server', 'date_format') - as $key) { + foreach (array('username', 'password', 'alias', 'tls', 'server', 'date_format') as $key) { if (array_key_exists($key, $options)) { $this->{$key} = $options[$key]; } @@ -115,13 +114,13 @@ class XMPP implements \PHPCI\Plugin protected function getConfigFormat() { $conf = $this->username; - if(!empty($this->server)) { + if (!empty($this->server)) { $conf .= ';'.$this->server; } $conf .= ' '.$this->password; - if(!empty($this->alias)) { + if (!empty($this->alias)) { $conf .= ' '.$this->alias; } @@ -134,8 +133,7 @@ class XMPP implements \PHPCI\Plugin public function findConfigFile() { if (file_exists('.sendxmpprc')) { - if( md5(file_get_contents('.sendxmpprc')) !== - md5($this->getConfigFormat())) { + if (md5(file_get_contents('.sendxmpprc')) !== md5($this->getConfigFormat())) { return null; } @@ -167,7 +165,7 @@ class XMPP implements \PHPCI\Plugin /* * Try to build conf file */ - if(is_null($this->findConfigFile())) { + if (is_null($this->findConfigFile())) { file_put_contents('.sendxmpprc', $this->getConfigFormat()); chmod('.sendxmpprc', 0600); } @@ -176,12 +174,12 @@ class XMPP implements \PHPCI\Plugin * Enabled ssl for connection */ $tls = ''; - if($this->tls) { + if ($this->tls) { $tls = ' -t'; } $message_file = uniqid('xmppmessage'); - if($this->buildMessage($message_file) === false) { + if ($this->buildMessage($message_file) === false) { return false; } @@ -191,8 +189,7 @@ class XMPP implements \PHPCI\Plugin $cmd = $sendxmpp . "%s -f .sendxmpprc -m %s %s"; $recipients = implode(' ', $this->recipients); - $success = $this->phpci->executeCommand( - $cmd, $tls, $message_file, $recipients); + $success = $this->phpci->executeCommand($cmd, $tls, $message_file, $recipients); print $this->phpci->getLastOutput(); @@ -205,20 +202,15 @@ class XMPP implements \PHPCI\Plugin } /** - * Build message for notification - * - * @return string + * @param $message_file + * @return int */ protected function buildMessage($message_file) { - $message = ''; - - if($this->build->isSuccessful()) { - $message = "✔ [".$this->build->getProjectTitle()."] Build #". - $this->build->getId()." successful"; + if ($this->build->isSuccessful()) { + $message = "✔ [".$this->build->getProjectTitle()."] Build #" . $this->build->getId()." successful"; } else { - $message = "✘ [".$this->build->getProjectTitle()."] Build #". - $this->build->getId()." failure"; + $message = "✘ [".$this->build->getProjectTitle()."] Build #" . $this->build->getId()." failure"; } $message .= ' ('.strftime($this->date_format).')';