Skip to content

Commit fb818d7

Browse files
authored
Merge pull request #4 from samsonasik/3.0.x
3.0.0
2 parents 6bbdcb9 + 7618f07 commit fb818d7

File tree

7 files changed

+75
-71
lines changed

7 files changed

+75
-71
lines changed

.github/workflows/ci_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-versions: ['7.3', '7.4', 8.0']
16+
php-versions: ['8.1', '8.2']
1717
steps:
1818
- name: Setup PHP Action
1919
uses: shivammathur/setup-php@v2

composer.json

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,28 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^7.3 || ^8.0",
25-
"laminas/laminas-filter": "^2.9",
26-
"laminas/laminas-validator": "^2.12",
27-
"symfony/polyfill-mbstring": "^1.10",
28-
"webmozart/assert": "^1.4"
24+
"php": "^8.1",
25+
"laminas/laminas-filter": "^2.31",
26+
"laminas/laminas-validator": "^2.29",
27+
"samsonasik/array-lookup": "*",
28+
"symfony/polyfill-mbstring": "^1.27",
29+
"webmozart/assert": "^1.11"
2930
},
3031
"require-dev": {
31-
"kahlan/kahlan": "^5.0",
32-
"laminas/laminas-coding-standard": "^2.0",
33-
"php-coveralls/php-coveralls": "^2.1",
34-
"phpstan/phpstan": "^0.12",
35-
"phpstan/phpstan-webmozart-assert": "^0.12.0",
32+
"kahlan/kahlan": "^5.2.2",
33+
"laminas/laminas-coding-standard": "^2.5",
34+
"php-coveralls/php-coveralls": "^2.5.3",
35+
"phpstan/phpstan": "^1.9.11",
36+
"phpstan/phpstan-webmozart-assert": "^1.2.2",
3637
"rector/rector": "dev-main",
37-
"squizlabs/php_codesniffer": "^3.5.8"
38+
"squizlabs/php_codesniffer": "^3.7.1"
3839
},
3940
"config": {
4041
"bin-dir": "bin",
41-
"sort-packages": true
42+
"sort-packages": true,
43+
"allow-plugins": {
44+
"dealerdirect/phpcodesniffer-composer-installer": true
45+
}
4246
},
4347
"autoload": {
4448
"psr-4": {

phpstan.neon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
includes:
2-
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
2+
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
3+
4+
parameters:
5+
checkGenericClassInNonGenericObjectType: false
6+
7+
ignoreErrors:
8+
- '#Parameter \#2 \$filter of static method ArrayLookup\\Finder\:\:first\(\) expects callable\(mixed, int\|string\|null=\): bool, Closure\(string, string\): bool given#'

rector.php

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
<?php
22

3-
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector;
4-
use Rector\Core\Configuration\Option;
5-
use Rector\Core\ValueObject\PhpVersion;
3+
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
4+
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
5+
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
66
use Rector\Set\ValueObject\SetList;
7-
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;
8-
use Rector\TypeDeclaration\Rector\Param\ParamTypeFromStrictTypedPropertyRector;
9-
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
10-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Config\RectorConfig;
119

12-
return static function (ContainerConfigurator $containerConfigurator): void {
13-
$containerConfigurator->import(SetList::CODING_STYLE);
14-
$containerConfigurator->import(SetList::PHP_70);
15-
$containerConfigurator->import(SetList::PHP_71);
16-
$containerConfigurator->import(SetList::PHP_72);
17-
$containerConfigurator->import(SetList::PHP_73);
18-
$containerConfigurator->import(SetList::CODE_QUALITY);
19-
$containerConfigurator->import(SetList::TYPE_DECLARATION);
20-
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
21-
22-
$parameters = $containerConfigurator->parameters();
23-
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/spec']);
10+
return static function (RectorConfig $rectorConfig): void {
11+
$rectorConfig->sets([
12+
SetList::CODING_STYLE,
13+
LevelSetList::UP_TO_PHP_81,
14+
SetList::CODE_QUALITY,
15+
SetList::TYPE_DECLARATION
16+
]);
2417

25-
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
26-
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
18+
$rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/spec', __FILE__]);
19+
$rectorConfig->importNames();
2720

28-
$parameters->set(Option::SKIP, [
29-
// requires php 7.4
30-
CallUserFuncArrayToVariadicRector::class,
31-
ReturnTypeFromStrictTypedPropertyRector::class,
32-
TypedPropertyFromStrictConstructorRector::class,
33-
ParamTypeFromStrictTypedPropertyRector::class,
21+
$rectorConfig->skip([
22+
NullToStrictStringFuncCallArgRector::class,
23+
StaticArrowFunctionRector::class => [
24+
__DIR__ . '/spec',
25+
],
26+
StaticClosureRector::class => [
27+
__DIR__ . '/spec',
28+
]
3429
]);
3530
};

spec/Validator/NamingSpec.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44

55
use Naming\Validator\Naming;
66

7-
describe('Naming', function () {
7+
describe('Naming', function (): void {
88

9-
given('validator', function () {
10-
11-
return new Naming();
12-
13-
});
9+
given('validator', fn(): Naming => new Naming());
1410

1511
describe('->isValid', function (): void {
1612

src/Filter/Naming.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,32 @@
1717

1818
use const MB_CASE_TITLE;
1919

20-
class Naming extends AbstractFilter
20+
final class Naming extends AbstractFilter
2121
{
22-
/** @param string $value */
22+
/**
23+
* @param string $value
24+
*/
2325
public function filter($value): string
2426
{
2527
$value = (new StripTags())->filter($value);
2628
$value = (new StringTrim())->filter($value);
27-
$value = mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
28-
$value = preg_replace('#\s{2,}#', ' ', $value);
2929

3030
Assert::string($value);
3131

32+
$value = mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
33+
$value = preg_replace('#\s{2,}#', ' ', $value);
34+
3235
$chars = ["'", '-'];
33-
array_walk($chars, function ($row) use (&$value): void {
36+
array_walk($chars, static function ($row) use (&$value): void {
37+
Assert::string($value);
38+
3439
$position = mb_strpos($value, $row);
3540
if ($position !== false && isset($value[$position + 1])) {
3641
$value[$position + 1] = mb_strtoupper($value[$position + 1]);
3742
}
3843
});
3944

45+
Assert::string($value);
4046
return $value;
4147
}
4248
}

src/Validator/Naming.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,57 @@
44

55
namespace Naming\Validator;
66

7+
use ArrayLookup\Finder;
78
use Laminas\Validator\AbstractValidator;
89
use Webmozart\Assert\Assert;
910

10-
use function array_filter;
1111
use function array_key_exists;
12-
use function current;
12+
use function is_string;
1313
use function mb_strlen;
1414
use function preg_match;
15-
use function strpos;
15+
use function str_contains;
1616

17-
use const ARRAY_FILTER_USE_KEY;
18-
19-
class Naming extends AbstractValidator
17+
final class Naming extends AbstractValidator
2018
{
2119
/**
2220
* @var string
2321
*/
24-
public const SPECIAL_OR_NUMBER = 'SPECIAL_OR_NUMBER';
22+
private const SPECIAL_OR_NUMBER = 'SPECIAL_OR_NUMBER';
2523

2624
/**
2725
* @var string
2826
*/
29-
public const SINGLE_DOT = 'SINGLE_DOT';
27+
private const SINGLE_DOT = 'SINGLE_DOT';
3028

3129
/**
3230
* @var string
3331
*/
34-
public const SINGLE_HYPHEN = 'SINGLE_HYPHEN';
32+
private const SINGLE_HYPHEN = 'SINGLE_HYPHEN';
3533

3634
/**
3735
* @var string
3836
*/
39-
public const SINGLE_APOSTROPHE = 'SINGLE_APOSTROPHE';
37+
private const SINGLE_APOSTROPHE = 'SINGLE_APOSTROPHE';
4038

4139
/**
4240
* @var string
4341
*/
44-
public const CONSECUTIVE_DOT = 'CONSECUTIVE_DOT';
42+
private const CONSECUTIVE_DOT = 'CONSECUTIVE_DOT';
4543

4644
/**
4745
* @var string
4846
*/
49-
public const CONSECUTIVE_HYPHEN = 'CONSECUTIVE_HYPHEN';
47+
private const CONSECUTIVE_HYPHEN = 'CONSECUTIVE_HYPHEN';
5048

5149
/**
5250
* @var string
5351
*/
54-
public const CONSECUTIVE_APOSTROPHE = 'CONSECUTIVE_APOSTROPHE';
52+
private const CONSECUTIVE_APOSTROPHE = 'CONSECUTIVE_APOSTROPHE';
5553

5654
/**
5755
* @var string
5856
*/
59-
public const DOT_TOBE_IN_LAST_WORD = 'DOT_TOBE_IN_LAST_WORD';
57+
private const DOT_TOBE_IN_LAST_WORD = 'DOT_TOBE_IN_LAST_WORD';
6058

6159
/** @var array<string, string> */
6260
protected $messageTemplates = [
@@ -109,12 +107,11 @@ public function isValid($value): bool
109107
"''" => self::CONSECUTIVE_APOSTROPHE,
110108
];
111109

112-
$error = array_filter($messageTemplates, function ($key) use ($value): bool {
113-
return strpos($value, $key) !== false;
114-
}, ARRAY_FILTER_USE_KEY);
110+
$filter = static fn(string $datum, string $key): bool => str_contains($value, $key);
111+
$error = Finder::first($messageTemplates, $filter);
115112

116-
if ($error !== []) {
117-
$this->error(current($error));
113+
if (is_string($error)) {
114+
$this->error($error);
118115
return false;
119116
}
120117
}

0 commit comments

Comments
 (0)