diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 19b694d..e462be4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,3 +30,5 @@ jobs: ['ubuntu-latest', 'windows-latest'] php: >- ['8.1', '8.2', '8.3', '8.4', '8.5'] + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 0000000..71145b0 --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,26 @@ +name: rector-cs + +on: + pull_request: + paths: + - 'src/**' + - 'tests/**' + - 'rector.php' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - '.github/workflows/rector-cs.yml' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rector-cs: + permissions: + contents: write # Required to push rector/CS fixes to PR branch + uses: yiisoft/actions/.github/workflows/rector-cs.yml@master + with: + php: '8.1' diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index 20f7d89..0000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,24 +0,0 @@ -on: - pull_request_target: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' - -name: rector - -jobs: - rector: - uses: yiisoft/actions/.github/workflows/rector.yml@master - secrets: - token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - os: >- - ['ubuntu-latest'] - php: >- - ['8.5'] diff --git a/.gitignore b/.gitignore index 0f8b69d..916bfe3 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ composer.phar # PHPBench .phpbench + +# PHP CS Fixer +/.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..2477e66 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,21 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +return ConfigBuilder::build() + ->setRiskyAllowed(true) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@Yiisoft/Core' => true, + '@Yiisoft/Core:risky' => true, + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 1ab379b..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,85 +0,0 @@ -preset: psr12 -risky: true - -version: 8.1 - -finder: - exclude: - - docs - - vendor - -enabled: - - alpha_ordered_traits - - array_indentation - - array_push - - combine_consecutive_issets - - combine_consecutive_unsets - - combine_nested_dirname - - declare_strict_types - - dir_constant - - fully_qualified_strict_types - - function_to_constant - - hash_to_slash_comment - - is_null - - logical_operators - - magic_constant_casing - - magic_method_casing - - method_separation - - modernize_types_casting - - native_function_casing - - native_function_type_declaration_casing - - no_alias_functions - - no_empty_comment - - no_empty_phpdoc - - no_empty_statement - - no_extra_block_blank_lines - - no_short_bool_cast - - no_superfluous_elseif - - no_unneeded_control_parentheses - - no_unneeded_curly_braces - - no_unneeded_final_method - - no_unset_cast - - no_unused_imports - - no_unused_lambda_imports - - no_useless_else - - no_useless_return - - normalize_index_brace - - php_unit_dedicate_assert - - php_unit_dedicate_assert_internal_type - - php_unit_expectation - - php_unit_mock - - php_unit_mock_short_will_return - - php_unit_namespaced - - php_unit_no_expectation_annotation - - phpdoc_no_empty_return - - phpdoc_no_useless_inheritdoc - - phpdoc_order - - phpdoc_property - - phpdoc_scalar - - phpdoc_singular_inheritdoc - - phpdoc_trim - - phpdoc_trim_consecutive_blank_line_separation - - phpdoc_type_to_var - - phpdoc_types - - phpdoc_types_order - - print_to_echo - - regular_callable_call - - return_assignment - - self_accessor - - self_static_accessor - - set_type_to_cast - - short_array_syntax - - short_list_syntax - - simplified_if_return - - single_quote - - standardize_not_equals - - ternary_to_null_coalescing - - trailing_comma_in_multiline_array - - unalign_double_arrow - - unalign_equals - - empty_loop_body_braces - - integer_literal_case - - union_type_without_spaces - -disabled: - - function_declaration diff --git a/CHANGELOG.md b/CHANGELOG.md index b868d9a..c33248e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.7.1 under development - New #156: Add `NumericHelper::trimDecimalZeros()` (@samdark, @vjik) +- Enh #163: Explicitly import classes, functions, and constants in "use" sections (@vjik) ## 2.7.0 November 23, 2025 diff --git a/composer.json b/composer.json index 4c47136..b5c9949 100644 --- a/composer.json +++ b/composer.json @@ -33,11 +33,13 @@ }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", + "friendsofphp/php-cs-fixer": "^3.95", "maglnet/composer-require-checker": "^4.7.1", + "phpbench/phpbench": "^1.4.1", "phpunit/phpunit": "^10.5.48", "rector/rector": "^2.1.2", "spatie/phpunit-watcher": "^1.24", - "phpbench/phpbench": "^1.4.1" + "yiisoft/code-style": "^1.0" }, "autoload": { "psr-4": { @@ -64,6 +66,8 @@ } }, "scripts": { + "cs-fix": "php-cs-fixer fix", + "rector": "rector", "test": "phpunit --testdox --no-interaction", "test-watch": "phpunit-watcher watch" } diff --git a/rector.php b/rector.php index 1f8a952..54537c2 100644 --- a/rector.php +++ b/rector.php @@ -5,6 +5,7 @@ use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; return RectorConfig::configure() @@ -18,5 +19,6 @@ ]) ->withSkip([ ClosureToArrowFunctionRector::class, + ReadOnlyPropertyRector::class, NullToStrictStringFuncCallArgRector::class, ]); diff --git a/src/AbstractCombinedRegexp.php b/src/AbstractCombinedRegexp.php index 169172c..f9dac6f 100644 --- a/src/AbstractCombinedRegexp.php +++ b/src/AbstractCombinedRegexp.php @@ -68,7 +68,7 @@ protected function throwFailedMatchException(string $string): void 'Failed to match pattern "%s" with string "%s".', $this->getCompiledPattern(), $string, - ) + ), ); } } diff --git a/src/CombinedRegexp.php b/src/CombinedRegexp.php index 81fc72c..da272d7 100644 --- a/src/CombinedRegexp.php +++ b/src/CombinedRegexp.php @@ -36,7 +36,7 @@ final class CombinedRegexp extends AbstractCombinedRegexp */ public function __construct( array $patterns, - private readonly string $flags = '' + private readonly string $flags = '', ) { if (empty($patterns)) { throw new InvalidArgumentException('At least one pattern should be specified.'); @@ -85,6 +85,16 @@ public function getMatchingPatternPosition(string $string): int return count($matches) - 1; } + public function getPatterns(): array + { + return $this->patterns; + } + + public function getFlags(): string + { + return $this->flags; + } + /** * @param string[] $patterns * @@ -106,19 +116,9 @@ private function compilePatterns(array $patterns): string $combinedRegexps = '(?|' . strtr( implode('|', $quotedPatterns), - [self::REGEXP_DELIMITER => self::QUOTE_REPLACER] + [self::REGEXP_DELIMITER => self::QUOTE_REPLACER], ) . ')'; return self::REGEXP_DELIMITER . $combinedRegexps . self::REGEXP_DELIMITER; } - - public function getPatterns(): array - { - return $this->patterns; - } - - public function getFlags(): string - { - return $this->flags; - } } diff --git a/src/Inflector.php b/src/Inflector.php index 91ac2cd..f9543be 100644 --- a/src/Inflector.php +++ b/src/Inflector.php @@ -384,8 +384,8 @@ public function getSpecialRules(): array } /** - * @param string|Transliterator $transliterator Either a {@see \Transliterator}, or a string from which - * a {@see \Transliterator} can be built for transliteration. Used by {@see toTransliterated()} when intl is available. + * @param string|Transliterator $transliterator Either a {@see Transliterator}, or a string from which + * a {@see Transliterator} can be built for transliteration. Used by {@see toTransliterated()} when intl is available. * Defaults to {@see TRANSLITERATE_LOOSE}. * * @return self @@ -507,8 +507,8 @@ public function toWords(string $input): string $words = preg_replace('/(?results[$string]['position'] ?? $this->throwFailedMatchException($string); } + public function getPatterns(): array + { + return $this->decorated->getPatterns(); + } + + public function getFlags(): string + { + return $this->decorated->getFlags(); + } + private function evaluate(string $string): void { if (isset($this->results[$string])) { @@ -58,18 +69,8 @@ private function evaluate(string $string): void $this->results[$string]['matches'] = true; $this->results[$string]['position'] = $position; - } catch (\Exception) { + } catch (Exception) { $this->results[$string]['matches'] = false; } } - - public function getPatterns(): array - { - return $this->decorated->getPatterns(); - } - - public function getFlags(): string - { - return $this->decorated->getFlags(); - } } diff --git a/src/NumericHelper.php b/src/NumericHelper.php index bf68d64..f22b864 100644 --- a/src/NumericHelper.php +++ b/src/NumericHelper.php @@ -18,6 +18,9 @@ use function preg_replace; use function str_replace; use function substr; +use function sprintf; + +use const FILTER_VALIDATE_INT; /** * Provides static methods to work with numeric strings. @@ -68,8 +71,8 @@ public static function toOrdinal(mixed $value): string throw new InvalidArgumentException("Value must be numeric. $type given."); } - if (fmod((float)$value, 1) !== 0.00) { - return (string)$value; + if (fmod((float) $value, 1) !== 0.00) { + return (string) $value; } if (in_array($value % 100, [11, 12, 13], true)) { @@ -184,7 +187,7 @@ public static function trimDecimalZeros(?string $value): ?string if (!is_numeric($value)) { throw new InvalidArgumentException( - sprintf('Value must be numeric string or null. "%s" given.', $value) + sprintf('Value must be numeric string or null. "%s" given.', $value), ); } diff --git a/src/StringHelper.php b/src/StringHelper.php index 2f4dd77..03bb8f3 100644 --- a/src/StringHelper.php +++ b/src/StringHelper.php @@ -34,6 +34,10 @@ use function strtr; use function trim; +use const PREG_SPLIT_DELIM_CAPTURE; +use const PREG_SPLIT_NO_EMPTY; +use const PREG_SPLIT_OFFSET_CAPTURE; + /** * Provides static methods to work with strings. */ @@ -50,9 +54,9 @@ final class StringHelper * * @return int The number of bytes in the given string. */ - public static function byteLength(string|null $input): int + public static function byteLength(?string $input): int { - return mb_strlen((string)$input, '8bit'); + return mb_strlen((string) $input, '8bit'); } /** @@ -158,7 +162,7 @@ public static function replaceSubstring( string $string, string $replacement, int $start, - int|null $length = null, + ?int $length = null, string $encoding = 'UTF-8', ): string { $stringLength = mb_strlen($string, $encoding); @@ -193,7 +197,7 @@ public static function replaceSubstring( * * @return bool Returns true if first input starts with second input, false otherwise. */ - public static function startsWith(string $input, string|null $with): bool + public static function startsWith(string $input, ?string $with): bool { return $with === null || str_starts_with($input, $with); } @@ -207,7 +211,7 @@ public static function startsWith(string $input, string|null $with): bool * * @return bool Returns true if first input starts with second input, false otherwise. */ - public static function startsWithIgnoringCase(string $input, string|null $with): bool + public static function startsWithIgnoringCase(string $input, ?string $with): bool { $bytes = self::byteLength($with); @@ -228,7 +232,7 @@ public static function startsWithIgnoringCase(string $input, string|null $with): * * @return bool Returns true if first input ends with second input, false otherwise. */ - public static function endsWith(string $input, string|null $with): bool + public static function endsWith(string $input, ?string $with): bool { return $with === null || str_ends_with($input, $with); } @@ -242,7 +246,7 @@ public static function endsWith(string $input, string|null $with): bool * * @return bool Returns true if first input ends with second input, false otherwise. */ - public static function endsWithIgnoringCase(string $input, string|null $with): bool + public static function endsWithIgnoringCase(string $input, ?string $with): bool { $bytes = self::byteLength($with); @@ -294,7 +298,7 @@ public static function truncateMiddle(string $input, int $length, string $trimMa } $trimMarkerLength = mb_strlen($trimMarker, $encoding); - $start = (int)ceil(($length - $trimMarkerLength) / 2); + $start = (int) ceil(($length - $trimMarkerLength) / 2); $end = $length - $start - $trimMarkerLength; return self::replaceSubstring($input, $trimMarker, $start, -$end, $encoding); @@ -468,8 +472,8 @@ public static function uppercaseFirstCharacterInEachWord(string $string, string $words = preg_split('/\s/u', $string, -1, PREG_SPLIT_NO_EMPTY); $wordsWithUppercaseFirstCharacter = array_map( - static fn (string $word) => self::uppercaseFirstCharacter($word, $encoding), - $words + static fn(string $word) => self::uppercaseFirstCharacter($word, $encoding), + $words, ); return implode(' ', $wordsWithUppercaseFirstCharacter); @@ -552,7 +556,7 @@ public static function parsePath( string $path, string $delimiter = '.', string $escapeCharacter = '\\', - bool $preserveDelimiterEscaping = false + bool $preserveDelimiterEscaping = false, ): array { if (strlen($delimiter) !== 1) { throw new InvalidArgumentException('Only 1 character is allowed for delimiter.'); @@ -583,11 +587,11 @@ public static function parsePath( sprintf( '/(?%1$s%1$s)*)%2$s/', preg_quote($escapeCharacter, '/'), - preg_quote($delimiter, '/') + preg_quote($delimiter, '/'), ), $path, -1, - PREG_SPLIT_OFFSET_CAPTURE + PREG_SPLIT_OFFSET_CAPTURE, ); $result = []; $countResults = count($matches); @@ -602,7 +606,7 @@ public static function parsePath( } return array_map( - static fn (string $key): string => str_replace( + static fn(string $key): string => str_replace( [ $escapeCharacter . $escapeCharacter, $escapeCharacter . $delimiter, @@ -611,9 +615,9 @@ public static function parsePath( $escapeCharacter, $delimiter, ], - $key + $key, ), - $result + $result, ); } diff --git a/src/WildcardPattern.php b/src/WildcardPattern.php index f5b0e27..78d46a7 100644 --- a/src/WildcardPattern.php +++ b/src/WildcardPattern.php @@ -39,8 +39,7 @@ final class WildcardPattern public function __construct( private string $pattern, private array $delimiters = ['\\\\', '/'], - ) { - } + ) {} /** * Checks if the passed string would match the given shell wildcard pattern. diff --git a/tests/AbstractCombinedRegexpTestCase.php b/tests/AbstractCombinedRegexpTestCase.php index bf06246..c31b3a5 100644 --- a/tests/AbstractCombinedRegexpTestCase.php +++ b/tests/AbstractCombinedRegexpTestCase.php @@ -7,6 +7,10 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Yiisoft\Strings\AbstractCombinedRegexp; +use Exception; +use InvalidArgumentException; + +use function sprintf; abstract class AbstractCombinedRegexpTestCase extends TestCase { @@ -18,7 +22,7 @@ public function testMatchAny(array $patterns, string $string, bool $expectedResu $message = sprintf( 'Failed to assert that string "%s" matches the string "%s".', $regexp->getCompiledPattern(), - $string + $string, ); $this->assertEquals($expectedResult, $actualResult, $message); } @@ -113,7 +117,7 @@ public function testMatchingPattern(array $patterns, string $string, string $exp $message = sprintf( 'Failed to assert that string "%s" matches the string "%s".', $regexp->getCompiledPattern(), - $string + $string, ); $this->assertEquals($expectedResult, $actualResult, $message); } @@ -199,7 +203,7 @@ public static function dataMatchingPatternPosition(): iterable public function testMatchDifferentDelimiters( array $patterns, string $flags, - string $string + string $string, ): void { $regexp = $this->createCombinedRegexp($patterns, $flags); $message = sprintf( @@ -228,7 +232,7 @@ public static function dataMatchDifferentDelimiters(): iterable public function testInvalidNumberOfPatterns(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('At least one pattern should be specified.'); $this->createCombinedRegexp([]); } @@ -239,7 +243,7 @@ public function testInvalidMatch(): void $string = 'def'; $this->assertFalse($regexp->matches($string)); - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Failed to match pattern "/(?|abc)/" with string "def".'); $regexp->getMatchingPatternPosition($string); diff --git a/tests/InflectorTest.php b/tests/InflectorTest.php index ecdf50c..9b0cb8c 100644 --- a/tests/InflectorTest.php +++ b/tests/InflectorTest.php @@ -12,56 +12,6 @@ final class InflectorTest extends TestCase { - private function getTestDataForToPlural(): array - { - return [ - 'access' => 'accesses', - 'address' => 'addresses', - 'move' => 'moves', - 'foot' => 'feet', - 'child' => 'children', - 'human' => 'humans', - 'man' => 'men', - 'staff' => 'staff', - 'tooth' => 'teeth', - 'person' => 'people', - 'mouse' => 'mice', - 'touch' => 'touches', - 'hash' => 'hashes', - 'shelf' => 'shelves', - 'potato' => 'potatoes', - 'bus' => 'buses', - 'test' => 'tests', - 'car' => 'cars', - 'netherlands' => 'netherlands', - 'currency' => 'currencies', - 'criterion' => 'criteria', - 'analysis' => 'analyses', - 'datum' => 'data', - 'schema' => 'schemas', - 'nation' => 'nations', - 'action' => 'actions', - 'creation' => 'creations', - 'decision' => 'decisions', - 'vision' => 'visions', - 'explosion' => 'explosions', - 'legion' => 'legions', - 'region' => 'regions', - 'information' => 'information', // special case - already ends in 'tion' but is uncountable - 'education' => 'educations', - 'attention' => 'attentions', - 'function' => 'functions', - 'junction' => 'junctions', - 'baron' => 'barons', - 'demon' => 'demons', - ]; - } - - private function getTestDataForToSingular(): array - { - return array_flip($this->getTestDataForToPlural()); - } - public function testToPlural(): void { $inflector = new Inflector(); @@ -137,7 +87,7 @@ public function testToPascalCase(): void $this->assertEquals('QweQweEwq', $inflector->toPascalCase('qwe qwe^ewq')); $this->assertEquals( 'ВідомоЩоТестиЗберігатьНашіНЕРВИ', - $inflector->toPascalCase('Відомо, що тести зберігать наші НЕРВИ! 🙃') + $inflector->toPascalCase('Відомо, що тести зберігать наші НЕРВИ! 🙃'), ); } @@ -453,7 +403,7 @@ public function testToTransliteratedWithTransliterationMap(): void 'O' => 'E', 'N' => 'N', 'E' => 'O', - ] + ], ); $this->assertEquals('ENO', $inflector->toTransliterated('ONE')); } @@ -489,16 +439,6 @@ public function testImmutability(): void $this->assertNotSame($original, $original->withTransliterator(Inflector::TRANSLITERATE_MEDIUM)); } - /** - * Asserts that value is one of expected values. - * - * @param string $message - */ - private function assertIsOneOf(mixed $actual, array $expected, $message = ''): void - { - self::assertThat($actual, new IsOneOfAssert($expected), $message); - } - public static function pascalCaseToIdProvider(): array { return [ @@ -540,4 +480,64 @@ public static function pascalCaseToIdProvider(): array ['test', ['TEST', '-']], ]; } + + private function getTestDataForToPlural(): array + { + return [ + 'access' => 'accesses', + 'address' => 'addresses', + 'move' => 'moves', + 'foot' => 'feet', + 'child' => 'children', + 'human' => 'humans', + 'man' => 'men', + 'staff' => 'staff', + 'tooth' => 'teeth', + 'person' => 'people', + 'mouse' => 'mice', + 'touch' => 'touches', + 'hash' => 'hashes', + 'shelf' => 'shelves', + 'potato' => 'potatoes', + 'bus' => 'buses', + 'test' => 'tests', + 'car' => 'cars', + 'netherlands' => 'netherlands', + 'currency' => 'currencies', + 'criterion' => 'criteria', + 'analysis' => 'analyses', + 'datum' => 'data', + 'schema' => 'schemas', + 'nation' => 'nations', + 'action' => 'actions', + 'creation' => 'creations', + 'decision' => 'decisions', + 'vision' => 'visions', + 'explosion' => 'explosions', + 'legion' => 'legions', + 'region' => 'regions', + 'information' => 'information', // special case - already ends in 'tion' but is uncountable + 'education' => 'educations', + 'attention' => 'attentions', + 'function' => 'functions', + 'junction' => 'junctions', + 'baron' => 'barons', + 'demon' => 'demons', + ]; + } + + private function getTestDataForToSingular(): array + { + return array_flip($this->getTestDataForToPlural()); + } + + /** + * Asserts that value is one of expected values. + * + * @param string $message + */ + private function assertIsOneOf(mixed $actual, array $expected, $message = ''): void + { + self::assertThat($actual, new IsOneOfAssert($expected), $message); + } } diff --git a/tests/IsOneOfAssert.php b/tests/IsOneOfAssert.php index 429245a..9a16d83 100644 --- a/tests/IsOneOfAssert.php +++ b/tests/IsOneOfAssert.php @@ -6,24 +6,24 @@ use PHPUnit\Framework\Constraint\Constraint; +use function in_array; + /** * IsOneOfAssert asserts that the value is one of the expected values. */ final class IsOneOfAssert extends Constraint { - public function __construct(private readonly array $allowedValues) - { - } + public function __construct(private readonly array $allowedValues) {} public function toString(): string { - $allowedValues = array_map(static fn ($value) => (string)$value, $this->allowedValues); + $allowedValues = array_map(static fn($value) => (string) $value, $this->allowedValues); $expectedAsString = implode(', ', $allowedValues); return "is one of $expectedAsString"; } protected function matches($other): bool { - return \in_array($other, $this->allowedValues, false); + return in_array($other, $this->allowedValues, false); } } diff --git a/tests/MemoizedCombinedRegexpTest.php b/tests/MemoizedCombinedRegexpTest.php index e406f0e..5448785 100644 --- a/tests/MemoizedCombinedRegexpTest.php +++ b/tests/MemoizedCombinedRegexpTest.php @@ -10,11 +10,6 @@ final class MemoizedCombinedRegexpTest extends AbstractCombinedRegexpTestCase { - protected function createCombinedRegexp(array $patterns, string $flags = ''): AbstractCombinedRegexp - { - return new MemoizedCombinedRegexp(new CombinedRegexp($patterns, $flags)); - } - public function testMemoization(): void { $decorated = $this->createMock(AbstractCombinedRegexp::class); @@ -32,4 +27,9 @@ public function testMemoization(): void $combinedRegexp->getMatchingPattern('test'); $combinedRegexp->getMatchingPatternPosition('test'); } + + protected function createCombinedRegexp(array $patterns, string $flags = ''): AbstractCombinedRegexp + { + return new MemoizedCombinedRegexp(new CombinedRegexp($patterns, $flags)); + } } diff --git a/tests/NumericHelperTest.php b/tests/NumericHelperTest.php index 460bfce..c500c8a 100644 --- a/tests/NumericHelperTest.php +++ b/tests/NumericHelperTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Strings\NumericHelper; use Yiisoft\Strings\Tests\Support\StringableObject; +use stdClass; final class NumericHelperTest extends TestCase { @@ -71,7 +72,7 @@ public function testNormalizeWithIncorrectType(): void public static function dataIsInteger(): array { return [ - [new \stdClass(), false], + [new stdClass(), false], [[], false], ['42', true], ['-42', true], diff --git a/tests/StringHelperTest.php b/tests/StringHelperTest.php index 3630743..c43e6a7 100644 --- a/tests/StringHelperTest.php +++ b/tests/StringHelperTest.php @@ -10,6 +10,8 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Strings\StringHelper; +use const PHP_EOL; + final class StringHelperTest extends TestCase { private const WS = [ @@ -482,7 +484,7 @@ public function testParsePath( string $delimiter, string $escapeCharacter, bool $preserveDelimiterEscaping, - array $expectedPath + array $expectedPath, ): void { $actualPath = StringHelper::parsePath($path, $delimiter, $escapeCharacter, $preserveDelimiterEscaping); $this->assertSame($expectedPath, $actualPath); diff --git a/tests/Support/StringableObject.php b/tests/Support/StringableObject.php index 5c83bb0..aaf731a 100644 --- a/tests/Support/StringableObject.php +++ b/tests/Support/StringableObject.php @@ -9,9 +9,8 @@ final class StringableObject implements Stringable { public function __construct( - private readonly string $string - ) { - } + private readonly string $string, + ) {} public function __toString(): string { diff --git a/tests/WildcardPatternTest.php b/tests/WildcardPatternTest.php index 99b9aee..9c8a9bf 100644 --- a/tests/WildcardPatternTest.php +++ b/tests/WildcardPatternTest.php @@ -101,16 +101,6 @@ public function testMatchWildcard(string $pattern, string $string, bool $expecte $this->assertSame($expectedResult, $wildcardPattern->match($string)); } - private function getWildcardPattern(string $pattern, array $options): WildcardPattern - { - $wildcardPattern = new WildcardPattern($pattern); - if (isset($options['caseSensitive']) && $options['caseSensitive'] === false) { - $wildcardPattern = $wildcardPattern->ignoreCase(); - } - - return $wildcardPattern; - } - public function testDisableOptions(): void { $wildcardPattern = (new WildcardPattern('abc42')) @@ -171,4 +161,14 @@ public function testQuote(string $string, string $expected): void { $this->assertSame($expected, WildcardPattern::quote($string)); } + + private function getWildcardPattern(string $pattern, array $options): WildcardPattern + { + $wildcardPattern = new WildcardPattern($pattern); + if (isset($options['caseSensitive']) && $options['caseSensitive'] === false) { + $wildcardPattern = $wildcardPattern->ignoreCase(); + } + + return $wildcardPattern; + } }