Git Product home page Git Product logo

Comments (5)

Ecsodikas avatar Ecsodikas commented on July 18, 2024 1

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.

from laravel-scout-elasticsearch.

matchish avatar matchish commented on July 18, 2024 1

@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.

from laravel-scout-elasticsearch.

matchish avatar matchish commented on July 18, 2024

Hey. Feel free to send a PR

from laravel-scout-elasticsearch.

matchish avatar matchish commented on July 18, 2024

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?

from laravel-scout-elasticsearch.

hanifqas avatar hanifqas commented on July 18, 2024

Issue: Error: Call to a member function toCodeString() on null

Description

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.

Steps to reproduce the issue

  1. Run the php artisan scout:import command.

Expected Result

The command should execute successfully, without any errors.

Actual Result

I get the error Error: Call to a member function toCodeString() on null.

Additional Information

  • Laravel version: 9.52
  • PHP version: 8.1
  • matchish/laravel-scout-elasticsearch package version: ^7.2

I 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.

Screenshots

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))

from laravel-scout-elasticsearch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.