Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 18, 2025

Problem

The NodeExpressionResolver was throwing an exception when parsing methods or functions with parameters that use the new keyword for default values:

public function deactivateSeries(\DateTimeImmutable $today = new \DateTimeImmutable('today')): bool
{
    return true;
}

Error:

Go\ParserReflection\ReflectionException: Could not find handler for the 
Go\ParserReflection\Resolver\NodeExpressionResolver::resolveExprNew method

Root Cause

The NodeExpressionResolver class uses a dynamic dispatch pattern to handle different AST node types from PHP-Parser. When it encountered an Expr\New_ node (representing object instantiation with the new keyword), it attempted to call a resolveExprNew() method that didn't exist.

Solution

Added the missing resolveExprNew() method to handle new expression nodes. The implementation:

  1. Resolves the class name from the AST node (handles both direct class names and dynamic expressions)
  2. Resolves constructor arguments recursively (supports both positional and named arguments)
  3. Instantiates the class using PHP's native ReflectionClass::newInstance() for safe object creation

The implementation follows the same pattern as other expression resolvers in the class (e.g., resolveExprFuncCall()) and matches PHP's native reflection behavior—calling getDefaultValue() on a parameter with a new expression returns an actual instance of the object.

Examples

After this fix, the following code patterns are now supported:

// DateTimeImmutable with constructor arguments
public function method(\DateTimeImmutable $today = new \DateTimeImmutable('today')): bool

// DateTime with specific date
public function method(\DateTime $date = new \DateTime('2023-01-01')): void

// stdClass without arguments
public function method(\stdClass $obj = new \stdClass()): void

Testing

Added comprehensive test coverage:

  • 3 unit tests in NodeExpressionResolverTest.php for different instantiation scenarios
  • 1 integration test in ReflectionParameterTest.php for parameter default values
  • New test stub file FileWithNewExpressionDefaults.php with realistic examples

All changes follow the minimal change principle and existing code patterns in the repository.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/nette/tracy/zipball/32303e02c222eea8571402a8310fc3fe70422c37
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/nikic/PHP-Parser/zipball/f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/phpstan/phpstan/zipball/2770dcdf5078d0b0d53f94317e06affe88419aa8
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/KlQHG7 /usr/bin/composer install --prefer-source --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/rectorphp/rector-php-parser/zipball/9c21f5f57464fc5af8765a1007eced8f7f62677c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/rectorphp/rector/zipball/40f9cf38c05296bd32f444121336a521a293fa61
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/15c5dd40dc4f38794d383bb95465193f5e0ae180
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/183a9b2632194febd219bb9246eee421dad8d45e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit/zipball/54391c61e4af8078e5b276ab082b6d3c54c9ad64
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/comparator/zipball/85c77556683e6eee4323e4c5468641ca0237e2e8
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/complexity/zipball/ee41d384ab1906c68852636b6de493846e13e5a0
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/a5c75038693ad2e8d4b6c15ba2403532647830c4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/70a298763b40b213ec087c51c739efcaa90bcd74
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/3be331570a721f9a4b5917f4209773de17f747d7
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/d36ad0d782e5756913e42ad87cb2890f4ffe467a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f5b498e631a74204185071eb41f33f38d64608aa
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/6e1a43b411b2ad34146dee7524cb13a068bb35f9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4f7722aa9a7b76aa775e2d9d4e95d1ea16eeeef4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/118cfaaa8bc5aef3287bf315b6060b1174754af6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/c1ca3814734c07492b3d4c5f794f4b0995333da2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/3e0404dc6b300e6bf56415467ebcb3fe4f33e964
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3b415def83fbcb41f991d9ebf16ae4ad8b7837b3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c6cb5dfe412af3d0dfd414cfd110e3b9cfdbc3c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/f6458abbf32a6c8174f8f26261475dc133b3d9dc
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/f77d2d4e78738c98d9a68d2596fe5e8fa380f449
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c687e3387b99f5b03b6caa64c74b63e2936ff874
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/staabm/side-effects-detector/zipball/d8334211a140ce329c13726d4a715adbddd0a163
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)
  • https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/V9p4m0 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/pyhet7 /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/2odKxQ /usr/bin/composer require --dev phpunit/phpunit --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Could not find handler for the Go\ParserReflection\Resolver\NodeExpressionResolver::resolveExprNew method</issue_title>
<issue_description>Similar to #140, there is an issue when parsing a function containing an argument with a new expression.

public function deactivateSeries(\DateTimeImmutable $today = new \DateTimeImmutable('today')): bool
{
   ....
}
Go\ParserReflection\ReflectionException : Could not find handler for the Go\\ParserReflection\\Resolver\\NodeExpressionResolver::resolveExprNew method
 \src\Resolver\NodeExpressionResolver.php:171
 \src\Resolver\NodeExpressionResolver.php:150
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

Fixes #153


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Oct 18, 2025
Copilot AI changed the title [WIP] Fix handler not found for NodeExpressionResolver resolveExprNew method Fix: Add support for new expressions in parameter default values Oct 18, 2025
Copilot AI requested a review from lisachenko October 18, 2025 18:51
@lisachenko lisachenko marked this pull request as ready for review October 18, 2025 18:53
@lisachenko lisachenko merged commit dcd0363 into master Oct 18, 2025
8 of 12 checks passed
@lisachenko lisachenko deleted the copilot/fix-node-expression-resolver branch October 18, 2025 18:55
@scrutinizer-notifier
Copy link

The inspection completed: No new issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Could not find handler for the Go\ParserReflection\Resolver\NodeExpressionResolver::resolveExprNew method

3 participants