Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
26 changes: 26 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -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'
24 changes: 0 additions & 24 deletions .github/workflows/rector.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ composer.phar

# PHPBench
.phpbench

# PHP CS Fixer
/.php-cs-fixer.cache
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use Yiisoft\CodeStyle\ConfigBuilder;

$finder = (new Finder())->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return ConfigBuilder::build()
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@Yiisoft/Core' => true,
'@Yiisoft/Core:risky' => true,
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -64,6 +66,8 @@
}
},
"scripts": {
"cs-fix": "php-cs-fixer fix",
"rector": "rector",
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
}
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -18,5 +19,6 @@
])
->withSkip([
ClosureToArrowFunctionRector::class,
ReadOnlyPropertyRector::class,
NullToStrictStringFuncCallArgRector::class,
]);
2 changes: 1 addition & 1 deletion src/AbstractCombinedRegexp.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function throwFailedMatchException(string $string): void
'Failed to match pattern "%s" with string "%s".',
$this->getCompiledPattern(),
$string,
)
),
);
}
}
24 changes: 12 additions & 12 deletions src/CombinedRegexp.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
*/
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.');
}

$this->patterns = array_values($patterns);

Check warning on line 45 in src/CombinedRegexp.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayValues": @@ @@ if (empty($patterns)) { throw new InvalidArgumentException('At least one pattern should be specified.'); } - $this->patterns = array_values($patterns); + $this->patterns = $patterns; $this->compiledPattern = $this->compilePatterns($this->patterns) . $this->flags; } /**
$this->compiledPattern = $this->compilePatterns($this->patterns) . $this->flags;
}

Expand Down Expand Up @@ -85,6 +85,16 @@
return count($matches) - 1;
}

public function getPatterns(): array
{
return $this->patterns;
}

public function getFlags(): string
{
return $this->flags;
}

/**
* @param string[] $patterns
*
Expand All @@ -101,24 +111,14 @@
* https://regex101.com/r/lE1Q1S/1, https://regex101.com/r/rWg7Fj/1
*/
foreach ($patterns as $i => $pattern) {
$quotedPatterns[] = $pattern . str_repeat('()', $i);

Check warning on line 114 in src/CombinedRegexp.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Concat": @@ @@ * https://regex101.com/r/lE1Q1S/1, https://regex101.com/r/rWg7Fj/1 */ foreach ($patterns as $i => $pattern) { - $quotedPatterns[] = $pattern . str_repeat('()', $i); + $quotedPatterns[] = str_repeat('()', $i) . $pattern; } $combinedRegexps = '(?|' . strtr(implode('|', $quotedPatterns), [self::REGEXP_DELIMITER => self::QUOTE_REPLACER]) . ')'; return self::REGEXP_DELIMITER . $combinedRegexps . self::REGEXP_DELIMITER; } }
}

$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;
}
}
12 changes: 6 additions & 6 deletions src/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@
}

/**
* @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
Expand Down Expand Up @@ -507,8 +507,8 @@
$words = preg_replace('/(?<!\p{Lu})(\p{Lu})|(\p{Lu})(?=\p{Ll})/u', ' \0', $input);
return mb_strtolower(
trim(
str_replace(['-', '_', '.'], ' ', $words)
)
str_replace(['-', '_', '.'], ' ', $words),
),
);
}

Expand All @@ -535,8 +535,8 @@
*/
$result = preg_replace($regex, addslashes($separator) . '\1', $input);

if ($separator !== '_') {

Check warning on line 538 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "NotIdentical": @@ @@ * never returns `false`. */ $result = preg_replace($regex, addslashes($separator) . '\1', $input); - if ($separator !== '_') { + if ($separator === '_') { $result = str_replace('_', $separator, $result); } return mb_strtolower(trim($result, $separator));
$result = str_replace('_', $separator, $result);

Check warning on line 539 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "UnwrapStrReplace": @@ @@ */ $result = preg_replace($regex, addslashes($separator) . '\1', $input); if ($separator !== '_') { - $result = str_replace('_', $separator, $result); + $result = $result; } return mb_strtolower(trim($result, $separator)); }
}

