Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal error: Internal error: Method newEloquentBuilder() was not found in reflection of class Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants. #233

Closed
marco76tv opened this issue Apr 4, 2024 · 21 comments · Fixed by #256
Labels
help wanted Extra attention is needed

Comments

@marco76tv
Copy link

when running php i get this error

Internal error: Internal error: Method newEloquentBuilder() was not found in reflection of class
Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants.

@staudenmeir
Copy link
Owner

Hi @marco76tv,
Do you get this error when running PHPStan?

What version of laravel-adjacency-list are you using?

@marco76tv
Copy link
Author

yes running with phpstan

larastan/larastan v2.9.2 Larastan

@staudenmeir
Copy link
Owner

What version of laravel-adjacency-list are you using?

@marco76tv
Copy link
Author

staudenmeir/laravel-adjacency-list v1.21

@staudenmeir
Copy link
Owner

What does your PHPStan/Larastan configuration look like?

@marco76tv
Copy link
Author

includes:
- ./vendor/larastan/larastan/extension.neon
- ./phpstan-baseline.neon
- ./vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon

parameters:

level: max

paths:
    - ./Modules
    - ./Themes

ignoreErrors:
    - '#Unsafe usage of new static#'
    - '#Unsafe call to private method#'
    - '#PHPDoc tag @mixin contains unknown class #'
   

