What is the reason for such tightly coupled classes; are you missing an abstraction?
Oct 22, 2023
6
Level 1
DI recursion
It so happened that I created two classes that have mutual dependencies. I can’t detect this in any way, so is there any way to catch such an error?
The Docker container stops with status 255, and there are no logs - neither in the container nor in the framework's storage.
How to reproduce?
Just create two classes like that
<?php
namespace App\Services;
class ClassOne
{
public function __construct(
protected ClassTwo $class,
) {
//
}
}
and another one
<?php
namespace App\Services;
class ClassTwo
{
public function __construct(
protected ClassOne $class,
) {
//
}
}
Then make command and bind the classes
<?php
namespace App\Console\Commands;
use App\Services\ClassOne;
use App\Services\ClassTwo;
use Illuminate\Console\Command;
class AnyCommand extends Command
{
protected $signature = 'any:command';
public function handle(ClassOne $one, ClassTwo $two)
{
//
}
}
And run command:
docker compose exec app php artisan any:command
There nothing in console, just exit,
Command echo $? returns 255
Please or to participate in this conversation.