Skip to content

Commit 89f4024

Browse files
author
Philippe SEGATORI
committed
Fix phpstan errors
1 parent b11ba39 commit 89f4024

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
"erusev/parsedown": "^1.7",
3333
"erusev/parsedown-extra": "^0.8",
3434
"phpstan/phpstan": "^0.12",
35-
"phpstan/phpstan-strict-rules": "^0.12.0",
36-
"phpstan/phpstan-webmozart-assert": "^0.12.0",
37-
"phpstan/phpstan-phpunit": "^0.12.0",
35+
"phpstan/phpstan-strict-rules": "^0.12",
36+
"phpstan/phpstan-webmozart-assert": "^0.12",
37+
"phpstan/phpstan-phpunit": "^0.12",
3838
"phpunit/phpunit": "^8.4",
3939
"pixelrobin/php-feather": "^1.0",
4040
"symfony/filesystem": "^4.2 || ^5.0",

phpstan.neon

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ parameters:
1818
-
1919
message: "#no value type specified in iterable type Symfony\\\\Component\\\\Process\\\\Process#"
2020
path: %currentWorkingDirectory%
21+
22+
# It's checked by Assert:count(1)
23+
-
24+
message: "#^Parameter \\#1 \\$language of function Safe\\\\pspell_config_create expects string, string\\|false given\\.$#"
25+
count: 1
26+
path: src/Spellchecker/PHPPspell.php
27+
28+
2129
# Missing strict comparison
2230
- '#^Construct empty\(\) is not allowed. Use more strict comparison.$#'
2331
# - '#^Only booleans are allowed in#'

renovate.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"extends": [
3-
"config:base"
4-
],
5-
"rangeStrategy": "replace"
2+
"extends": [
3+
"config:base",
4+
":preserveSemverRanges"
5+
]
66
}

src/Source/Directory.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpSpellcheck\Source;
66

7+
use PhpSpellcheck\Exception\RuntimeException;
78
use PhpSpellcheck\Text;
89

910
class Directory implements SourceInterface
@@ -57,9 +58,11 @@ private function getContents(): iterable
5758
foreach ($filesInDir as $file) {
5859
if (\is_string($file)) {
5960
$file = new \SplFileInfo($file);
60-
} elseif (\is_array($file)) {
61+
} elseif (\is_array($file) && !empty($file)) {
6162
// When regex pattern is used, an array containing the file path in its first element is returned
6263
$file = new \SplFileInfo(current($file));
64+
} else {
65+
throw new RuntimeException(\Safe\sprintf('Couldn\'t create "%s" object from the given file', \SplFileInfo::class));
6366
}
6467

6568
if (!$file->isDir() && $file->getRealPath() !== false) {

src/Spellchecker/PHPPspell.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function check(
5151
array $languages,
5252
array $context
5353
): iterable {
54-
Assert::count($languages, 1, 'PHPPspell spellchecker doesn\'t support multiple languages check');
54+
Assert::count($languages, 1, 'PHPPspell spellchecker doesn\'t support multi-language check');
5555

5656
$pspellConfig = \Safe\pspell_config_create(current($languages));
5757
\Safe\pspell_config_mode($pspellConfig, $this->mode);
@@ -66,6 +66,11 @@ public function check(
6666
foreach ($words as $key => $word) {
6767
if (!pspell_check($dictionary, $word)) {
6868
$suggestions = pspell_suggest($dictionary, $word);
69+
70+
Assert::isArray(
71+
$suggestions,
72+
\Safe\sprintf('pspell_suggest method failed with dictionary "%s" and word "%s"', $dictionary, $word)
73+
);
6974
yield new Misspelling($word, 0, $lineNumber + 1, $suggestions, $context);
7075
}
7176
}

src/Utils/LineAndOffset.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class LineAndOffset
2121
public static function findFromFirstCharacterOffset(string $text, int $offsetFromFirstCharacter): array
2222
{
2323
// positive offset
24-
Assert::greaterThanEq($offsetFromFirstCharacter, 0, sprintf('Offset must be a positive integer, "%s" given', $offsetFromFirstCharacter));
24+
Assert::greaterThanEq($offsetFromFirstCharacter, 0, \Safe\sprintf('Offset must be a positive integer, "%s" given', $offsetFromFirstCharacter));
2525

2626
$textLength = mb_strlen($text);
2727
if ($textLength < $offsetFromFirstCharacter) {

0 commit comments

Comments
 (0)