Skip to content

Commit

Permalink
Merge pull request #2 from rfussien/analysis-XWlvP5
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
rfussien authored Jun 22, 2017
2 parents ed42adc + 55651b6 commit 75c4168
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 71 deletions.
26 changes: 14 additions & 12 deletions src/Adapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R;
<?php

namespace G2R;

use G2R\Config\ProjectConfig;
use G2R\Config\RundeckConfig;
Expand Down Expand Up @@ -44,7 +46,7 @@ public static function factory(
}

/**
* Eventually attach a Logger
* Eventually attach a Logger.
*
* @param LoggerInterface|null $logger
*/
Expand All @@ -54,7 +56,7 @@ public function __construct(LoggerInterface $logger = null)
}

/**
* Run the adapter
* Run the adapter.
*
* @throws Exception
*/
Expand All @@ -72,7 +74,7 @@ public function run()
!$project['runOnFail']
) {
$this->warning(
"The project config for {$this->getHook()->getProjectName()} " .
"The project config for {$this->getHook()->getProjectName()} ".
"doesn't enable to run the job when the build failed"
);

Expand All @@ -85,7 +87,7 @@ public function run()
}

/**
* Load the rundeck job runner
* Load the rundeck job runner.
*
* @param JobRunner $jobRunner
*/
Expand All @@ -99,7 +101,7 @@ public function attachJobRunner(JobRunner $jobRunner)
}

/**
* Load the projects config
* Load the projects config.
*
* @param ProjectConfig $projectsConfig
*/
Expand Down Expand Up @@ -131,7 +133,7 @@ private function getJobRunner()
}

/**
* Get the hook
* Get the hook.
*
* @return HookResolver
*/
Expand All @@ -140,14 +142,14 @@ private function getHook()
if (!isset($this->hook)) {
$this->hook = HookResolver::load($this->getInput());

$this->debug('Hook handler type: ' . get_class($this->hook));
$this->debug('Hook handler type: '.get_class($this->hook));
}

return $this->hook;
}

/**
* Get the input (php://input by default)
* Get the input (php://input by default).
*
* @return string
*/
Expand All @@ -158,7 +160,7 @@ private function getInput()

$this->input = file_get_contents('php://input');

$this->debug('input content: ' . $this->input);
$this->debug('input content: '.$this->input);
}

return $this->input;
Expand All @@ -175,13 +177,13 @@ public function setInput($input)
}

