pfsense/rector.php
Reid Linnemann 875221b639 ArrayGetExprRector support for variable and funccall array keys
Change how buildPathArgNode() generates an Arg node - as we introduce support
for more complicated expressions in array keys to be converted to string path
expressions, a simple implode() is no longer sufficient. The following changes
are introduced:

 * buildPathStringNode() function added that aggregates successive string keys
   into a single delimited path String_ node
 * buildPathStringEncapsedNode() function added that uses buildPathStringNode to
   generate EncapsedStringPart nodes, aggregating them along with successive
   Variables and String_s as parts in an Encapsed node, adding delimiters as
   appropriate to String_ parts
 * buildPathEncapsedOrStringNode() function added that builds either a plain
   String_ or Encapsed node as appropriate from the consumed nodes
 * buildPathConcatNode() function added which creates a string Concat node from
   the first node and second node in the list, aggregating the second node on
   into either a String_ or Encapsed node with helpers as appropriate
 * appendDelimiter() and prependDelimiter() functions added that will prepend or
   append a delimiter to a String_ or to the appropriate part of an Encapsed
   node, creating an additional String_ part if necessary for it
 * buildPathArgNode() is modified to generate a String_, Encapsed, or Concat
   root node as appropriate depending on the input nodes, and properly nest
   Concat nodes into a root Concat node until all input nodes have been consumed
   by helpers

With these changes additional tests are provided to validate the desired output
is generated for a number of cases, using the variable 'config' for reference
fixtures.
2023-03-20 14:14:20 +00:00

44 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Tools\Rector\Rector\Rules;
return static function (RectorConfig $rectorConfig): void {
// Recursively check these paths...
$rectorConfig->paths([
__DIR__ . '/src',
]);
// for files with these extensions...
$rectorConfig->fileExtensions([
'php',
'inc',
]);
// while skipping third-pary code that isn't our concern.
$rectorConfig->skip([
__DIR__ . '/src/usr/local/pfSense/include/vendor/*',
__DIR__ . '/src/etc/inc/priv.defs.inc',
]);
/*
* Register Rector rules or rulesets here
*
* See https://github.com/rectorphp/rector#running-rector
*
* Place custom Rectors in tools/rector/src/Rector named
* SomeDescriptiveNameRector.php namespaced as "Tools\Rector\Rector".
* Class should be "final" qualified, extend AbstractRector
* and the same name as the filename.
*
* See https://github.com/rectorphp/rector/blob/main/docs/create_own_rule.md
*/
$rectorConfig->ruleWithConfiguration(Rules\ArrayGetExprRector::class,
['g' => 'g_get',
'config' => 'config_get_path']);
};