diff --git a/src/CodeAnalysisTasks.php b/src/CodeAnalysisTasks.php
index ee25ad22..d9e4d681 100644
--- a/src/CodeAnalysisTasks.php
+++ b/src/CodeAnalysisTasks.php
@@ -65,7 +65,9 @@ private function loadConfig(array $opts)
{
$config = new Config();
$config->loadUserConfig($opts['config']);
- $this->tools = new Tools($config);
+ $this->tools = new Tools($config, function ($text) {
+ $this->say($text);
+ });
}
private function loadOptions(array $opts)
diff --git a/src/Tools/AnalyzeResults.php b/src/Tools/AnalyzeResults.php
index dfef13db..e3a8f687 100644
--- a/src/Tools/AnalyzeResults.php
+++ b/src/Tools/AnalyzeResults.php
@@ -15,7 +15,6 @@ public function __construct(Options $o)
/**
* @param \Edge\QA\RunningTool[] $runningTools
- * @return type
*/
public function __invoke(array $runningTools)
{
diff --git a/src/Tools/Analyzer/PhpCsFixer.php b/src/Tools/Analyzer/PhpCsFixer.php
index 880d3acb..0e66540e 100644
--- a/src/Tools/Analyzer/PhpCsFixer.php
+++ b/src/Tools/Analyzer/PhpCsFixer.php
@@ -24,8 +24,8 @@ public function __invoke()
$analyzedDirs = $this->options->getAnalyzedDirs();
$analyzedDir = reset($analyzedDirs);
if (count($analyzedDirs) > 1) {
- $this->say("php-cs-fixer analyzes only first directory {$analyzedDir}");
- $this->say(
+ $this->writeln("php-cs-fixer analyzes only first directory {$analyzedDir}");
+ $this->writeln(
"- multiple dirs are supported if you specify " .
"php-cs-fixer.config in .phpqa.yml"
);
diff --git a/src/Tools/Analyzer/PhpMetrics.php b/src/Tools/Analyzer/PhpMetrics.php
index 7ba06f6c..2de46daa 100644
--- a/src/Tools/Analyzer/PhpMetrics.php
+++ b/src/Tools/Analyzer/PhpMetrics.php
@@ -18,7 +18,7 @@ public function __invoke()
$analyzedDirs = $this->options->getAnalyzedDirs();
$analyzedDir = reset($analyzedDirs);
if (count($analyzedDirs) > 1) {
- $this->say("phpmetrics analyzes only first directory {$analyzedDir}");
+ $this->writeln("phpmetrics analyzes only first directory {$analyzedDir}");
}
$args = array(
$analyzedDir,
diff --git a/src/Tools/Tool.php b/src/Tools/Tool.php
index 9a5a5f21..3d5422fa 100644
--- a/src/Tools/Tool.php
+++ b/src/Tools/Tool.php
@@ -14,21 +14,29 @@ abstract class Tool
protected $options;
/** @var RunningTool */
protected $tool;
+ /** @var callable */
+ private $presenter;
- public function __construct(Config $c, Options $o, RunningTool $t)
+ public function __construct(Config $c, Options $o, RunningTool $t, $presenter)
{
$this->config = $c;
$this->options = $o;
$this->tool = $t;
+ $this->presenter = $presenter;
}
abstract public function __invoke();
- public function saveDynamicConfig($config, $fileExtension)
+ protected function saveDynamicConfig($config, $fileExtension)
{
$directory = rtrim($this->options->isSavedToFiles ? $this->options->rawFile('') : getcwd(), '/');
$file = "{$directory}/{$this->tool}-phpqa.{$fileExtension}";
file_put_contents($file, $config);
return \Edge\QA\escapePath($file);
}
+
+ protected function writeln($text)
+ {
+ $this->presenter->__invoke($text);
+ }
}
diff --git a/src/Tools/Tools.php b/src/Tools/Tools.php
index 238afb06..44824ec5 100644
--- a/src/Tools/Tools.php
+++ b/src/Tools/Tools.php
@@ -11,10 +11,12 @@ class Tools
private $config;
private $tools = array();
private $selectedTools;
+ private $presenter;
- public function __construct(Config $c)
+ public function __construct(Config $c, $presenter)
{
$this->config = $c;
+ $this->presenter = $presenter;
$this->loadTools();
}
@@ -50,7 +52,7 @@ function (array $config) {
public function getExecutableTools(Options $o)
{
if (!$this->selectedTools) {
- $this->selectedTools = $o->buildRunningTools($this->tools, $this->config);
+ $this->selectedTools = $o->buildRunningTools($this->tools);
}
return array_filter(
$this->selectedTools,
@@ -65,7 +67,7 @@ public function buildCommand(RunningTool $tool, Options $o)
$binary = $this->tools[(string) $tool]['customBinary'] ?: \Edge\QA\pathToBinary((string) $tool);
$handlerClass = $this->tools[(string) $tool]['handler'];
- $handler = new $handlerClass($this->config, $o, $tool);
+ $handler = new $handlerClass($this->config, $o, $tool, $this->presenter);
$args = $handler($tool);
return array($binary, $args);
diff --git a/tests/OptionsTest.php b/tests/OptionsTest.php
index b5388c7a..b4a83790 100644
--- a/tests/OptionsTest.php
+++ b/tests/OptionsTest.php
@@ -93,8 +93,8 @@ public function testExecute(array $opts, $isParallel)
public function provideExecutionMode()
{
return array(
- 'parallel executaion is default mode' => array(array(), true),
- 'parallel executaion is default mode' => array(array('execution' => 'parallel'), true),
+ 'parallel execution is default mode' => array(array(), true),
+ 'parallel execution' => array(array('execution' => 'parallel'), true),
'dont use parallelism if execution is other word' => array(array('execution' => 'single'), false),
);
}