excludePaths:
    - ./*/vendor/*
    - ./*/build/*
    - ./*/docs/*
    # - ./*/Tests/*
    - ./*/rector.php
    - ./*/phpinsights.php
    

bootstrapFiles:
    - ./phpstan_constants.php
#    - ./vendor/amenadiel/jpgraph/src/config.inc.php

scanFiles:
    - ./Modules/Xot/Helpers/Helper.php

editorUrl: 'vscode://file/%%file%%:%%line%%'

tmpDir: ./build/phpstan

checkUnusedViews: false
checkModelProperties: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
reportUnmatchedIgnoredErrors: false
checkOctaneCompatibility: false

@staudenmeir
Copy link
Owner

staudenmeir commented Apr 5, 2024

Internal error: Internal error: Method newEloquentBuilder() was not found in reflection of class Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants.

Is that the whole message? Do you see where the error is coming from?

@marco76tv
Copy link
Author


 Error

Internal error: Internal error: Method newEloquentBuilder() was not found in reflection of class
Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants. while analysing file
xxx/xxx/xxx.php
Run PHPStan with -v option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml
Child process error (exit code 1):

@staudenmeir
Copy link
Owner

xxx/xxx/xxx.php

This is the relevant part. What is the content of this file?

@mxaGianluca
Copy link

mxaGianluca commented Apr 15, 2024

Hi @staudenmeir, i've just hit the same issue.

  • larastan (2.9.4)
  • AdjacencyList (1.20)

This is the complete output i'm getting:

 -- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
     Error                                                                                                                                                                         
 -- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
     Internal error: Internal error: Method newEloquentBuilder() was not found in reflection of class Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors. while         
     analysing file {application path omitted}/app/Models/FsDirectory.php                                                                                               
                                                                                                                                                                                   
     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml:                                                                     
     ## phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(558)                                                   
     #0 {application path omitted}/vendor/larastan/larastan/src/Methods/BuilderHelper.php(215):                                                                         
     PHPStan\Reflection\ClassReflection->getNativeMethod('newEloquentBuil...')                                                                                                     
     #1 {application path omitted}/vendor/larastan/larastan/src/Methods/RelationForwardsCallsExtension.php(79):                                                         
     Larastan\Larastan\Methods\BuilderHelper->determineBuilderName('Staudenmeir\\Lar...')                                                                                          
     #2 {application path omitted}/vendor/larastan/larastan/src/Methods/RelationForwardsCallsExtension.php(39):                                                         
     Larastan\Larastan\Methods\RelationForwardsCallsExtension->findMethod(Object(PHPStan\Reflection\ClassReflection), 'breadthFirst')                                              
     #3 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(506):                                                  
     Larastan\Larastan\Methods\RelationForwardsCallsExtension->hasMethod(Object(PHPStan\Reflection\ClassReflection), 'breadthFirst')                                               
     #4 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Type/ObjectType.php(551):                                                             
     PHPStan\Reflection\ClassReflection->hasMethod('breadthFirst')                                                                                                                 
     #5 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3578): PHPStan\Type\ObjectType->hasMethod('breadthFirst')  
     #6 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3606):                                                     
     PHPStan\Analyser\MutatingScope->filterTypeWithMethod(Object(PHPStan\Type\Generic\GenericObjectType), 'breadthFirst')                                                          
     #7 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1417):                                                     
     PHPStan\Analyser\MutatingScope->methodCallReturnType(Object(PHPStan\Type\Generic\GenericObjectType), 'breadthFirst', Object(PhpParser\Node\Expr\MethodCall))                  
     #8 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1423):                                                     
     PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()                                                                                                                  
     #9 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(588):                                                      
     PHPStan\Analyser\MutatingScope->resolveType('$this->ancestor...', Object(PhpParser\Node\Expr\MethodCall))                                                                     
     #10 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionReturnTypeCheck.php(52):                                               
     PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\MethodCall))                                                                                               
     #11 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Methods/ReturnTypeRule.php(43):                                                
     PHPStan\Rules\FunctionReturnTypeCheck->checkReturnType(Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Type\ObjectType), Object(PhpParser\Node\Expr\MethodCall),       
     Object(PhpParser\Node\Stmt\Return_), 'Method App\\Mode...', 'Method App\\Mode...', 'Method App\\Mode...', 'Method App\\Mode...', false)                                       
     #12 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(107):                                                      
     PHPStan\Rules\Methods\ReturnTypeRule->processNode(Object(PhpParser\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope))                                                
     #13 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(108):                                               
     PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope))                                        
     #14 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(586):                                                 
     PHPStan\Node\ClassStatementsGatherer->__invoke(Object(PhpParser\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope))                                                   
     #15 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(477):                                                 
     PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}(Object(PhpParser\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope))                                   
     #16 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(420):                                                 
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope), Object(Closure),                             
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                    
     #17 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(604):                                                 
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure),                 
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                    
     #18 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(420):                                                 
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope),                                          
     Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))                                                                                      
     #19 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(687):                                                 
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope),                                       
     Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))                                                                                      
     #20 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(420):                                                 
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure),                              
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                    
     #21 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(659):                                                 
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure),                  
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                    
     #22 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(389):                                                 
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope), Object(Closure),                          
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                    
     #23 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(166):                                                      
     PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))                                                              
     #24 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(132):                                                      
     PHPStan\Analyser\FileAnalyser->analyseFile('...', Array, Object(PHPStan\Rules\LazyRegistry), Object(PHPStan\Collectors\Registry), NULL)                        
     #25 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                      
     PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)                                                                                                               
     #26 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117):                                           
     _PHPStan_5473b6701\Evenement\EventEmitter->emit('data', Array)                                                                                                                
     #27 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                      
     _PHPStan_5473b6701\Clue\React\NDJson\Decoder->handleData(Array)                                                                                                               
     #28 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62):                                                    
     _PHPStan_5473b6701\Evenement\EventEmitter->emit('data', Array)                                                                                                                
     #29 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                      
     _PHPStan_5473b6701\React\Stream\Util::_PHPStan_5473b6701\React\Stream\{closure}('{"action":"anal...')                                                                         
     #30 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154):                                   
     _PHPStan_5473b6701\Evenement\EventEmitter->emit('data', Array)                                                                                                                
     #31 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201):                                   
     _PHPStan_5473b6701\React\Stream\DuplexResourceStream->handleData(Resource id #6845)                                                                                           
     #32 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173):                                   
     _PHPStan_5473b6701\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)                                                                                              
     #33 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(98):                                                       
     _PHPStan_5473b6701\React\EventLoop\StreamSelectLoop->run()                                                                                                                    
     #34 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259):                                         
     PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_5473b6701\Symfony\Component\Console\Input\ArgvInput),                                                                  
     Object(_PHPStan_5473b6701\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                    
     #35 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870):                                             
     _PHPStan_5473b6701\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_5473b6701\Symfony\Component\Console\Input\ArgvInput),                                       
     Object(_PHPStan_5473b6701\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                    
     #36 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261):                                             
     _PHPStan_5473b6701\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand),                                                                 
     Object(_PHPStan_5473b6701\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_5473b6701\Symfony\Component\Console\Output\ConsoleOutput))                              
     #37 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):                                             
     _PHPStan_5473b6701\Symfony\Component\Console\Application->doRun(Object(_PHPStan_5473b6701\Symfony\Component\Console\Input\ArgvInput),                                         
     Object(_PHPStan_5473b6701\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                    
     #38 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_5473b6701\Symfony\Component\Console\Application->run()        
     #39 phar://{application path omitted}/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_5473b6701\{closure}()                                         
     #40 {application path omitted}/vendor/phpstan/phpstan/phpstan(8): require('phar:///Users/g...')                                                                    
     #41 {application path omitted}/vendor/bin/phpstan(119): include('...')                                                                              
     #42 {main}                                                                                                                                                                    
     Child process error (exit code 1):       

phpstan.neon:

includes:
    - ./vendor/larastan/larastan/extension.neon
    - ./vendor/ekino/phpstan-banned-code/extension.neon
    - ./vendor/bensampo/laravel-enum/extension.neon

parameters:

    paths:
        - app

    # The level 8 is the highest level
    level: 5

    ignoreErrors:

    banned_code:
        nodes:
            -
                type: Stmt_Echo
                functions: null
            -
                type: Expr_Eval
                functions: null
            -
                type: Expr_Exit
                functions: null
            -
                type: Expr_FuncCall
                functions:
                    - dd
                    - debug_backtrace
                    - dump
                    - exec
                    - passthru
                    - phpinfo
                    - print_r
                    - proc_open
                    - shell_exec
                    - system
                    - var_dump

    excludePaths:
        - ./*/*/FileToBeExcluded.php

    checkMissingIterableValueType: false

