REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.91 KB
Close
/opt/cpanel/ea-wappspector/vendor/rector/rector/rules/Php74/Rector/FuncCall/MoneyFormatToNumberFormatRector.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\Php74\Rector\FuncCall; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; use Rector\NodeAnalyzer\ArgsAnalyzer; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php74\Rector\FuncCall\MoneyFormatToNumberFormatRector\MoneyFormatToNumberFormatRectorTest */ final class MoneyFormatToNumberFormatRector extends AbstractRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\NodeAnalyzer\ArgsAnalyzer */ private $argsAnalyzer; /** * @readonly * @var \Rector\PhpParser\Node\Value\ValueResolver */ private $valueResolver; public function __construct(ArgsAnalyzer $argsAnalyzer, ValueResolver $valueResolver) { $this->argsAnalyzer = $argsAnalyzer; $this->valueResolver = $valueResolver; } public function provideMinPhpVersion() : int { return PhpVersionFeature::DEPRECATE_MONEY_FORMAT; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Change money_format() to equivalent number_format()', [new CodeSample(<<<'CODE_SAMPLE' $value = money_format('%i', $value); CODE_SAMPLE , <<<'CODE_SAMPLE' $value = number_format(round($value, 2, PHP_ROUND_HALF_ODD), 2, '.', ''); CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [FuncCall::class]; } /** * @param FuncCall $node */ public function refactor(Node $node) : ?FuncCall { if (!$this->isName($node, 'money_format')) { return null; } if ($node->isFirstClassCallable()) { return null; } $args = $node->getArgs(); if ($this->argsAnalyzer->hasNamedArg($args)) { return null; } $formatValue = $args[0]->value; if (!$this->valueResolver->isValue($formatValue, '%i')) { return null; } return $this->warpInNumberFormatFuncCall($node, $args[1]->value); } private function warpInNumberFormatFuncCall(FuncCall $funcCall, Expr $expr) : FuncCall { $roundFuncCall = $this->nodeFactory->createFuncCall('round', [$expr, new LNumber(2), new ConstFetch(new Name('PHP_ROUND_HALF_ODD'))]); $funcCall->name = new Name('number_format'); $funcCall->args = [new Arg($roundFuncCall), new Arg(new LNumber(2)), new Arg(new String_('.')), new Arg(new String_(''))]; return $funcCall; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 6
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
ArrayKeyExistsOnPropertyRector.php
2.01 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
FilterVarToAddSlashesRector.php
1.79 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
HebrevcToNl2brHebrevRector.php
1.52 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
MbStrrposEncodingArgumentPositionRector.php
1.85 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
MoneyFormatToNumberFormatRector.php
2.91 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
RestoreIncludePathToIniRestoreRector.php
1.69 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).