Skip to content

Commit

Permalink
add line number for errors for better error reports/easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Feb 5, 2024
1 parent 40ccf0a commit cc5800c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 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 ), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with name type ' . get_class( $arg->name ) . ' on line ' . $arg->getLine(), 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 ), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with class type ' . get_class( $arg->class ) . ' on line ' . $arg->getLine(), 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 ), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with name type ' . get_class( $arg->name ) . ' on line ' . $arg->getLine(), 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 ), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with var type ' . get_class( $arg->var ) . ' on line ' . $arg->getLine(), 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 ), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with key type ' . get_class( $arg->dim ) . ' on line ' . $arg->getLine(), 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 ), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with var type ' . get_class( $arg->var ) . ' on line ' . $arg->getLine(), 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 ), 0 );
throw new UnexpectedValueException( 'Unsupported dynamic hook name with type ' . get_class( $arg ) . ' on line ' . $arg->getLine(), 0 );
}

/**
Expand Down

0 comments on commit cc5800c

Please sign in to comment.