PHP 8.2.31
Preview: StrictArraySearchRector.php Size: 1.21 KB
//opt/cpanel/ea-wappspector/vendor/rector/rector/rules/CodingStyle/Rector/FuncCall/StrictArraySearchRector.php

<?php

declare (strict_types=1);
namespace Rector\CodingStyle\Rector\FuncCall;

use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
 * @see \Rector\Tests\CodingStyle\Rector\FuncCall\StrictArraySearchRector\StrictArraySearchRectorTest
 */
final class StrictArraySearchRector extends AbstractRector
{
    public function getRuleDefinition() : RuleDefinition
    {
        return new RuleDefinition('Makes array_search search for identical elements', [new CodeSample('array_search($value, $items);', 'array_search($value, $items, true);')]);
    }
    /**
     * @return array<class-string<Node>>
     */
    public function getNodeTypes() : array
    {
        return [FuncCall::class];
    }
    /**
     * @param FuncCall $node
     */
    public function refactor(Node $node) : ?Node
    {
        if (!$this->isName($node, 'array_search')) {
            return null;
        }
        if (\count($node->args) === 2) {
            $node->args[2] = $this->nodeFactory->createArg($this->nodeFactory->createTrue());
            return $node;
        }
        return null;
    }
}

Directory Contents

Dirs: 0 × Files: 8

Name Size Perms Modified Actions
5.67 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
3.52 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
2.37 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
2.59 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
5.74 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
2.99 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
1.21 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
3.85 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).