Skip to content

Commit

Permalink
Enhancement: Rename (A|a)nalyser to (A|a)nalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark committed Oct 5, 2020
1 parent 23fedaf commit 1cdd173
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 75 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ jobs:
run: ./box compile

- name: "Run phar without cache"
run: bin/doctor-rst.phar analyse dummy/ --no-cache
run: bin/doctor-rst.phar analyze dummy/ --no-cache

- name: "Cache file should not exist"
run: "[ ! -f '.doctor-rst.cache' ]"

- name: "Run phar with cache enabled"
run: bin/doctor-rst.phar analyse dummy/
run: bin/doctor-rst.phar analyze dummy/

- name: "Cache file should exist"
run: "[ -f '.doctor-rst.cache' ]"

- name: "Run phar again with cache enabled to be sure the cache file could be reused"
run: bin/doctor-rst.phar analyse dummy/
run: bin/doctor-rst.phar analyze dummy/

- name: "Run phar with custom cache file output"
run: bin/doctor-rst.phar analyse dummy/ --cache-file=.doctor-rst.cache2
run: bin/doctor-rst.phar analyze dummy/ --cache-file=.doctor-rst.cache2

- name: "Custom cache file should exist"
run: "[ -f '.doctor-rst.cache2' ]"
4 changes: 2 additions & 2 deletions config/cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ services:
autowire: true
autoconfigure: true

App\Analyser\Cache: '@App\Analyser\FileCache'
App\Analyser\FileCache:
App\Analyzer\Cache: '@App\Analyzer\FileCache'
App\Analyzer\FileCache:
$cacheFile: '%cache.file%'
8 changes: 4 additions & 4 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ services:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

App\Analyser\Cache: '@App\Analyser\InMemoryCache'
App\Analyzer\Cache: '@App\Analyzer\InMemoryCache'

App\Analyser\MemoizingAnalyser:
$analyser: '@App\Analyser\RstAnalyser'
App\Analyzer\MemoizingAnalyzer:
$analyzer: '@App\Analyzer\RstAnalyzer'

App\Command\AnalyseCommand:
App\Command\AnalyzeCommand:
public: true
App\Command\RulesCommand:
public: true
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh -l

sh -c "php /usr/bin/doctor-rst analyse $DOCS_DIR $*"
sh -c "php /usr/bin/doctor-rst analyze $DOCS_DIR $*"
6 changes: 3 additions & 3 deletions src/Analyser/Analyser.php → src/Analyzer/Analyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
* file that was distributed with this source code.
*/

namespace App\Analyser;
namespace App\Analyzer;

use App\Rule\Rule;
use App\Value\Violation;
use SplFileInfo;

interface Analyser
interface Analyzer
{
/**
* @param Rule[] $rules
*
* @return Violation[]
*/
public function analyse(SplFileInfo $file, array $rules): array;
public function analyze(SplFileInfo $file, array $rules): array;
}
2 changes: 1 addition & 1 deletion src/Analyser/Cache.php → src/Analyzer/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace App\Analyser;
namespace App\Analyzer;

use SplFileInfo;

Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/FileCache.php → src/Analyzer/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace App\Analyser;
namespace App\Analyzer;

use App\Application;
use App\Value\Violation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace App\Analyser;
namespace App\Analyzer;

use SplFileInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
* file that was distributed with this source code.
*/

namespace App\Analyser;
namespace App\Analyzer;

use SplFileInfo;

