Skip to content

Commit

Permalink
Tools - fix showing notices and typos
Browse files Browse the repository at this point in the history
phpqa --analyzedDirs src/Tools/,src/Task --tools phpmetrics --output cli
  • Loading branch information
zdenekdrahos committed Sep 30, 2017
1 parent 96ea124 commit 6b3049e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/CodeAnalysisTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/Tools/AnalyzeResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function __construct(Options $o)

/**
* @param \Edge\QA\RunningTool[] $runningTools
* @return type
*/
public function __invoke(array $runningTools)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/Analyzer/PhpCsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function __invoke()
$analyzedDirs = $this->options->getAnalyzedDirs();
$analyzedDir = reset($analyzedDirs);
if (count($analyzedDirs) > 1) {
$this->say("<error>php-cs-fixer analyzes only first directory {$analyzedDir}</error>");
$this->say(
$this->writeln("<error>php-cs-fixer analyzes only first directory {$analyzedDir}</error>");
$this->writeln(
"- <info>multiple dirs are supported if you specify " .
"<comment>php-cs-fixer.config</comment> in <comment>.phpqa.yml</comment></info>"
);
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Analyzer/PhpMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __invoke()
$analyzedDirs = $this->options->getAnalyzedDirs();
$analyzedDir = reset($analyzedDirs);
if (count($analyzedDirs) > 1) {
$this->say("<error>phpmetrics analyzes only first directory {$analyzedDir}</error>");
$this->writeln("<error>phpmetrics analyzes only first directory {$analyzedDir}</error>");
}
$args = array(
$analyzedDir,
Expand Down
12 changes: 10 additions & 2 deletions src/Tools/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 5 additions & 3 deletions src/Tools/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
Expand Down

0 comments on commit 6b3049e

Please # to comment.