Skip to content

Commit 9a12372

Browse files
authored
Psalm improvements (#50)
1 parent f5cfc87 commit 9a12372

File tree

7 files changed

+23
-3
lines changed

7 files changed

+23
-3
lines changed

psalm.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="6"
4-
resolveFromConfigFile="true"
3+
errorLevel="1"
54
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
65
xmlns="https://getpsalm.org/schema/config"
76
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

src/Inflector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ final class Inflector
5353

5454
/**
5555
* @var string[] The rules for converting a word into its plural form.
56+
* @psalm-var array<string,string>
5657
* The keys are the regular expressions and the values are the corresponding replacements.
5758
*/
5859
private array $pluralizeRules = [
@@ -91,6 +92,7 @@ final class Inflector
9192

9293
/**
9394
* @var string[] The rules for converting a word into its singular form.
95+
* @psalm-var array<string, string>
9496
* The keys are the regular expressions and the values are the corresponding replacements.
9597
*/
9698
private array $singularizeRules = [
@@ -138,6 +140,7 @@ final class Inflector
138140
];
139141

140142
/**
143+
* @psalm-var array<string, string>
141144
* @var string[] The special rules for converting a word between its plural form and singular form.
142145
* The keys are the special words in singular form, and the values are the corresponding plural form.
143146
*/
@@ -285,6 +288,7 @@ final class Inflector
285288

286289
/**
287290
* @param string[] $rules The rules for converting a word into its plural form.
291+
* @psalm-param array<string, string> $rules
288292
* The keys are the regular expressions and the values are the corresponding replacements.
289293
* @return self
290294
*/
@@ -307,6 +311,7 @@ public function getPluralizeRules(): array
307311
/**
308312
* @param string[] $rules The rules for converting a word into its singular form.
309313
* The keys are the regular expressions and the values are the corresponding replacements.
314+
* @psalm-param array<string, string> $rules
310315
* @return self
311316
*/
312317
public function withSingularizeRules(array $rules): self
@@ -327,6 +332,7 @@ public function getSingularizeRules(): array
327332

328333
/**
329334
* @param string[] $rules The special rules for converting a word between its plural form and singular form.
335+
* @psalm-param array<string, string> $rules
330336
* The keys are the special words in singular form, and the values are the corresponding plural form.
331337
* @return self
332338
*/
@@ -351,7 +357,7 @@ public function getSpecialRules(): array
351357
* a {@see \Transliterator} can be built for transliteration. Used by {@see toTransliterated()} when intl is available.
352358
* Defaults to {@see TRANSLITERATE_LOOSE}.
353359
* @return self
354-
*@see https://secure.php.net/manual/en/transliterator.transliterate.php
360+
* @see https://secure.php.net/manual/en/transliterator.transliterate.php
355361
*/
356362
public function withTransliterator($transliterator): self
357363
{

src/NumericHelper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public static function toOrdinal($value): string
4747
*/
4848
public static function normalize($value): string
4949
{
50+
/**
51+
* @psalm-suppress DocblockTypeContradiction
52+
*/
5053
if (!is_scalar($value)) {
5154
$type = gettype($value);
5255
throw new \InvalidArgumentException("Value must be scalar. $type given.");

src/StringHelper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ public static function startsWithIgnoringCase(string $input, ?string $with): boo
184184
return true;
185185
}
186186

187+
/**
188+
* @psalm-suppress PossiblyNullArgument
189+
*/
187190
return static::lowercase(static::substring($input, 0, $bytes, '8bit')) === static::lowercase($with);
188191
}
189192

@@ -233,6 +236,9 @@ public static function endsWithIgnoringCase(string $input, ?string $with): bool
233236
return true;
234237
}
235238

239+
/**
240+
* @psalm-suppress PossiblyNullArgument
241+
*/
236242
return static::lowercase(mb_substr($input, -$bytes, mb_strlen($input, '8bit'), '8bit')) === static::lowercase($with);
237243
}
238244

tests/NumericHelperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Yiisoft\Strings\Tests;
46

57
use PHPUnit\Framework\TestCase;

tests/StringHelperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public function testStartsWithIgnoringCase(): void
158158
$this->assertTrue(StringHelper::startsWithIgnoringCase('HTTP://BÜrger.DE/', 'http://bürger.de'));
159159
$this->assertTrue(StringHelper::startsWithIgnoringCase('üЯйΨB', 'ÜяЙΨ'));
160160
$this->assertTrue(StringHelper::startsWithIgnoringCase('anything', ''));
161+
$this->assertTrue(StringHelper::startsWithIgnoringCase('anything', null));
161162
}
162163

163164
/**
@@ -210,6 +211,7 @@ public function testEndsWithIgnoringCase(): void
210211
$this->assertTrue(StringHelper::endsWithIgnoringCase('string', 'nG'));
211212
$this->assertTrue(StringHelper::endsWithIgnoringCase('BüЯйΨ', 'ÜяЙΨ'));
212213
$this->assertTrue(StringHelper::endsWithIgnoringCase('anything', ''));
214+
$this->assertTrue(StringHelper::endsWithIgnoringCase('anything', null));
213215
}
214216

215217
public function testCountWords(): void

tests/WildcardPatternTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Yiisoft\Strings\Tests;
46

57
use PHPUnit\Framework\TestCase;

0 commit comments

Comments
 (0)