Skip to content

Commit

Permalink
Prepare v2.0.0 (#39)
Browse files Browse the repository at this point in the history
* refactor to 7.2, typed params
* fix phpdoc
* cleanup PHPDoc again
* add feature completeness for ansible 2
* remove travis support for older versions
* removce hhvm completely
  • Loading branch information
maschmann authored Dec 15, 2018
1 parent ac70405 commit ce8f56e
Show file tree
Hide file tree
Showing 18 changed files with 751 additions and 274 deletions.
14 changes: 2 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@ env:
matrix:
fast_finish: true
allow_failures:
- php: hhvm
include:
- php: 5.4
- php: 5.5
- php: 5.6
env: PROCESS_VERSION="2.6.x"
- php: 5.6
env: PROCESS_VERSION="2.7.x"
- php: 5.6
env: PROCESS_VERSION="2.8.x"
- php: 7.0
- php: hhvm
- php: 7.2
- php: 7.3

before_script:
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then phpenv config-rm xdebug.ini; fi
- if [ "$PROCESS_VERSION" != "" ]; then composer require symfony/process:${PROCESS_VERSION} --dev --no-update; fi
- if [ "$deps" = "" ]; then composer install; fi
37 changes: 17 additions & 20 deletions Ansible/Ansible.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
use Asm\Ansible\Command\AnsiblePlaybook;
use Asm\Ansible\Command\AnsiblePlaybookInterface;
use Asm\Ansible\Exception\CommandException;
use Symfony\Component\Process\ProcessBuilder;
use Asm\Ansible\Process\ProcessBuilder;
use Asm\Ansible\Process\ProcessBuilderInterface;

/**
* Ansible command factory
Expand Down Expand Up @@ -52,12 +53,11 @@ final class Ansible
* @param string $ansibleBaseDir base directory of ansible project structure
* @param string $playbookCommand path to playbook executable, default ansible-playbook
* @param string $galaxyCommand path to galaxy executable, default ansible-galaxy
* @throws CommandException
*/
public function __construct(
$ansibleBaseDir,
$playbookCommand = '',
$galaxyCommand = ''
string $ansibleBaseDir,
string $playbookCommand = '',
string $galaxyCommand = ''
) {
$this->ansibleBaseDir = $this->checkDir($ansibleBaseDir);
$this->playbookCommand = $this->checkCommand($playbookCommand, 'ansible-playbook');
Expand All @@ -71,7 +71,7 @@ public function __construct(
*
* @return AnsiblePlaybookInterface
*/
public function playbook()
public function playbook(): AnsiblePlaybookInterface
{
return new AnsiblePlaybook(
$this->createProcess($this->playbookCommand)
Expand All @@ -83,7 +83,7 @@ public function playbook()
*
* @return AnsibleGalaxyInterface
*/
public function galaxy()
public function galaxy(): AnsibleGalaxyInterface
{
return new AnsibleGalaxy(
$this->createProcess($this->galaxyCommand)
Expand All @@ -93,28 +93,25 @@ public function galaxy()
/**
* Set process timeout in seconds.
*
* @param integer $timeout
* @return $this
* @param int $timeout
* @return Ansible
*/
public function setTimeout($timeout)
public function setTimeout(int $timeout): Ansible
{
$this->timeout = $timeout;

return $this;
}

/**
* @param string $prefix command to execute
* @return ProcessBuilder
* @param string $prefix base command
* @return ProcessBuilderInterface
*/
private function createProcess($prefix)
private function createProcess(string $prefix): ProcessBuilderInterface
{
$process = new ProcessBuilder();
$process = new ProcessBuilder($prefix, $this->ansibleBaseDir);

return $process
->setPrefix($prefix)
->setWorkingDirectory($this->ansibleBaseDir)
->setTimeout($this->timeout);
return $process->setTimeout($this->timeout);
}

/**
Expand All @@ -123,7 +120,7 @@ private function createProcess($prefix)
* @return string
* @throws CommandException
*/
private function checkCommand($command, $default)
private function checkCommand(string $command, string $default): string
{
// normally ansible is in /usr/local/bin/*
if ('' === $command) {
Expand All @@ -149,7 +146,7 @@ private function checkCommand($command, $default)
* @return string
* @throws CommandException
*/
private function checkDir($dir)
private function checkDir(string $dir): string
{
if (!is_dir($dir)) {
throw new CommandException('Ansible project root ' . $dir . ' not found!');
Expand Down
34 changes: 17 additions & 17 deletions Ansible/Command/AbstractAnsibleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Asm\Ansible\Command;

use Symfony\Component\Process\ProcessBuilder;
use Asm\Ansible\Process\ProcessBuilderInterface;

/**
* Class AbstractAnsibleCommand
Expand All @@ -21,7 +21,7 @@
abstract class AbstractAnsibleCommand
{
/**
* @var ProcessBuilder
* @var ProcessBuilderInterface
*/
protected $processBuilder;

Expand All @@ -41,9 +41,9 @@ abstract class AbstractAnsibleCommand
private $baseOptions;

/**
* @param ProcessBuilder $processBuilder
* @param ProcessBuilderInterface $processBuilder
*/
public function __construct(ProcessBuilder $processBuilder)
public function __construct(ProcessBuilderInterface $processBuilder)
{
$this->processBuilder = $processBuilder;
$this->options = [];
Expand All @@ -55,9 +55,9 @@ public function __construct(ProcessBuilder $processBuilder)
* Get parameter string which will be used to call ansible.
*
* @param bool $asArray
* @return string[]
* @return string|array
*/
protected function prepareArguments($asArray = true)
protected function prepareArguments(bool $asArray = true)
{
$arguments = array_merge(
[$this->getBaseOptions()],
Expand All @@ -78,7 +78,7 @@ protected function prepareArguments($asArray = true)
* @param string $name
* @param string $value
*/
protected function addOption($name, $value)
protected function addOption(string $name, string $value): void
{
$this->options[$name] = $value;
}
Expand All @@ -88,17 +88,17 @@ protected function addOption($name, $value)
*
* @param string $name
*/
protected function addParameter($name)
protected function addParameter(string $name): void
{
$this->parameters[] = $name;
}

/**
* Get all options as array.
*
* @return string
* @return array
*/
protected function getOptions()
protected function getOptions(): array
{
$options = [];

Expand All @@ -112,9 +112,9 @@ protected function getOptions()
/**
* Get all parameters as array.
*
* @return string
* @return array
*/
protected function getParameters()
protected function getParameters(): array
{
return $this->parameters;
}
Expand All @@ -126,7 +126,7 @@ protected function getParameters()
* @param string $baseOption
* @return $this
*/
protected function addBaseoption($baseOption)
protected function addBaseoption(string $baseOption)
{
$this->baseOptions[] = $baseOption;

Expand All @@ -138,7 +138,7 @@ protected function addBaseoption($baseOption)
*
* @return string
*/
protected function getBaseOptions()
protected function getBaseOptions(): string
{
return implode(' ', $this->baseOptions);
}
Expand All @@ -150,7 +150,7 @@ protected function getBaseOptions()
* @param string $glue
* @return string
*/
protected function checkParam($param, $glue = ' ')
protected function checkParam($param, string $glue = ' '): string
{
if (is_array($param)) {
$param = implode($glue, $param);
Expand All @@ -160,7 +160,7 @@ protected function checkParam($param, $glue = ' ')
}

/**
* Creates process with process builder and executes it.
* Creates process with processBuilder builder and executes it.
*
* @param null $callback
* @return int|string
Expand All @@ -173,7 +173,7 @@ protected function runProcess($callback)
)
->getProcess();

// exitcode
// exit code
$result = $process->run($callback);

// text-mode
Expand Down
2 changes: 1 addition & 1 deletion Ansible/Command/AnsibleCommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ public function execute($callback = null);
* @param bool $asArray
* @return string|array
*/
public function getCommandlineArguments($asArray = true);
public function getCommandlineArguments(bool $asArray = true);
}
Loading

0 comments on commit ce8f56e

Please sign in to comment.