Skip to content

Commit

Permalink
fixes #27
Browse files Browse the repository at this point in the history
  • Loading branch information
jens1o committed Aug 7, 2018
1 parent 26b9c3c commit c0cd04e
Show file tree
Hide file tree
Showing 28 changed files with 137 additions and 108 deletions.
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ language: php
sudo: false

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- nightly

matrix:
include:
- php: 5.5
- php: 7.1
env: COMPOSER_OPTIONS="--prefer-lowest --prefer-stable"
- php: 7.0
env: COMPOSER_REQUIRE="symfony/process:^2.0"
- php: 7.0
env: COMPOSER_REQUIRE="symfony/process:^3.0"

before_script:
- composer self-update
- if [ -n "$COMPOSER_REQUIRE" ]; then composer require --no-update $COMPOSER_REQUIRE; fi
- composer update $COMPOSER_OPTIONS
29 changes: 13 additions & 16 deletions src/Alchemy/BinaryDriver/AbstractBinary.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand Down Expand Up @@ -48,7 +49,7 @@ public function __construct(ProcessBuilderFactoryInterface $factory, LoggerInter
/**
* @inheritDoc
*/
public function listen(ListenerInterface $listener)
public function listen(ListenerInterface $listener) : BinaryInterface
{
$this->listenersManager->register($listener, $this);

Expand All @@ -58,7 +59,7 @@ public function listen(ListenerInterface $listener)
/**
* @inheritDoc
*/
public function unlisten(ListenerInterface $listener)
public function unlisten(ListenerInterface $listener) : BinaryInterface
{
$this->listenersManager->unregister($listener, $this);

Expand All @@ -68,17 +69,15 @@ public function unlisten(ListenerInterface $listener)
/**
* @inheritDoc
*/
public function getConfiguration()
public function getConfiguration() : ConfigurationInterface
{
return $this->configuration;
}

/**
* @inheritDoc
*
* @return BinaryInterface
*/
public function setConfiguration(ConfigurationInterface $configuration)
public function setConfiguration(ConfigurationInterface $configuration) : ConfigurationAwareInterface
{
$this->configuration = $configuration;
$this->applyProcessConfiguration();
Expand All @@ -89,17 +88,17 @@ public function setConfiguration(ConfigurationInterface $configuration)
/**
* @inheritDoc
*/
public function getProcessBuilderFactory()
public function getProcessBuilderFactory() : ProcessBuilderFactoryInterface
{
return $this->factory;
}

/**
* @inheritDoc
*
* @return BinaryInterface
* @return ProcessBuilderFactoryAwareInterface
*/
public function setProcessBuilderFactory(ProcessBuilderFactoryInterface $factory)
public function setProcessBuilderFactory(ProcessBuilderFactoryInterface $factory) : ProcessBuilderFactoryAwareInterface
{
$this->factory = $factory;
$this->applyProcessConfiguration();
Expand All @@ -110,25 +109,23 @@ public function setProcessBuilderFactory(ProcessBuilderFactoryInterface $factory
/**
* @inheritDoc
*/
public function getProcessRunner()
public function getProcessRunner() : ProcessRunnerInterface
{
return $this->processRunner;
}

/**
* @inheritDoc
*/
public function setProcessRunner(ProcessRunnerInterface $runner)
public function setProcessRunner(ProcessRunnerInterface $runner) : void
{
$this->processRunner = $runner;

return $this;
}

/**
* @inheritDoc
*/
public function command($command, $bypassErrors = false, $listeners = null)
public function command($command, bool $bypassErrors = false, $listeners = null) : string
{
if (!is_array($command)) {
$command = (array)$command;
Expand All @@ -140,11 +137,11 @@ public function command($command, $bypassErrors = false, $listeners = null)
/**
* @inheritDoc
*/
public static function load($binaries, LoggerInterface $logger = null, $configuration = [])
public static function load($binaries, ? LoggerInterface $logger = null, $configuration = []) : BinaryInterface
{
$finder = new ExecutableFinder();
$binary = null;
$binaries = is_array($binaries) ? $binaries : array($binaries);
$binaries = is_array($binaries) ? $binaries : (array)$binaries;

foreach ($binaries as $candidate) {
if (file_exists($candidate) && is_executable($candidate)) {
Expand Down
6 changes: 4 additions & 2 deletions src/Alchemy/BinaryDriver/BinaryDriverTestCase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

namespace Alchemy\BinaryDriver;

Expand All @@ -25,10 +26,11 @@ public function createProcessBuilderFactoryMock()
* @param string $commandLine The commandline executed
* @param string $output The process output
* @param string $error The process error output
* @param bool $enableCallback
*
* @return Process
*/
public function createProcessMock($runs = 1, $success = true, $commandLine = null, $output = null, $error = null, $callback = false)
public function createProcessMock(int $runs = 1, bool $success = true, string $commandLine = null, string $output = null, string $error = null, bool $enableCallback = false)
{
$process = $this->getMockBuilder(\Symfony\Component\Process\Process::class)
->disableOriginalConstructor()
Expand All @@ -37,7 +39,7 @@ public function createProcessMock($runs = 1, $success = true, $commandLine = nul
$builder = $process->expects($this->exactly($runs))
->method('run');

if (true === $callback) {
if (true === $enableCallback) {
$builder->with($this->isInstanceOf('Closure'));
}

Expand Down
9 changes: 5 additions & 4 deletions src/Alchemy/BinaryDriver/BinaryInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand Down Expand Up @@ -26,7 +27,7 @@ interface BinaryInterface extends ConfigurationAwareInterface, ProcessBuilderFac
*
* @return BinaryInterface
*/
public function listen(ListenerInterface $listener);
public function listen(ListenerInterface $listener) : self;

/**
* Removes a listener from the binary driver
Expand All @@ -35,7 +36,7 @@ public function listen(ListenerInterface $listener);
*
* @return BinaryInterface
*/
public function unlisten(ListenerInterface $listener);
public function unlisten(ListenerInterface $listener) : self;

/**
* Runs a command against the driver.
Expand All @@ -50,7 +51,7 @@ public function unlisten(ListenerInterface $listener);
*
* @throws ExecutionFailureException in case of process failure.
*/
public function command($command, $bypassErrors = false, $listeners = null);
public function command($command, bool $bypassErrors = false, $listeners = null) : string;

/**
* Loads a binary
Expand All @@ -63,5 +64,5 @@ public function command($command, $bypassErrors = false, $listeners = null);
*
* @return BinaryInterface
*/
public static function load($binaries, LoggerInterface $logger = null, $configuration = []);
public static function load($binaries, LoggerInterface $logger = null, $configuration = []) : BinaryInterface;
}
13 changes: 7 additions & 6 deletions src/Alchemy/BinaryDriver/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand Down Expand Up @@ -31,15 +32,15 @@ public function getIterator()
/**
* @inheritDoc
*/
public function get($key, $default = null)
public function get(string $key, $default = null)
{
return isset($this->data[$key]) ? $this->data[$key] : $default;
}

/**
* @inheritDoc
*/
public function set($key, $value)
public function set(string $key, $value)
{
$this->data[$key] = $value;

Expand All @@ -49,15 +50,15 @@ public function set($key, $value)
/**
* @inheritDoc
*/
public function has($key)
public function has(string $key) : bool
{
return array_key_exists($key, $this->data);
return isset($this->data[$key]) || array_key_exists($key, $this->data);
}

/**
* @inheritDoc
*/
public function remove($key)
public function remove(string $key)
{
$value = $this->get($key);
unset($this->data[$key]);
Expand All @@ -68,7 +69,7 @@ public function remove($key)
/**
* @inheritDoc
*/
public function all()
public function all() : array
{
return $this->data;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Alchemy/BinaryDriver/ConfigurationAwareInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand All @@ -18,12 +19,14 @@ interface ConfigurationAwareInterface
*
* @return ConfigurationInterface
*/
public function getConfiguration();
public function getConfiguration() : ConfigurationInterface;

/**
* Set the configuration
*
* @param ConfigurationInterface $configuration
*
* @return ConfigurationAwareInterface
*/
public function setConfiguration(ConfigurationInterface $configuration);
public function setConfiguration(ConfigurationInterface $configuration) : ConfigurationAwareInterface;
}
13 changes: 7 additions & 6 deletions src/Alchemy/BinaryDriver/ConfigurationInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand All @@ -21,15 +22,15 @@ interface ConfigurationInterface extends \ArrayAccess, \IteratorAggregate
*
* @return mixed
*/
public function get($key, $default = null);
public function get(string $key, $default = null);

/**
* Set a value to configuration
*
* @param string $key The key
* @param mixed $value The value corresponding to the key
*/
public function set($key, $value);
public function set(string $key, $value);

/**
* Tells if Configuration contains `$key`
Expand All @@ -38,7 +39,7 @@ public function set($key, $value);
*
* @return bool
*/
public function has($key);
public function has(string $key) : bool;

/**
* Removes a value given a key
Expand All @@ -47,12 +48,12 @@ public function has($key);
*
* @return mixed The previous value
*/
public function remove($key);
public function remove(string $key);

/**
* Returns all values set in the configuration
*
* @return array
* @return mixed[]
*/
public function all();
public function all() : array;
}
1 change: 1 addition & 0 deletions src/Alchemy/BinaryDriver/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand Down
13 changes: 7 additions & 6 deletions src/Alchemy/BinaryDriver/Listeners/DebugListener.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare (strict_types = 1);

/*
* This file is part of Alchemy\BinaryDriver.
Expand All @@ -21,7 +22,7 @@ class DebugListener extends EventEmitter implements ListenerInterface
private $eventOut;
private $eventErr;

public function __construct($prefixOut = '[OUT] ', $prefixErr = '[ERROR] ', $eventOut = 'debug', $eventErr = 'debug')
public function __construct(string $prefixOut = '[OUT] ', string $prefixErr = '[ERROR] ', string $eventOut = 'debug', string $eventErr = 'debug')
{
$this->prefixOut = $prefixOut;
$this->prefixErr = $prefixErr;
Expand All @@ -32,7 +33,7 @@ public function __construct($prefixOut = '[OUT] ', $prefixErr = '[ERROR] ', $eve
/**
* @inheritDoc
*/
public function handle($type, $data)
public function handle(string $type, string $data) : void
{
if (Process::ERR === $type) {
$this->emitLines($this->eventErr, $this->prefixErr, $data);
Expand All @@ -44,15 +45,15 @@ public function handle($type, $data)
/**
* @inheritDoc
*/
public function forwardedEvents()
public function forwardedEvents() : array
{
return array_unique(array($this->eventErr, $this->eventOut));
return array_unique([$this->eventErr, $this->eventOut]);
}

private function emitLines($event, $prefix, $lines)
private function emitLines(string $event, string $prefix, string $lines)
{
foreach (explode("\n", $lines) as $line) {
$this->emit($event, array($prefix . $line));
$this->emit($event, [$prefix . $line]);
}
}
}
Loading

0 comments on commit c0cd04e

Please sign in to comment.