Skip to content

Commit

Permalink
[TASK] Refactor type hints and method access modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
a-r-m-i-n committed Dec 3, 2023
1 parent fd4c75c commit 9eeb359
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 102 deletions.
31 changes: 13 additions & 18 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,11 @@

class Application extends SingleCommandApplication
{
/**
* @var Scanner
*/
private $scanner;
private Scanner $scanner;

/**
* @var string
*/
private $version;
private string $version;

/**
* @var bool
*/
private $isVerbose = false;
private bool $isVerbose = false;

public function __construct(string $name = 'ec', ?Scanner $scanner = null)
{
Expand Down Expand Up @@ -91,8 +82,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v

/** @var array|null $skip */
$skip = $input->getOption('skip');
$skippingRules = $this->parseSkippingRules($skip);
$this->scanner->setSkippingRules($skippingRules);
$this->scanner->setSkippingRules($this->parseSkippingRules($skip));
}

protected function executing(Input $input, Output $output): int
Expand Down Expand Up @@ -239,7 +229,7 @@ protected function executing(Input $input, Output $output): int
return $returnValue;
}

protected function scan(Finder $finder, int $fileCount, SymfonyStyle $io, bool $strict = false, bool $noProgress = false, bool $compact = false, bool $uncovered = false): int
private function scan(Finder $finder, int $fileCount, SymfonyStyle $io, bool $strict = false, bool $noProgress = false, bool $compact = false, bool $uncovered = false): int
{
$io->writeln('<comment>Starting scan...</comment>');

Expand Down Expand Up @@ -317,7 +307,7 @@ protected function scan(Finder $finder, int $fileCount, SymfonyStyle $io, bool $
return $errorCountTotal > 0 ? 2 : 0;
}

protected function fix(Finder $finder, SymfonyStyle $io, bool $strict = false): int
private function fix(Finder $finder, SymfonyStyle $io, bool $strict = false): int
{
$io->writeln('<comment>Starting to fix issues...</comment>');

Expand Down Expand Up @@ -350,7 +340,7 @@ protected function fix(Finder $finder, SymfonyStyle $io, bool $strict = false):
return false === $hasUnfixableExceptions ? 0 : 1;
}

protected function createProgressBar(SymfonyStyle $io, int $fileCount): ProgressBar
private function createProgressBar(SymfonyStyle $io, int $fileCount): ProgressBar
{
$progressBar = $io->createProgressBar($fileCount);

Expand All @@ -364,7 +354,12 @@ protected function createProgressBar(SymfonyStyle $io, int $fileCount): Progress
return $progressBar;
}

protected function parseSkippingRules(array $skippingRules = null): array
/**
* @param array<int, string>|null $skippingRules Strings in array may contain comma-separated values
*
* @return array|string[]
*/
private function parseSkippingRules(array $skippingRules = null): array
{
if (!$skippingRules) {
return [];
Expand Down
5 changes: 1 addition & 4 deletions src/EditorConfig/Rules/File/CharsetRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

class CharsetRule extends Rule
{
/**
* @var string
*/
private $expectedEncoding;
private string $expectedEncoding;

public function __construct(string $filePath, string $fileContent, string $expectedEncoding)
{
Expand Down
11 changes: 2 additions & 9 deletions src/EditorConfig/Rules/File/EndOfLineRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@

class EndOfLineRule extends Rule
{
/**
* @var string
*/
private $endOfLine;

/**
* @var string
*/
private $expectedEndOfLine;
private string $endOfLine;
private string $expectedEndOfLine;

public function __construct(string $filePath, string $fileContent, string $endOfLine)
{
Expand Down
5 changes: 1 addition & 4 deletions src/EditorConfig/Rules/File/InsertFinalNewLineRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

class InsertFinalNewLineRule extends Rule
{
/**
* @var string
*/
private $newLineFormat;
private string $newLineFormat;

public function __construct(string $filePath, string $fileContent, ?string $newLineFormat = null)
{
Expand Down
5 changes: 1 addition & 4 deletions src/EditorConfig/Rules/File/TrimTrailingWhitespaceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

class TrimTrailingWhitespaceRule extends Rule
{
/**
* @var bool
*/
private $insertFinalNewLine;
private bool $insertFinalNewLine;

public function __construct(string $filePath, string $fileContent, bool $insertFinalNewLine)
{
Expand Down
16 changes: 5 additions & 11 deletions src/EditorConfig/Rules/FileResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@

class FileResult
{
/**
* @var string
*/
private $filePath;
private string $filePath;

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

/**
* @var bool
*/
private $isBinary;
private bool $isBinary;

/**
* @var array
* @var array|UnfixableException[]
*/
private $unfixableExceptions = [];
private array $unfixableExceptions = [];

public function __construct(string $filePath, array $rules, bool $isBinary = false)
{
Expand Down
16 changes: 3 additions & 13 deletions src/EditorConfig/Rules/Line/IndentionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,9 @@

class IndentionRule extends Rule
{
/**
* @var string
*/
private $style;
/**
* @var int|null
*/
private $size;

/**
* @var bool
*/
private $strict;
private string $style;
private ?int $size;
private bool $strict;

public function __construct(string $filePath, string $fileContent, string $style, ?int $size, bool $strict = false)
{
Expand Down
5 changes: 1 addition & 4 deletions src/EditorConfig/Rules/Line/MaxLineLengthRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

class MaxLineLengthRule extends Rule
{
/**
* @var int|null
*/
private $maxLineLength;
private ?int $maxLineLength;

public function __construct(string $filePath, string $fileContent = null, int $maxLineLength = null)
{
Expand Down
7 changes: 2 additions & 5 deletions src/EditorConfig/Rules/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ abstract class Rule implements RuleInterface
public const MAX_LINE_LENGTH = 'max_line_length';
public const TRIM_TRAILING_WHITESPACE = 'trim_trailing_whitespace';

/**
* @var string
*/
protected $filePath;
protected string $filePath;

/**
* @var array|RuleError[]
*/
protected $errors = [];
protected array $errors = [];

public static function getDefinitions(): array
{
Expand Down
12 changes: 3 additions & 9 deletions src/EditorConfig/Rules/RuleError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@

class RuleError
{
/**
* @var string
*/
private $message;

/**
* @var int|null
*/
private $line;
private string $message;

private ?int $line;

public function __construct(string $message, ?int $line = null)
{
Expand Down
10 changes: 5 additions & 5 deletions src/EditorConfig/Rules/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
class Validator
{
/**
* @var array
* @var array|Declaration[]
*/
private $editorConfig;
private array $editorConfig;

/**
* @var array
* @var array|string[]
*/
private $skippingRules;
private array $skippingRules;

public function createValidatedFileResult(SplFileInfo $file, array $editorConfig, bool $strictMode = false, array $skippingRules = []): FileResult
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public function createValidatedFileResult(SplFileInfo $file, array $editorConfig
/**
* @param string $ruleName see \Armin\EditorconfigCli\EditorConfig\Rules\Rule class constants
*/
protected function hasRuleSet(string $ruleName): bool
private function hasRuleSet(string $ruleName): bool
{
return !in_array($ruleName, $this->skippingRules, true)
&& isset($this->editorConfig[$ruleName])
Expand Down
29 changes: 13 additions & 16 deletions src/EditorConfig/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,26 @@

class Scanner
{
/**
* @var string|null
*/
private $rootPath;
private ?string $rootPath;

/**
* @var array
* @var array|string[]
*/
private $skippingRules;
private array $skippingRules;

/**
* @var EditorConfig
*/
private $editorConfig;
private EditorConfig $editorConfig;

/**
* @var Validator
*/
private $validator;
private Validator $validator;

/**
* @var array|string[]
*/
private $skippedBinaryFiles = [];
private array $skippedBinaryFiles = [];

/**
* @var array|SplFileInfo[]
*/
private $unavailableFiles = [];
private array $unavailableFiles = [];

public function __construct(?EditorConfig $editorConfig = null, ?Validator $validator = null, string $rootPath = null, array $skippingRules = [])
{
Expand All @@ -60,11 +51,17 @@ public function setRootPath(?string $rootPath): void
}
}

/**
* @return array|string[]
*/
public function getSkippingRules(): array
{
return $this->skippingRules;
}

/**
* @param array|string[] $skippingRules
*/
public function setSkippingRules(array $skippingRules): void
{
$this->skippingRules = $skippingRules;
Expand Down

0 comments on commit 9eeb359

Please sign in to comment.