Skip to content

Commit

Permalink
Fix phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe SEGATORI committed Jan 10, 2021
1 parent b11ba39 commit 89f4024
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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#'
8 changes: 4 additions & 4 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": [
"config:base"
],
"rangeStrategy": "replace"
"extends": [
"config:base",
":preserveSemverRanges"
]
}
5 changes: 4 additions & 1 deletion src/Source/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpSpellcheck\Source;

use PhpSpellcheck\Exception\RuntimeException;
use PhpSpellcheck\Text;

class Directory implements SourceInterface
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion src/Spellchecker/PHPPspell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/LineAndOffset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 89f4024

Please sign in to comment.