Skip to content

Commit

Permalink
use strlen() directly, as enough for string check (#4969)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 10, 2023
1 parent ead7a25 commit b5c8f9a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
4 changes: 1 addition & 3 deletions packages/NodeNameResolver/Regex/RegexPatternDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Rector\NodeNameResolver\Regex;

use Nette\Utils\Strings;

final class RegexPatternDetector
{
/**
Expand All @@ -17,7 +15,7 @@ final class RegexPatternDetector

public function isRegexPattern(string $name): bool
{
if (Strings::length($name) <= 2) {
if (strlen($name) <= 2) {
return false;
}

Expand Down
33 changes: 16 additions & 17 deletions packages/Parallel/Application/ParallelFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,22 @@ public function process(
$timeoutInSeconds = SimpleParameterProvider::provideIntParameter(Option::PARALLEL_JOB_TIMEOUT_IN_SECONDS);
$fileChunksBudgetPerProcess = [];

$processSpawner = function() use (
&$systemErrors,
&$fileDiffs,
&$jobs,
$postFileCallback,
&$systemErrorsCount,
&$reachedInternalErrorsCountLimit,
$mainScript,
$input,
$serverPort,
$streamSelectLoop,
$timeoutInSeconds,
$handleErrorCallable,
&$fileChunksBudgetPerProcess,
&$processSpawner
): void {

$processSpawner = function () use (
&$systemErrors,
&$fileDiffs,
&$jobs,
$postFileCallback,
&$systemErrorsCount,
&$reachedInternalErrorsCountLimit,
$mainScript,
$input,
$serverPort,
$streamSelectLoop,
$timeoutInSeconds,
$handleErrorCallable,
&$fileChunksBudgetPerProcess,
&$processSpawner
): void {
$processIdentifier = Random::generate();
$workerCommandLine = $this->workerCommandLineFactory->create(
$mainScript,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\CodeQuality\Rector\If_;

use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
Expand Down Expand Up @@ -193,6 +192,6 @@ private function haveNestedTernary(array $nodes): bool
private function isNodeTooLong(Assign $assign): bool
{
$assignContent = $this->betterStandardPrinter->print($assign);
return Strings::length($assignContent) > self::LINE_LENGTH_LIMIT;
return strlen($assignContent) > self::LINE_LENGTH_LIMIT;
}
}
2 changes: 1 addition & 1 deletion rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function resolveName(string $prefix, string $tag, UseUse $useUse): strin
return $prefix . $originalUseUseNode->name->toString();
}

$unaliasedShortClass = Strings::substring($tag, Strings::length($originalUseUseNode->alias->toString()));
$unaliasedShortClass = Strings::substring($tag, strlen($originalUseUseNode->alias->toString()));
if (\str_starts_with($unaliasedShortClass, '\\')) {
return $prefix . $originalUseUseNode->name . $unaliasedShortClass;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\Php74\Rector\LNumber;

use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\LNumber;
Expand Down Expand Up @@ -169,7 +168,7 @@ private function shouldSkip(LNumber | DNumber $node, mixed $rawValue): bool
}

// too short
return Strings::length($rawValue) <= self::GROUP_SIZE;
return strlen($rawValue) <= self::GROUP_SIZE;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Application/FileProcessor/PhpFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ private function printFile(File $file, Configuration $configuration): void
* On printing, the space may be wiped, these below check compare with original file content used to verify
* that no change actually needed
*/
if (! $file->getFileDiff() instanceof FileDiff && current($file->getNewStmts()) instanceof FileWithoutNamespace) {
if (! $file->getFileDiff() instanceof FileDiff && current(
$file->getNewStmts()
) instanceof FileWithoutNamespace) {
/**
* Handle new line or space before <?php or InlineHTML node wiped on print format preserving
* On very first content level
Expand Down

0 comments on commit b5c8f9a

Please sign in to comment.