Skip to content

Commit

Permalink
Scrutinizer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Fisher committed May 18, 2014
1 parent 5cf9ca1 commit 36907ea
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
11 changes: 10 additions & 1 deletion src/Console/Command/Command.php
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Task\Console\Input\Input;
use Task\Project;

class Command extends BaseCommand
{
Expand All @@ -15,6 +16,10 @@ class Command extends BaseCommand

public function run(InputInterface $input, OutputInterface $output)
{
if (!($input instanceof Input)) {
throw new InvalidArgumentException("Input must be instance of Task\Console\Input\Input");
}

$this->setInput($input);
$this->setOutput($output);
return parent::run($input, $output);
Expand Down Expand Up @@ -56,6 +61,10 @@ public function getProperty($name, $default = null)

public function runTask($name)
{
return $this->getApplication()->runTask($name, $this->getInput(), $this->getOutput());
if (($project = $this->getApplication()) instanceof Project) {
$project->runTask($name, $this->getInput(), $this->getOutput());
} else {
throw new \RuntimeException("Can only run tasks on Task\Project instances");
}
}
}
19 changes: 11 additions & 8 deletions src/Console/Command/GroupCommand.php
Expand Up @@ -5,6 +5,7 @@
use Task\Project;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Task\Console\Command\Command;

class GroupCommand extends Command
{
Expand Down Expand Up @@ -35,14 +36,16 @@ public function getCommands()
$commands = [];
foreach ($this->getTasks() as $taskName) {
$task = $project->get($taskName);
$commands = array_values(array_unique(
array_merge(
$commands,
$project->resolveDependencies($task),
[$task]
),
SORT_REGULAR
));
if ($task instanceof Command) {
$commands = array_values(array_unique(
array_merge(
$commands,
$project->resolveDependencies($task),
[$task]
),
SORT_REGULAR
));
}
}

return $commands;
Expand Down
16 changes: 14 additions & 2 deletions src/Console/Command/ShellCommand.php
Expand Up @@ -22,9 +22,21 @@ public function configure()
$this->setName('shell');
}

public function getShell()
{
if (!$shell = $this->shell) {
if ($app = $this->getApplication()) {
$shell = new Shell($app);
} else {
throw new \RuntimeException("Couldn't find an application");
}
}

return $shell;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$shell = $this->shell ?: new Shell($this->getApplication());
return $shell->run();
return $this->getShell()->run();
}
}
6 changes: 5 additions & 1 deletion src/Injector.php
Expand Up @@ -4,6 +4,8 @@

class Injector
{
protected $container;

public function __construct(\Pimple $container)
{
$this->container = $container;
Expand All @@ -17,7 +19,9 @@ public function __invoke(array $arguments, $bindTo = null)
throw new \InvalidArgumentException("Last element must be callable");
}

$callback = $callback->bindTo($bindTo);
if ($callback instanceof \Closure) {
$callback = $callback->bindTo($bindTo);
}

# Can't do this with array_map because exceptions are swallowed (see
# https://bugs.php.net/bug.php?id=55416).
Expand Down
5 changes: 3 additions & 2 deletions src/Project.php
Expand Up @@ -17,6 +17,7 @@ class Project extends Application
{
protected $container;
protected $dependencies;
protected $injector;

/**
* @param string $name
Expand Down Expand Up @@ -78,6 +79,7 @@ protected function doRunCommand(BaseCommand $command, InputInterface $input, Out
[$command]
);

$exitCode = 0;
foreach ($run as $command) {
$output->writeln("Running {$command->getName()}...");
$exitCode = parent::doRunCommand($command, $input, $output);
Expand Down Expand Up @@ -180,7 +182,6 @@ public function addTask()
break;
default:
throw new \InvalidArgumentException("Unrecognised task signature for $name");
break;
}
}

Expand All @@ -207,7 +208,7 @@ public function getTaskDependencies($taskName)
return array_key_exists($taskName, $this->dependencies) ? $this->dependencies[$taskName] : [];
}

public function resolveDependencies(Command $task, $nested = false)
public function resolveDependencies(BaseCommand $task, $nested = false)
{
$run = [];
$taskName = $task->getName();
Expand Down

0 comments on commit 36907ea

Please sign in to comment.