Skip to content

Commit

Permalink
change getLine to aliased getStartLine for php-parser v5 compat prepa…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
kkmuffme committed Feb 18, 2024
1 parent cc5800c commit 3d4111e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public static function getDynamicHookName( object $arg ) : ?string {

if ( $arg instanceof PhpParser\Node\Expr\StaticCall ) {
if ( ! $arg->name instanceof PhpParser\Node\Identifier ) {
throw new UnexpectedValueException( 'Unsupported dynamic hook name with name type ' . get_class( $arg->name ) . ' on line ' . $arg->getLine(), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with name type ' . get_class( $arg->name ) . ' on line ' . $arg->getStartLine(), 0 );
}

// hook name with Foo:bar()
Expand All @@ -436,7 +436,7 @@ public static function getDynamicHookName( object $arg ) : ?string {
// need to check recursively
$temp = static::getDynamicHookName( $arg->class );
if ( is_null( $temp ) ) {
throw new UnexpectedValueException( 'Unsupported dynamic hook name with class type ' . get_class( $arg->class ) . ' on line ' . $arg->getLine(), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with class type ' . get_class( $arg->class ) . ' on line ' . $arg->getStartLine(), 0 );
}

$append_method_call = '()';
Expand All @@ -445,13 +445,13 @@ public static function getDynamicHookName( object $arg ) : ?string {

if ( $arg instanceof PhpParser\Node\Expr\PropertyFetch || $arg instanceof PhpParser\Node\Expr\MethodCall ) {
if ( ! $arg->name instanceof PhpParser\Node\Identifier ) {
throw new UnexpectedValueException( 'Unsupported dynamic hook name with name type ' . get_class( $arg->name ) . ' on line ' . $arg->getLine(), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with name type ' . get_class( $arg->name ) . ' on line ' . $arg->getStartLine(), 0 );
}

// need to check recursively
$temp = static::getDynamicHookName( $arg->var );
if ( is_null( $temp ) ) {
throw new UnexpectedValueException( 'Unsupported dynamic hook name with var type ' . get_class( $arg->var ) . ' on line ' . $arg->getLine(), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with var type ' . get_class( $arg->var ) . ' on line ' . $arg->getStartLine(), 0 );
}

$append_method_call = $arg instanceof PhpParser\Node\Expr\MethodCall ? '()' : '';
Expand All @@ -467,13 +467,13 @@ public static function getDynamicHookName( object $arg ) : ?string {
if ( $arg instanceof PhpParser\Node\Expr\ArrayDimFetch ) {
$key_hook_name = static::getDynamicHookName( $arg->dim );
if ( is_null( $key_hook_name ) ) {
throw new UnexpectedValueException( 'Unsupported dynamic hook name with key type ' . get_class( $arg->dim ) . ' on line ' . $arg->getLine(), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with key type ' . get_class( $arg->dim ) . ' on line ' . $arg->getStartLine(), 0 );
}

// need to check recursively
$temp = static::getDynamicHookName( $arg->var );
if ( is_null( $temp ) ) {
throw new UnexpectedValueException( 'Unsupported dynamic hook name with var type ' . get_class( $arg->var ) . ' on line ' . $arg->getLine(), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with var type ' . get_class( $arg->var ) . ' on line ' . $arg->getStartLine(), 0 );
}

if ( $key_hook_name[0] === '{' ) {
Expand All @@ -495,7 +495,7 @@ public static function getDynamicHookName( object $arg ) : ?string {

// other types not supported yet
// add handling if encountered @todo
throw new UnexpectedValueException( 'Unsupported dynamic hook name with type ' . get_class( $arg ) . ' on line ' . $arg->getLine(), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with type ' . get_class( $arg ) . ' on line ' . $arg->getStartLine(), 0 );
}

/**
Expand Down Expand Up @@ -1318,13 +1318,13 @@ public function enterNode( PhpParser\Node $node ) {
];

// see visitor.php for original code
if ( ( $this->useNamespace !== '' || $this->useStatements !== [] || $this->useStatementsNonClass !== false ) && $this->maxLine > $node->getLine() ) {
if ( ( $this->useNamespace !== '' || $this->useStatements !== [] || $this->useStatementsNonClass !== false ) && $this->maxLine > $node->getStartLine() ) {
$this->useNamespace = '';
$this->useStatements = [];
$this->useStatementsNonClass = false;
}

$this->maxLine = $node->getLine();
$this->maxLine = $node->getStartLine();

if ( $node instanceof Namespace_ ) {
// as soon as there is a new namespace, we need to empty the useStatements, as there will be new ones for the given namespace
Expand Down

0 comments on commit 3d4111e

Please sign in to comment.