return mb_strtolower(trim($result, $separator));
Expand Down Expand Up @@ -602,7 +602,7 @@
{
$input = $this->toPascalCase($input);

return mb_strtolower(mb_substr($input, 0, 1)) . mb_substr($input, 1);

Check warning on line 605 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "MBString": @@ @@ public function toCamelCase(string $input): string { $input = $this->toPascalCase($input); - return mb_strtolower(mb_substr($input, 0, 1)) . mb_substr($input, 1); + return strtolower(mb_substr($input, 0, 1)) . mb_substr($input, 1); } /** * Returns given word as "snake_cased".
}

/**
Expand Down Expand Up @@ -668,7 +668,7 @@
*/
public function toSlug(string $input, string $replacement = '-', bool $lowercase = true): string
{
$quotedReplacement = preg_quote($replacement, '/');

Check warning on line 671 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "PregQuote": @@ @@ */ public function toSlug(string $input, string $replacement = '-', bool $lowercase = true): string { - $quotedReplacement = preg_quote($replacement, '/'); + $quotedReplacement = $replacement; /** * Replace all non-words character *

/**
* Replace all non-words character
Expand All @@ -685,7 +685,7 @@
* `preg_replace()` never returns `false`.
*/
$input = preg_replace(
"/^(?:$quotedReplacement)+|(?:$quotedReplacement)+$/u" . ($lowercase ? 'i' : ''),

Check warning on line 688 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ * @var string $input We assume that `$input` and `$quotedReplacement` are valid UTF-8 strings, so * `preg_replace()` never returns `false`. */ - $input = preg_replace("/^(?:{$quotedReplacement})+|(?:{$quotedReplacement})+\$/u" . ($lowercase ? 'i' : ''), '', $input); + $input = preg_replace("/^(?:{$quotedReplacement})+|(?:{$quotedReplacement})+\$/u", '', $input); return $lowercase ? strtolower($input) : $input; } /**

Check warning on line 688 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Ternary": @@ @@ * @var string $input We assume that `$input` and `$quotedReplacement` are valid UTF-8 strings, so * `preg_replace()` never returns `false`. */ - $input = preg_replace("/^(?:{$quotedReplacement})+|(?:{$quotedReplacement})+\$/u" . ($lowercase ? 'i' : ''), '', $input); + $input = preg_replace("/^(?:{$quotedReplacement})+|(?:{$quotedReplacement})+\$/u" . ($lowercase ? '' : 'i'), '', $input); return $lowercase ? strtolower($input) : $input; } /**
'',
$input,
);
Expand All @@ -703,8 +703,8 @@
* @noinspection PhpComposerExtensionStubsInspection
*
* @param string $input Input string. It must be valid UTF-8 string.
* @param string|Transliterator|null $transliterator either a {@see \Transliterator} or a string
* from which a {@see \Transliterator} can be built. If null, value set with {@see withTransliterator()}
* @param string|Transliterator|null $transliterator either a {@see Transliterator} or a string
* from which a {@see Transliterator} can be built. If null, value set with {@see withTransliterator()}
* or {@see TRANSLITERATE_LOOSE} is used.
*/
public function toTransliterated(string $input, $transliterator = null): string
Expand Down
27 changes: 14 additions & 13 deletions src/MemoizedCombinedRegexp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Yiisoft\Strings;

use Exception;

/**
* `MemoizedCombinedRegexp` is a decorator for {@see AbstractCombinedRegexp} that caches results of
* - {@see AbstractCombinedRegexp::matches()}
Expand All @@ -19,8 +21,7 @@

public function __construct(
private readonly AbstractCombinedRegexp $decorated,
) {
}
) {}

public function getCompiledPattern(): string
{
Expand All @@ -36,7 +37,7 @@

public function getMatchingPattern(string $string): string
{
$this->evaluate($string);

Check warning on line 40 in src/MemoizedCombinedRegexp.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ } public function getMatchingPattern(string $string): string { - $this->evaluate($string); + return $this->getPatterns()[$this->getMatchingPatternPosition($string)]; } public function getMatchingPatternPosition(string $string): int

return $this->getPatterns()[$this->getMatchingPatternPosition($string)];
}
Expand All @@ -48,6 +49,16 @@
return $this->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])) {
Expand All @@ -58,18 +69,8 @@

$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();
}
}
9 changes: 6 additions & 3 deletions src/NumericHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -68,8 +71,8 @@
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)) {
Expand Down Expand Up @@ -157,7 +160,7 @@
throw new InvalidArgumentException("Not supported postfix '$postfix' in input string: $string");
}

return (int) ((float) $numericPart * $postfixMultiplier);

Check warning on line 163 in src/NumericHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "CastFloat": @@ @@ if ($postfixMultiplier === null) { throw new InvalidArgumentException("Not supported postfix '{$postfix}' in input string: {$string}"); } - return (int) ((float) $numericPart * $postfixMultiplier); + return (int) ($numericPart * $postfixMultiplier); } throw new InvalidArgumentException("Incorrect input string: {$string}"); }
}

throw new InvalidArgumentException("Incorrect input string: $string");
Expand All @@ -184,7 +187,7 @@

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),
);
}

Expand Down
Loading
Loading