Closed mikysetiawan closed 5 months ago
Hey. Feel free to send a PR
The error occurs because for some class nodes, the namespacedName property is null, indicating that these class nodes do not have a fully qualified name. This could happen if the class does not have a namespace defined, or if there is an issue with the way the AST is generated or traversed.
Could you provide more info about file on which the error occured?
I am encountering an issue with the matchish/laravel-scout-elasticsearch
package when running the php artisan scout:import
command. The error message I receive is:
Error: Call to a member function toCodeString() on null
This error occurs at the following line of code in the SearchableListFactory.php
file:
return $node->namespacedName->toCodeString();
From my understanding, it seems that namespacedName
is null
for some $node
objects, and therefore, calling toCodeString()
on it results in an error.
php artisan scout:import
command.The command should execute successfully, without any errors.
I get the error Error: Call to a member function toCodeString() on null
.
matchish/laravel-scout-elasticsearch
package version: ^7.2I have tried re-installing the package, moving non-class PHP files to a different location, and updating the composer.json file's autoload files array. Additionally, I have checked all models in the App
namespace, and all of them have the class defined and no files are missing the class definition. However, none of these steps have resolved the issue.
PS ...\logisticapi> php artisan scout:import
Error
Call to a member function toCodeString() on null
at ...\vendor\matchish\laravel-scout-elasticsearch\src\Searchable\SearchableListFactory.php:110
106▕ return $node instanceof Class_;
107▕ });
108▕
109▕ return Collection::make($nodes)->map(function ($node) {
➜ 110▕ return $node->namespacedName->toCodeString();
111▕ });
112▕ }
113▕
114▕ /**
1 [internal]:0
Matchish\ScoutElasticSearch\Searchable\SearchableListFactory::Matchish\ScoutElasticSearch\Searchable\{closure}(Object(PhpParser\Node\Stmt\Class_))
2 ...\vendor\laravel\framework\src\Illuminate\Collections\Arr.php:560
array_map(Object(Closure))
We had the same error today. The problem was that we used anonymous classes in our code base. By replacing them with generic new stdClass()
we fixed the problem. This is quite an ugly solution, but it works.
I hope this helps anyone having the same error.
@Ecsodikas thanks for sharing yours findings. don't remember details but yes anonymous classes not supported to be able to search by multiple models as I remember.
Describe the bug Error when I want to running scout:import: Call to a member function toCodeString() on null
at ....\vendor\matchish\laravel-scout-elasticsearch\src\Searchable\SearchableListFactory.php:110
To Reproduce Steps to reproduce the behavior:
curl -u elastic:password -XDELETE http://localhost:9200/INDEX_NAME
php artisan scout:import
Expected behavior No error
Version Laravel 9.19 Laravel Scout Elasticsearch 7.2.1