Hope this helps.

@staudenmeir
Copy link
Owner

@mxaGianluca What does app/Models/FsDirectory.php look like?

@mxaGianluca
Copy link

mxaGianluca commented Apr 15, 2024

@mxaGianluca What does app/Models/FsDirectory.php look like?

I've reduced it to this:

<?php

namespace App\Models;

use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;
use Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors;

class FsDirectory
{
    use HasRecursiveRelationships;

    public function ancestorDirectories(): Ancestors
    {
        return $this->ancestorsAndSelf()
            ->hasParent()
            ->breadthFirst();
    }
}

Removing the ancestorDirectories method will prevent the error from being thrown.

@staudenmeir
Copy link
Owner

Thanks @mxaGianluca. I can reproduce the error, but I don't know what the package can do to prevent it (if it can do anything). It only seems to occur when you call multiple scopes.

@staudenmeir staudenmeir added the help wanted Extra attention is needed label Apr 17, 2024
@mxaGianluca
Copy link

@staudenmeir i'm not 100% sure, but might this issue be related? larastan/larastan#1759

@staudenmeir
Copy link
Owner

staudenmeir commented Apr 17, 2024

@mxaGianluca I've read that, but AFAICT, the package's generics are correct.

Did you just now add the ancestorDirectories() relationship and Larastan/PHPStan failed immediately? Or have you had it in your code for a while and the error only started occurring after a Larastan/PHPStan update?

@mxaGianluca
Copy link

In my specific case i updated from L9 -> L10 and i updated nunomaduro/larastan:2.2 to larastan/larastan:2.9.4.

I didn't have this error in the older version.

It looks like something that should be fixed upstream.

@mxaGianluca
Copy link

It's not a solution yet, but i have a workaround.

public function ancestorDirectories(): Ancestors
{
    return $this
        ->ancestorsAndSelf()
        ->addAncestorConstraints();
}

public function scopeAddAncestorConstraints($query)
{
    $query
        ->hasParent()
        ->breadthFirst();
}

This prevents the error from being thrown.

@SanderMuller
Copy link
Contributor

@mxaGianluca can you check if this error has been resolved since #252 and #255 have been merged? You would have to load this package via dev-main in composer to test this (until a new release is tagged)

If it isn't fixed, then we might have to take a look at improving the scope generics.

@mxaGianluca
Copy link

@SanderMuller it doesn't seem that it has been fixed. I've loaded the package via dev-main but the error remains the same.

Hope this helps.

@SanderMuller
Copy link
Contributor

@SanderMuller it doesn't seem that it has been fixed. I've loaded the package via dev-main but the error remains the same.

Hope this helps.

I know somewhat the area where it's going wrong, but not sure yet why exactly or how to fix it, but I will fiddle with it when I have some spare time!

@staudenmeir this is the WIP: https://github.com/staudenmeir/laravel-adjacency-list/compare/main...SanderMuller:laravel-adjacency-list:fix/issue-233?expand=1 the @mixin in Ancestors turns the fatal error into

 105    Call to an undefined method                                                                                                                                                                                                                            
         Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Ancestors<static(Staudenmeir\LaravelAdjacencyList\Tests\Tree\Models\User)>>>::breadthFirst().  
         🪪  method.notFound   

One step forward, but I don't have an actual fix yet

@staudenmeir
Copy link
Owner

This has been fixed in the latest release thanks to @SanderMuller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants