Project

General

Profile

« Previous | Next » 

Revision 875221b6

Added by Reid Linnemann over 2 years ago

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.

View differences:

rector.php
37 37
     */ 
38 38

  
39 39
	$rectorConfig->ruleWithConfiguration(Rules\ArrayGetExprRector::class,
40
										 ['g' => 'g_get']);
40
										 ['g' => 'g_get',
41
										  'config' => 'config_get_path']);
41 42

  
42 43
};

Also available in: Unified diff