final class MemoizingAnalyser implements Analyser
final class MemoizingAnalyzer implements Analyzer
{
private Analyser $analyser;
private Analyzer $analyzer;
private Cache $cache;

public function __construct(Analyser $analyser, Cache $cache)
public function __construct(Analyzer $analyzer, Cache $cache)
{
$this->analyser = $analyser;
$this->analyzer = $analyzer;
$this->cache = $cache;
}

/**
* {@inheritdoc}
*/
public function analyse(SplFileInfo $file, array $rules): array
public function analyze(SplFileInfo $file, array $rules): array
{
if ($this->cache->has($file, $rules)) {
return $this->cache->get($file, $rules);
}

$violations = $this->analyser->analyse($file, $rules);
$violations = $this->analyzer->analyze($file, $rules);
$this->cache->set($file, $rules, $violations);

return $violations;
Expand Down
6 changes: 3 additions & 3 deletions src/Analyser/RstAnalyser.php → src/Analyzer/RstAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
* file that was distributed with this source code.
*/

namespace App\Analyser;
namespace App\Analyzer;

use App\Rule\Rule;
use App\Value\Lines;
use App\Value\Violation;
use SplFileInfo;
use Symfony\Contracts\Service\ResetInterface;

final class RstAnalyser implements Analyser
final class RstAnalyzer implements Analyzer
{
/**
* @param Rule[] $rules
*
* @return Violation[]
*/
public function analyse(SplFileInfo $file, array $rules): array
public function analyze(SplFileInfo $file, array $rules): array
{
$realpath = $file->getRealPath();
if (false === $realpath) {
Expand Down
6 changes: 3 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace App;

use App\Command\AnalyseCommand;
use App\Command\AnalyzeCommand;
use App\Command\RulesCommand;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Application as BaseApplication;
Expand Down Expand Up @@ -41,8 +41,8 @@ public function doRun(InputInterface $input, OutputInterface $output): int
{
$container = $this->buildContainer($input);

/** @var AnalyseCommand $analyseCommand */
$analyseCommand = $container->get(AnalyseCommand::class);
/** @var AnalyzeCommand $analyseCommand */
$analyseCommand = $container->get(AnalyzeCommand::class);

/** @var RulesCommand $rulesCommand */
$rulesCommand = $container->get(RulesCommand::class);
Expand Down
25 changes: 13 additions & 12 deletions src/Command/AnalyseCommand.php → src/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

namespace App\Command;

use App\Analyser\MemoizingAnalyser;
use App\Analyzer\MemoizingAnalyzer;
use App\Formatter\Registry as FormatterRegistry;
use App\Handler\Registry;
use App\Rule\Configurable;
use App\Rule\Rule;
use App\Value\AnalyserResult;
use App\Value\AnalyzerResult;
use App\Value\ExcludedViolationList;
use App\Value\FileResult;
use App\Value\RuleGroup;
Expand All @@ -32,22 +32,22 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Yaml;

class AnalyseCommand extends Command
class AnalyzeCommand extends Command
{
protected static $defaultName = 'analyse';
protected static $defaultName = 'analyze';

private Registry $registry;

/** @var Rule[] */
private array $rules = [];

private MemoizingAnalyser $analyser;
private MemoizingAnalyzer $analyzer;
private FormatterRegistry $formatterRegistry;

public function __construct(Registry $registry, MemoizingAnalyser $analyser, FormatterRegistry $formatterRegistry)
public function __construct(Registry $registry, MemoizingAnalyzer $analyzer, FormatterRegistry $formatterRegistry)
{
$this->registry = $registry;
$this->analyser = $analyser;
$this->analyzer = $analyzer;
$this->formatterRegistry = $formatterRegistry;

parent::__construct();
Expand All @@ -57,6 +57,7 @@ protected function configure(): void
{
$this
->setDescription('Analyse *.rst files')
->setAliases(['analyse'])
->addArgument('dir', InputArgument::OPTIONAL, 'Directory', '.')
->addOption('rule', 'r', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Which rule should be applied?')
->addOption('group', 'g', InputOption::VALUE_REQUIRED, 'Which groups should be used?')
Expand Down Expand Up @@ -143,18 +144,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$file,
new ExcludedViolationList(
$config['whitelist'] ?? [],
$this->analyser->analyse($file, $this->rules)
$this->analyzer->analyze($file, $this->rules)
)
);
}
$analyserResult = new AnalyserResult($fileResults);
$analyzerResult = new AnalyzerResult($fileResults);

$this->analyser->write();
$this->analyzer->write();

$this->formatterRegistry
->get($errorFormat)
->format($io, $analyserResult, $analyseDir, $showValidFiles);
->format($io, $analyzerResult, $analyseDir, $showValidFiles);

return $analyserResult->hasViolations() ? 1 : 0;
return $analyzerResult->hasViolations() ? 1 : 0;
}
}
6 changes: 3 additions & 3 deletions src/Formatter/ConsoleFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace App\Formatter;

use App\Value\AnalyserResult;
use App\Value\AnalyzerResult;
use App\Value\FileResult;
use App\Value\Violation;
use Symfony\Component\Console\Style\OutputStyle;
Expand All @@ -22,12 +22,12 @@ class ConsoleFormatter implements Formatter
{
public function format(
OutputStyle $style,
AnalyserResult $analyserResult,
AnalyzerResult $analyzerResult,
string $analyseDir,
bool $showValidFiles
): void {
$violatedFiles = 0;
foreach ($analyserResult->all() as $fileResult) {
foreach ($analyzerResult->all() as $fileResult) {
if ($fileResult->violationList()->hasViolations()) {
++$violatedFiles;
$this->formatViolationList($style, $analyseDir, $fileResult);
Expand Down
4 changes: 2 additions & 2 deletions src/Formatter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

namespace App\Formatter;

use App\Value\AnalyserResult;
use App\Value\AnalyzerResult;
use Symfony\Component\Console\Style\OutputStyle;

interface Formatter
{
public function format(OutputStyle $style, AnalyserResult $analyserResult, string $analyseDir, bool $showValidFiles): void;
public function format(OutputStyle $style, AnalyzerResult $analyzerResult, string $analyseDir, bool $showValidFiles): void;

public function name(): string;
}
6 changes: 3 additions & 3 deletions src/Formatter/GithubFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

namespace App\Formatter;

use App\Value\AnalyserResult;
use App\Value\AnalyzerResult;
use Symfony\Component\Console\Style\OutputStyle;

class GithubFormatter implements Formatter
{
public function format(OutputStyle $style, AnalyserResult $analyserResult, string $analyseDir, bool $showValidFiles): void
public function format(OutputStyle $style, AnalyzerResult $analyzerResult, string $analyseDir, bool $showValidFiles): void
{
foreach ($analyserResult->all() as $fileResult) {
foreach ($analyzerResult->all() as $fileResult) {
foreach ($fileResult->violationList()->violations() as $violation) {
$style->writeln(sprintf(
'::error file=%s,line=%s::%s',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace App\Value;

final class AnalyserResult
final class AnalyzerResult
{
/** @var FileResult[] */
private array $results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* file that was distributed with this source code.
*/

namespace App\Tests\Analyser;
namespace App\Tests\Analyzer;

use App\Analyser\FileCache;
use App\Analyzer\FileCache;
use App\Application;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
Expand Down
Loading

0 comments on commit 1cdd173

Please sign in to comment.