Skip to content

Commit

Permalink
[TASK] Remove "checkMissingIterableValueType" option and add missing …
Browse files Browse the repository at this point in the history
…iteration value types
  • Loading branch information
a-r-m-i-n committed Jul 19, 2024
1 parent 653e0e1 commit 0baf93a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 14 deletions.
1 change: 0 additions & 1 deletion .build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ parameters:
excludePaths:
- ../src/Compatibility
- ../src/Compiler.php
checkMissingIterableValueType: false
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
$dir = $input->getOption('dir');
$this->scanner->setRootPath($dir);

/** @var array|null $skip */
/** @var string[]|null $skip */
$skip = $input->getOption('skip');
$this->scanner->setSkippingRules($this->parseSkippingRules($skip));
}
Expand Down
8 changes: 7 additions & 1 deletion src/EditorConfig/Rules/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ abstract class Rule implements RuleInterface
public const TRIM_TRAILING_WHITESPACE = 'trim_trailing_whitespace';

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

/**
* @return string[]
*/
public static function getDefinitions(): array
{
return [
Expand Down Expand Up @@ -48,6 +51,9 @@ public function getFilePath(): string
return $this->filePath;
}

/**
* @return RuleError[]
*/
public function getErrors(): array
{
return $this->errors;
Expand Down
3 changes: 3 additions & 0 deletions src/EditorConfig/Rules/RuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ interface RuleInterface
{
public function isValid(): bool;

/**
* @return RuleError[]
*/
public function getErrors(): array;

public function fixContent(string $content): string;
Expand Down
22 changes: 13 additions & 9 deletions src/EditorConfig/Rules/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
class Validator
{
/**
* @var array|Declaration[]
* @var Declaration[]
*/
private array $editorConfig;

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

/**
* @param array<string, mixed> $editorConfig
* @param string[] $skippingRules
*/
public function createValidatedFileResult(SplFileInfo $file, array $editorConfig, bool $strictMode = false, array $skippingRules = []): FileResult
{
$this->editorConfig = $editorConfig;
Expand Down Expand Up @@ -65,30 +69,30 @@ public function createValidatedFileResult(SplFileInfo $file, array $editorConfig
$rules[] = new IndentionRule($filePath, $file->getContents(), $style, $size, $strictMode);
}

if (isset($editorConfig['trim_trailing_whitespace']) && $editorConfig['trim_trailing_whitespace'] instanceof TrimTrailingWhitespace && $editorConfig['trim_trailing_whitespace']->getValue()) {
if (isset($editorConfig[Rule::TRIM_TRAILING_WHITESPACE]) && $editorConfig[Rule::TRIM_TRAILING_WHITESPACE] instanceof TrimTrailingWhitespace && $editorConfig[Rule::TRIM_TRAILING_WHITESPACE]->getValue()) {
$rules[] = new Line\TrimTrailingWhitespaceRule($filePath, $file->getContents());
}

// File rules
if (isset($editorConfig['charset']) && $editorConfig['charset'] instanceof Charset) {
$rules[] = new CharsetRule($filePath, $file->getContents(), strtolower($editorConfig['charset']->getStringValue()));
if (isset($editorConfig[Rule::CHARSET]) && $editorConfig[Rule::CHARSET] instanceof Charset) {
$rules[] = new CharsetRule($filePath, $file->getContents(), strtolower($editorConfig[Rule::CHARSET]->getStringValue()));
}

$eofRule = null;
if ($this->hasRuleSet(Rule::END_OF_LINE)) {
$rules[] = $eofRule = new EndOfLineRule($filePath, $file->getContents(), $editorConfig['end_of_line']->getStringValue());
$rules[] = $eofRule = new EndOfLineRule($filePath, $file->getContents(), $editorConfig[Rule::END_OF_LINE]->getStringValue());
}

$insertFinalNewLine = null;
if ($this->hasRuleSet(Rule::INSERT_FINAL_NEWLINE) && $insertFinalNewLine = $editorConfig[Rule::INSERT_FINAL_NEWLINE]->getValue()) {
$rules[] = new InsertFinalNewLineRule($filePath, $file->getContents(), $eofRule ? $eofRule->getEndOfLine() : null);
$rules[] = new InsertFinalNewLineRule($filePath, $file->getContents(), $eofRule?->getEndOfLine());
}
if ($this->hasRuleSet(Rule::TRIM_TRAILING_WHITESPACE)) {
$rules[] = new TrimTrailingWhitespaceRule($filePath, $file->getContents(), $insertFinalNewLine ?? false);
}

if ($this->hasRuleSet(Rule::MAX_LINE_LENGTH) && 'off' !== $editorConfig['max_line_length']->getValue()) {
$maxLineLength = (int)$editorConfig['max_line_length']->getValue();
if ($this->hasRuleSet(Rule::MAX_LINE_LENGTH) && 'off' !== $editorConfig[Rule::MAX_LINE_LENGTH]->getValue()) {
$maxLineLength = (int)$editorConfig[Rule::MAX_LINE_LENGTH]->getValue();
if ($maxLineLength > 0) {
$rules[] = new MaxLineLengthRule($filePath, $file->getContents(), $maxLineLength);
}
Expand Down
12 changes: 12 additions & 0 deletions src/EditorConfig/Utility/FinderUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@

class FinderUtility
{
/**
* @var string[]
*/
private static array $currentExcludes = [];

/**
* Creates new Symfony Finder instance based on given config.
*
* @param array<string, mixed> $finderOptions
*/
public static function createByFinderOptions(array $finderOptions, ?string $gitOnly = null): Finder
{
Expand All @@ -25,6 +30,8 @@ public static function createByFinderOptions(array $finderOptions, ?string $gitO

/**
* Using finderOptions array to build Finder instance.
*
* @param array<string, mixed> $finderOptions
*/
protected static function buildFinderByCliArguments(array $finderOptions): Finder
{
Expand Down Expand Up @@ -76,6 +83,8 @@ protected static function buildGitOnlyFinder(string $workingDir, string $gitOnly
/**
* Requires given PHP file (in isolated closure scope) and expect a Symfony Finder instance to be returned.
* Also, the passed $finderOptions will be available in code of required PHP file (scoped and as global variable).
*
* @param array<string, mixed> $finderOptions
*/
public static function loadCustomFinderInstance(
string $finderConfigPath,
Expand Down Expand Up @@ -105,6 +114,9 @@ public static function loadCustomFinderInstance(
return $closure($finderConfigPath);
}

/**
* @return string[]
*/
public static function getCurrentExcludes(): array
{
return self::$currentExcludes;
Expand Down
11 changes: 9 additions & 2 deletions src/EditorConfig/Utility/TimeTrackingUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class TimeTrackingUtility
{
/**
* @var array
* @var array{time: float, message: string}[]
*/
private static $recordedSteps = [];
private static array $recordedSteps = [];

public static function reset(): void
{
Expand All @@ -29,12 +29,19 @@ public static function getDuration(): float
$start = reset(self::$recordedSteps);
$end = end(self::$recordedSteps);

if (!is_array($start) || !is_array($end)) {
return 0.0;
}

$start = $start['time'];
$end = $end['time'];

return round(($end - $start), 3);
}

/**
* @return array<int, string>
*/
public static function getRecordedSteps(): array
{
$output = [];
Expand Down

0 comments on commit 0baf93a

Please sign in to comment.