Attempt to read property "methods" on null
Laravel 10.x | Scramble 0.8.5 | PHP 8.3.x
Error occurs when requesting docs/api.json and breaks the loading of the whole docs site:
The getClassDefinition method has a return type of ?ClassDefinition yet the MethodAnalyzer::analyze method does not accommodate for this.
I did some debugging and it seems to be unable to find the ExchangeRateResourceCollection ClassDefinition which is a standard Laravel class that extends Illuminate\Http\Resources\Json\ResourceCollection:
/** @tags Rates */
class ExchangeRatesController extends Controller
{
/**
* Search Rates
*
* @param ?ExchangeRateBook $book Find the current rates for this rate book.
*/
public function __invoke(ExchangeRatesRequest $request, ExchangeRateBook $book = null)
{
$book ??= app(SessionRateBook::class);
/** @var ExchangeRateCollection $rates */
$rates = ExchangeRate::book($book->id)
->base($book->base_currency_id)
->with(['baseCurrency', 'targetCurrency'])
->get()
->sortByTargetCurrencyRanking();
abort_if($rates->isEmpty(), 404);
return new ExchangeRateResourceCollection($rates);
}
}
Hey @dmason30
Can you share the implementation of ExchangeRateResourceCollection?
@romalytvynenko Here it is, it is just used to add some meta data to the collection. i should say this was working fine in a previous version of this package and rendering the docs without issue. This route has not been changed in a couple years.
namespace App\Http\Resources;
use App\Facades\RateConfig;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ExchangeRateResourceCollection extends ResourceCollection
{
public function with($request)
{
$config = RateConfig::driver();
return [
'meta' => [
'operators' => [
'calculation' => [
'charge' => $config->chargeOperator(),
'quantity' => $config->quantityOperator(),
],
'comparison' => [
'gt' => $config->greaterThanOperator(),
'gte' => $config->greaterThanOrEqualToOperator(),
'lt' => $config->lessThanOperator(),
'lte' => $config->lessThanOrEqualToOperator(),
'percentage' => $config->percentage(),
],
],
'templates' => $config->translator()->templates()->toArray(),
],
];
}
}
@dmason30 cannot reproduce. Any chance you can create a simple Laravel project repo with reproduction of this issue?
I have the same problem mentioned here: https://github.com/dedoc/scramble/issues/352
@dmason30 can you please check if the issue persists on v0.10.5?
I tried it and it's still happening... only under octane :(
@rcerljenko yeah, on Octane it still persists. The question here is if it's still happening for @dmason30 as I'm not sure Dan's case is about Octane.
Unfortunately I don't have access to that project anymore (I have changed jobs). There is a chance this was running on octane locally when I encountered the error as we definitely ran it on octane on prod.
@romalytvynenko I can be your production tester if you want. I currently have a project that is active in dev and deployed to Linux Octane prod server
@rcerljenko Nice, thanks! If you can create a repro repo that I can simply install and get this issue – this also would be great 😊
@dmason30 should be fixed in v0.10.7