Skip to content

Commit 0203f87

Browse files
authored
Merge pull request #6 from samsonasik/bump
Bump to laminas/filter 3 and laminas/validator 3
2 parents f85d44f + 1cc1393 commit 0203f87

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
],
2323
"require": {
2424
"php": "^8.1",
25-
"laminas/laminas-filter": "^2.31",
26-
"laminas/laminas-validator": "^2.29",
25+
"laminas/laminas-filter": "^3.0",
26+
"laminas/laminas-validator": "^3.0",
2727
"samsonasik/array-lookup": "^1.3",
2828
"symfony/polyfill-mbstring": "^1.27",
2929
"webmozart/assert": "^1.11"
@@ -32,8 +32,8 @@
3232
"kahlan/kahlan": "^5.2.2",
3333
"laminas/laminas-coding-standard": "^2.5",
3434
"php-coveralls/php-coveralls": "^2.5.3",
35-
"phpstan/phpstan": "^1.9.11",
36-
"phpstan/phpstan-webmozart-assert": "^1.2.2",
35+
"phpstan/phpstan": "^2.0",
36+
"phpstan/phpstan-webmozart-assert": "^2.0",
3737
"rector/rector": "dev-main",
3838
"squizlabs/php_codesniffer": "^3.7.1"
3939
},

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ includes:
22
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
33

44
parameters:
5+
treatPhpDocTypesAsCertain: false
56
ignoreErrors:
6-
- '#Parameter \#2 \$filter of static method ArrayLookup\\Finder\:\:first\(\) expects callable\(mixed, int\|string\|null=\): bool, Closure\(string, string\): bool given#'
77
-
88
identifier: missingType.generics
99
path: src/Filter/Naming.php

spec/Filter/NamingSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
$naming = new Naming();
2525
foreach ($maps as $key => $value) {
26-
expect($naming->filter($key))->toBe($value);
26+
expect($naming($key))->toBe($value);
2727
}
2828

2929
});

src/Filter/Naming.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Naming\Filter;
66

7-
use Laminas\Filter\AbstractFilter;
7+
use Laminas\Filter\FilterInterface;
88
use Laminas\Filter\StringTrim;
99
use Laminas\Filter\StripTags;
1010
use Webmozart\Assert\Assert;
@@ -17,12 +17,12 @@
1717

1818
use const MB_CASE_TITLE;
1919

20-
final class Naming extends AbstractFilter
20+
final class Naming implements FilterInterface
2121
{
2222
/**
2323
* @param string $value
2424
*/
25-
public function filter($value): string
25+
public function filter(mixed $value): string
2626
{
2727
$value = (new StripTags())->filter($value);
2828
$value = (new StringTrim())->filter($value);
@@ -45,4 +45,12 @@ public function filter($value): string
4545
Assert::string($value);
4646
return $value;
4747
}
48+
49+
/**
50+
* @param string $value
51+
*/
52+
public function __invoke(mixed $value): string
53+
{
54+
return $this->filter($value);
55+
}
4856
}

src/Validator/Naming.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ final class Naming extends AbstractValidator
5757
private const DOT_TOBE_IN_LAST_WORD = 'DOT_TOBE_IN_LAST_WORD';
5858

5959
/** @var array<string, string> */
60-
protected $messageTemplates = [
60+
protected array $messageTemplates = [
6161
self::SPECIAL_OR_NUMBER => 'Names can contain only letters, hyphens, apostrophe, spaces & full stops',
6262
self::SINGLE_DOT => 'Single "." character is not allowed',
6363
self::SINGLE_HYPHEN => 'Single "-" character is not allowed',
@@ -69,7 +69,7 @@ final class Naming extends AbstractValidator
6969
];
7070

7171
/** @param string $value */
72-
public function isValid($value): bool
72+
public function isValid(mixed $value): bool
7373
{
7474
Assert::string($value);
7575
$this->setValue($value);
@@ -99,7 +99,8 @@ public function isValid($value): bool
9999
"''" => self::CONSECUTIVE_APOSTROPHE,
100100
];
101101

102-
$filter = static fn(string $datum, string $key): bool => str_contains($value, $key);
102+
$filter = static fn(mixed $datum, int|string|null $key): bool
103+
=> is_string($key) && str_contains($value, $key);
103104
$error = Finder::first($messageTemplates, $filter);
104105

105106
if (is_string($error)) {

0 commit comments

Comments
 (0)