/**
* Call the logger
* Call the logger.
*
* @param $level
* @param $message
* @param array $context
*/
public function log($level, $message, array $context = array())
public function log($level, $message, array $context = [])
{
if ($this->logger) {
$this->logger->log($level, $message, $context);
Expand Down
4 changes: 3 additions & 1 deletion src/Config/AbstractConfig.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Config;
<?php

namespace G2R\Config;

use G2R\Exception\Exception;
use Noodlehaus\Config;
Expand Down
11 changes: 7 additions & 4 deletions src/Config/ProjectConfig.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Config;
<?php

namespace G2R\Config;

use G2R\Exception\Exception;

Expand Down Expand Up @@ -49,7 +51,7 @@ protected function setProjectDefaults()
}

/**
* Try to find a project and return it
* Try to find a project and return it.
*
* @return array $project
*/
Expand All @@ -76,13 +78,14 @@ function ($config) use ($name, $ref) {
}

/**
* Return a project identified by its short url
* Return a project identified by its short url.
*
* @param $name
* @param string $ref
*
* @return array $project
* @throws Exception
*
* @return array $project
*/
public function getProject($name, $ref = 'master')
{
Expand Down
8 changes: 5 additions & 3 deletions src/Config/RundeckConfig.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php namespace G2R\Config;
<?php

namespace G2R\Config;

class RundeckConfig extends AbstractConfig
{
/**
* The default config values
* The default config values.
*
* @return array
*/
Expand All @@ -18,7 +20,7 @@ protected function getDefaults()
}

/**
* Set the required fields
* Set the required fields.
*
* @return array
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Exception;
<?php

namespace G2R\Exception;

class Exception extends \Exception
{
Expand Down
9 changes: 6 additions & 3 deletions src/Gitlab/Hook/AbstractHook.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Gitlab\Hook;
<?php

namespace G2R\Gitlab\Hook;

abstract class AbstractHook
{
Expand Down Expand Up @@ -39,13 +41,14 @@ public function getProjectName()
}

/**
* Return the project url
* Return the project url.
*
* @return string
*/
abstract public function getUrl();

/**
* Return the Build status (success, failed, running)
* Return the Build status (success, failed, running).
*/
abstract public function getBuildStatus();
}
4 changes: 3 additions & 1 deletion src/Gitlab/Hook/Build.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Gitlab\Hook;
<?php

namespace G2R\Gitlab\Hook;

class Build extends AbstractHook
{
Expand Down
4 changes: 3 additions & 1 deletion src/Gitlab/Hook/Push.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Gitlab\Hook;
<?php

namespace G2R\Gitlab\Hook;

class Push extends AbstractHook
{
Expand Down
4 changes: 3 additions & 1 deletion src/Gitlab/Hook/Tag.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Gitlab\Hook;
<?php

namespace G2R\Gitlab\Hook;

class Tag extends AbstractHook
{
Expand Down
9 changes: 6 additions & 3 deletions src/Gitlab/HookResolver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Gitlab;
<?php

namespace G2R\Gitlab;

use G2R\Exception\Exception;
use G2R\Gitlab\Hook\Build;
Expand All @@ -8,7 +10,7 @@
class HookResolver
{
/**
* Load a gitlab or gitlab CI webhook handler
* Load a gitlab or gitlab CI webhook handler.
*
* @param string $hookContent
*
Expand All @@ -30,9 +32,10 @@ public static function load($hookContent)
}

/**
* Check if the hook content has a valid object kind
* Check if the hook content has a valid object kind.
*
* @param string $hookContent
*
* @return string $hookContent
*/
private static function objectValidation($hookContent)
Expand Down
27 changes: 15 additions & 12 deletions src/Rundeck/JobRunner.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace G2R\Rundeck;
<?php

namespace G2R\Rundeck;

use G2R\Config\RundeckConfig;
use G2R\Exception\Exception;
Expand All @@ -13,7 +15,7 @@ public function __construct(RundeckConfig $config)
}

/**
* return the Rundeck configuration
* return the Rundeck configuration.
*
* @return RundeckConfig
*/
Expand All @@ -23,7 +25,7 @@ public function getConfig()
}

/**
* Send the request to rundesk
* Send the request to rundesk.
*
* @param $jobId
* @param array $parameters
Expand All @@ -35,13 +37,13 @@ public function run($jobId, array $parameters = [])
$options = [
'http' => [
'header' => "X-Rundeck-Auth-Token: {$this->config['token']}\r\n",
'method' => $method
]
'method' => $method,
],
];

if ($method == 'POST') {
$options ['http']['header'] .= "Content-type: application/x-www-form-urlencoded\r\n";
$options ['http']['content'] = http_build_query($parameters);
$options['http']['header'] .= "Content-type: application/x-www-form-urlencoded\r\n";
$options['http']['content'] = http_build_query($parameters);
}

$context = stream_context_create($options);
Expand All @@ -50,7 +52,7 @@ public function run($jobId, array $parameters = [])
}

/**
* Return the formatted url for a GET or POST rundeck request to run a job
* Return the formatted url for a GET or POST rundeck request to run a job.
*
* http://rundeck.org/docs/api/index.html#running-a-job
* GET /api/1/job/[ID]/run
Expand All @@ -59,15 +61,16 @@ public function run($jobId, array $parameters = [])
* @param $jobId
* @param string $method
*
* @return string
* @throws Exception
*
* @return string
*/
public function getApiUrl($jobId, $method = 'GET')
{
return
"http" . (($this->config['ssl']) ? 's' : '') . "://" .
$this->config['host'] . ':' . $this->config['port'] . '/api/' .
$this->config['api_version'] . '/job/' . $jobId . '/' .
'http'.(($this->config['ssl']) ? 's' : '').'://'.
$this->config['host'].':'.$this->config['port'].'/api/'.
$this->config['api_version'].'/job/'.$jobId.'/'.
((strcasecmp($method, 'get') == 0) ? 'run' : 'executions');
}
}
18 changes: 9 additions & 9 deletions tests/G2R/AdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace G2R;
<?php

use G2R\Rundeck\JobRunner;
namespace G2R;

class AdapterTest extends TestCase
{
Expand Down Expand Up @@ -190,7 +190,7 @@ private function mockRundeckConfig()
->disableOriginalConstructor()
->setMethods([
'getApiUrl',
'getFilename'
'getFilename',
])
->getMock();

Expand All @@ -206,7 +206,7 @@ private function mockJobRunner($rundeckConfig)
->disableOriginalConstructor()
->setMethods([
'getConfig',
'run'
'run',
])
->getMock();

Expand All @@ -222,7 +222,7 @@ private function mockProjectsConfig()
->disableOriginalConstructor()
->setMethods([
'getProject',
'getFilename'
'getFilename',
])
->getMock();

Expand All @@ -237,10 +237,10 @@ private function getProjectThatRunOnFail()
'ref' => 'master',
'runOnFail' => true,
'runOnTagOnly' => true,
'jobArgs' => array(
'jobArgs' => [
'arg1' => 'foo',
'arg2' => 'bar',
),
],
'runJobAs' => 'foo',
];
}
Expand All @@ -253,10 +253,10 @@ private function getProjectThatDoesNotRunOnFail()
'ref' => 'master',
'runOnFail' => false,
'runOnTagOnly' => true,
'jobArgs' => array(
'jobArgs' => [
'arg1' => 'foo',
'arg2' => 'bar',
),
],
'runJobAs' => 'foo',
];
}
Expand Down
Loading

0 comments on commit 75c4168

Please sign in to comment.