diff --git a/composer.json b/composer.json index 4b95b66..b69847d 100644 --- a/composer.json +++ b/composer.json @@ -32,9 +32,9 @@ "erusev/parsedown": "^1.7", "erusev/parsedown-extra": "^0.8", "phpstan/phpstan": "^0.12", - "phpstan/phpstan-strict-rules": "^0.12.0", - "phpstan/phpstan-webmozart-assert": "^0.12.0", - "phpstan/phpstan-phpunit": "^0.12.0", + "phpstan/phpstan-strict-rules": "^0.12", + "phpstan/phpstan-webmozart-assert": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", "phpunit/phpunit": "^8.4", "pixelrobin/php-feather": "^1.0", "symfony/filesystem": "^4.2 || ^5.0", diff --git a/phpstan.neon b/phpstan.neon index e94d760..2d17bd4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -18,6 +18,14 @@ parameters: - message: "#no value type specified in iterable type Symfony\\\\Component\\\\Process\\\\Process#" path: %currentWorkingDirectory% + + # It's checked by Assert:count(1) + - + message: "#^Parameter \\#1 \\$language of function Safe\\\\pspell_config_create expects string, string\\|false given\\.$#" + count: 1 + path: src/Spellchecker/PHPPspell.php + + # Missing strict comparison - '#^Construct empty\(\) is not allowed. Use more strict comparison.$#' # - '#^Only booleans are allowed in#' diff --git a/renovate.json b/renovate.json index 878720c..5fcce11 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,6 @@ { - "extends": [ - "config:base" - ], - "rangeStrategy": "replace" + "extends": [ + "config:base", + ":preserveSemverRanges" + ] } diff --git a/src/Source/Directory.php b/src/Source/Directory.php index 03c8ccd..2206e65 100644 --- a/src/Source/Directory.php +++ b/src/Source/Directory.php @@ -4,6 +4,7 @@ namespace PhpSpellcheck\Source; +use PhpSpellcheck\Exception\RuntimeException; use PhpSpellcheck\Text; class Directory implements SourceInterface @@ -57,9 +58,11 @@ private function getContents(): iterable foreach ($filesInDir as $file) { if (\is_string($file)) { $file = new \SplFileInfo($file); - } elseif (\is_array($file)) { + } elseif (\is_array($file) && !empty($file)) { // When regex pattern is used, an array containing the file path in its first element is returned $file = new \SplFileInfo(current($file)); + } else { + throw new RuntimeException(\Safe\sprintf('Couldn\'t create "%s" object from the given file', \SplFileInfo::class)); } if (!$file->isDir() && $file->getRealPath() !== false) { diff --git a/src/Spellchecker/PHPPspell.php b/src/Spellchecker/PHPPspell.php index 84a49cc..53d438f 100644 --- a/src/Spellchecker/PHPPspell.php +++ b/src/Spellchecker/PHPPspell.php @@ -51,7 +51,7 @@ public function check( array $languages, array $context ): iterable { - Assert::count($languages, 1, 'PHPPspell spellchecker doesn\'t support multiple languages check'); + Assert::count($languages, 1, 'PHPPspell spellchecker doesn\'t support multi-language check'); $pspellConfig = \Safe\pspell_config_create(current($languages)); \Safe\pspell_config_mode($pspellConfig, $this->mode); @@ -66,6 +66,11 @@ public function check( foreach ($words as $key => $word) { if (!pspell_check($dictionary, $word)) { $suggestions = pspell_suggest($dictionary, $word); + + Assert::isArray( + $suggestions, + \Safe\sprintf('pspell_suggest method failed with dictionary "%s" and word "%s"', $dictionary, $word) + ); yield new Misspelling($word, 0, $lineNumber + 1, $suggestions, $context); } } diff --git a/src/Utils/LineAndOffset.php b/src/Utils/LineAndOffset.php index 1937407..872d404 100644 --- a/src/Utils/LineAndOffset.php +++ b/src/Utils/LineAndOffset.php @@ -21,7 +21,7 @@ class LineAndOffset public static function findFromFirstCharacterOffset(string $text, int $offsetFromFirstCharacter): array { // positive offset - Assert::greaterThanEq($offsetFromFirstCharacter, 0, sprintf('Offset must be a positive integer, "%s" given', $offsetFromFirstCharacter)); + Assert::greaterThanEq($offsetFromFirstCharacter, 0, \Safe\sprintf('Offset must be a positive integer, "%s" given', $offsetFromFirstCharacter)); $textLength = mb_strlen($text); if ($textLength < $offsetFromFirstCharacter) {