Skip to content

Commit

Permalink
Add final or abstract keyword when missing
Browse files Browse the repository at this point in the history
  • Loading branch information
villfa authored Mar 31, 2022
1 parent bcb124c commit 6c908c1
Show file tree
Hide file tree
Showing 53 changed files with 332 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
- name: "Run Infection"
run: |
git fetch --depth=1 origin $GITHUB_BASE_REF
infection -j$(nproc) --logger-github --git-diff-filter=AM --git-diff-base=origin/$GITHUB_BASE_REF --ignore-msi-with-no-mutations --min-msi=85 --min-covered-msi=95
infection -j$(nproc) --logger-github --git-diff-filter=AM --git-diff-base=origin/$GITHUB_BASE_REF --ignore-msi-with-no-mutations --min-msi=76 --min-covered-msi=82
18 changes: 18 additions & 0 deletions src/Assessor/Assessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Churn\Assessor;

/**
* @internal
*/
interface Assessor
{
/**
* Assess a PHP file.
*
* @param string $contents The contents of a PHP file.
*/
public function assess(string $contents): int;
}
2 changes: 1 addition & 1 deletion src/Assessor/CyclomaticComplexityAssessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @internal
*/
class CyclomaticComplexityAssessor
final class CyclomaticComplexityAssessor implements Assessor
{
/**
* @var array<int, int>
Expand Down
9 changes: 5 additions & 4 deletions src/Command/AssessComplexityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Churn\Command;

use Churn\Assessor\Assessor;
use Churn\Assessor\CyclomaticComplexityAssessor;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -13,19 +14,19 @@
/**
* @internal
*/
class AssessComplexityCommand extends Command
final class AssessComplexityCommand extends Command
{
/**
* @var CyclomaticComplexityAssessor
* @var Assessor
*/
private $assessor;

/**
* Class constructor.
*
* @param CyclomaticComplexityAssessor $assessor The class calculating the complexity.
* @param Assessor $assessor The class calculating the complexity.
*/
public function __construct(CyclomaticComplexityAssessor $assessor)
public function __construct(Assessor $assessor)
{
parent::__construct();

Expand Down
8 changes: 4 additions & 4 deletions src/Command/Helper/MaxScoreChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Churn\Command\Helper;

use Churn\Result\ResultAccumulator;
use Churn\Result\ResultReporter;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
class MaxScoreChecker
final class MaxScoreChecker
{
/**
* @var float|null
Expand All @@ -30,9 +30,9 @@ public function __construct(?float $maxScoreThreshold)
/**
* @param InputInterface $input Input.
* @param OutputInterface $output Output.
* @param ResultAccumulator $report The report containing the scores.
* @param ResultReporter $report The report containing the scores.
*/
public function isOverThreshold(InputInterface $input, OutputInterface $output, ResultAccumulator $report): bool
public function isOverThreshold(InputInterface $input, OutputInterface $output, ResultReporter $report): bool
{
$maxScore = $report->getMaxScore();

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Helper/ProgressBarSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @internal
*/
class ProgressBarSubscriber implements AfterAnalysis, AfterFileAnalysis, BeforeAnalysis
final class ProgressBarSubscriber implements AfterAnalysis, AfterFileAnalysis, BeforeAnalysis
{
/**
* @var ProgressBar
Expand Down
5 changes: 3 additions & 2 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Churn\Configuration\Config;
use Churn\Configuration\Loader;
use Churn\Event\Broker;
use Churn\Event\BrokerImpl;
use Churn\Event\Event\AfterAnalysisEvent;
use Churn\Event\Event\BeforeAnalysisEvent;
use Churn\Event\HookLoader;
Expand All @@ -35,7 +36,7 @@
* @internal
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class RunCommand extends Command
final class RunCommand extends Command
{
public const LOGO = "
___ _ _ __ __ ____ _ _ ____ _ _ ____
Expand Down Expand Up @@ -110,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$this->printLogo($input, $output);
$config = $this->getConfiguration($input, $output);
$broker = new Broker();
$broker = new BrokerImpl();
(new HookLoader($config->getDirPath()))->attachHooks($config->getHooks(), $broker);
if (true === $input->getOption('progress')) {
$broker->subscribe(new ProgressBarSubscriber($output));
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @internal
*/
class Config
abstract class Config
{
/**
* @var array<string>
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @internal
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Loader
final class Loader
{
/**
* @param string $confPath Path of the configuration file to load.
Expand All @@ -43,7 +43,7 @@ public static function fromPath(string $confPath, bool $isDefaultValue): Config
}

if ($isDefaultValue) {
return new Config();
return new ReadOnlyConfig();
}

throw new InvalidArgumentException('The configuration file can not be read at ' . $originalConfPath);
Expand Down
12 changes: 12 additions & 0 deletions src/Configuration/ReadOnlyConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Churn\Configuration;

/**
* @internal
*/
final class ReadOnlyConfig extends Config
{
}
62 changes: 3 additions & 59 deletions src/Event/Broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,18 @@

namespace Churn\Event;

use Churn\Event\Channel\AfterAnalysisChannel;
use Churn\Event\Channel\AfterFileAnalysisChannel;
use Churn\Event\Channel\BeforeAnalysisChannel;

/**
* @internal
*/
class Broker
interface Broker
{
/**
* @var array<string, array<callable>>
* @psalm-var array<class-string, array<callable>>
*/
private $subscribers = [];

/**
* @var array<\Churn\Event\Channel>
*/
private $channels;

/**
* Class constructor.
*/
public function __construct()
{
$this->channels = [
new AfterAnalysisChannel(),
new AfterFileAnalysisChannel(),
new BeforeAnalysisChannel(),
];
}

/**
* @param object $subscriber A subscriber object.
*/
public function subscribe($subscriber): void
{
foreach ($this->channels as $channel) {
if (!$channel->accepts($subscriber)) {
continue;
}

$this->subscribers[$channel->getEventClassname()][] = $channel->buildEventHandler($subscriber);
}
}

/**
* @param Event $event The triggered event.
*/
public function notify(Event $event): void
{
foreach ($this->subscribers as $eventClass => $subscribers) {
if (!$event instanceof $eventClass) {
continue;
}

$this->notifyAll($event, $subscribers);
}
}
public function subscribe($subscriber): void;

/**
* @param Event $event The triggered event.
* @param array<callable> $subscribers The subscribers to notify.
*/
private function notifyAll(Event $event, array $subscribers): void
{
foreach ($subscribers as $subscriber) {
$subscriber($event);
}
}
public function notify(Event $event): void;
}
77 changes: 77 additions & 0 deletions src/Event/BrokerImpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace Churn\Event;

use Churn\Event\Channel\AfterAnalysisChannel;
use Churn\Event\Channel\AfterFileAnalysisChannel;
use Churn\Event\Channel\BeforeAnalysisChannel;

/**
* @internal
*/
final class BrokerImpl implements Broker
{
/**
* @var array<string, array<callable>>
* @psalm-var array<class-string, array<callable>>
*/
private $subscribers = [];

/**
* @var array<\Churn\Event\Channel>
*/
private $channels;

/**
* Class constructor.
*/
public function __construct()
{
$this->channels = [
new AfterAnalysisChannel(),
new AfterFileAnalysisChannel(),
new BeforeAnalysisChannel(),
];
}

/**
* @param object $subscriber A subscriber object.
*/
public function subscribe($subscriber): void
{
foreach ($this->channels as $channel) {
if (!$channel->accepts($subscriber)) {
continue;
}

$this->subscribers[$channel->getEventClassname()][] = $channel->buildEventHandler($subscriber);
}
}

/**
* @param Event $event The triggered event.
*/
public function notify(Event $event): void
{
foreach ($this->subscribers as $eventClass => $subscribers) {
if (!$event instanceof $eventClass) {
continue;
}

$this->notifyAll($event, $subscribers);
}
}

/**
* @param Event $event The triggered event.
* @param array<callable> $subscribers The subscribers to notify.
*/
private function notifyAll(Event $event, array $subscribers): void
{
foreach ($subscribers as $subscriber) {
$subscriber($event);
}
}
}
20 changes: 10 additions & 10 deletions src/Event/Event/AfterAnalysisEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,55 @@

namespace Churn\Event\Event;

use Churn\Result\ResultAccumulator;
use Churn\Result\ResultReporter;

/**
* @internal
*/
final class AfterAnalysisEvent implements AfterAnalysis
{
/**
* @var ResultAccumulator
* @var ResultReporter
*/
private $resultAccumulator;
private $resultReporter;

/**
* @param ResultAccumulator $resultAccumulator The results report.
* @param ResultReporter $resultReporter The results report.
*/
public function __construct(ResultAccumulator $resultAccumulator)
public function __construct(ResultReporter $resultReporter)
{
$this->resultAccumulator = $resultAccumulator;
$this->resultReporter = $resultReporter;
}

/**
* Returns the total number of files analysed.
*/
public function getNumberOfFiles(): int
{
return $this->resultAccumulator->getNumberOfFiles();
return $this->resultReporter->getNumberOfFiles();
}

/**
* Returns the max number of changes among the analysed files.
*/
public function getMaxNumberOfChanges(): int
{
return $this->resultAccumulator->getMaxCommits();
return $this->resultReporter->getMaxCommits();
}

/**
* Returns the max cyclomatic complexity among the analysed files.
*/
public function getMaxCyclomaticComplexity(): int
{
return $this->resultAccumulator->getMaxComplexity();
return $this->resultReporter->getMaxComplexity();
}

/**
* Returns the highest score among the analysed files.
*/
public function getMaxScore(): ?float
{
return $this->resultAccumulator->getMaxScore();
return $this->resultReporter->getMaxScore();
}
}
Loading

0 comments on commit 6c908c1

Please sign in to comment.