mirror of
https://github.com/Dannecron/test-php8-attributes.git
synced 2025-12-25 13:22:34 +03:00
php8-style constuctors
This commit is contained in:
2
cli.php
2
cli.php
@@ -6,8 +6,8 @@ $jokeGuzzle = new \GuzzleHttp\Client([
|
||||
'base_uri' => 'https://v2.jokeapi.dev',
|
||||
]);
|
||||
|
||||
$jokeService = new \App\Service\JokeService($jokeGuzzle);
|
||||
$cache = new \Sarahman\SimpleCache\FileSystemCache(__DIR__ . '/tmp/cache');
|
||||
$jokeService = new \App\Service\JokeService($jokeGuzzle);
|
||||
$jokeOperation = new \App\Operation\JokeOperation($jokeService, $cache);
|
||||
|
||||
$app = new \Ahc\Cli\Application('Joke App', 'v0.0.1');
|
||||
|
||||
@@ -8,13 +8,10 @@ use App\Operation\JokeOperation;
|
||||
|
||||
class JokeCommand extends \Ahc\Cli\Input\Command
|
||||
{
|
||||
private JokeOperation $jokeOperation;
|
||||
|
||||
public function __construct(JokeOperation $jokeOperation)
|
||||
{
|
||||
public function __construct(
|
||||
private JokeOperation $jokeOperation
|
||||
) {
|
||||
parent::__construct('joke', 'Get some joke');
|
||||
|
||||
$this->jokeOperation = $jokeOperation;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
|
||||
@@ -10,13 +10,10 @@ use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
class JokeOperation
|
||||
{
|
||||
protected JokeInterface $jokeService;
|
||||
protected CacheInterface $cache;
|
||||
|
||||
public function __construct(JokeInterface $jokeService, CacheInterface $cache)
|
||||
{
|
||||
$this->jokeService = $jokeService;
|
||||
$this->cache = $cache;
|
||||
public function __construct(
|
||||
protected JokeInterface $jokeService,
|
||||
protected CacheInterface $cache
|
||||
) {
|
||||
}
|
||||
|
||||
public function getRandomJoke(): string
|
||||
|
||||
@@ -12,11 +12,9 @@ use Psr\Http\Message\ResponseInterface;
|
||||
*/
|
||||
class JokeService implements JokeInterface
|
||||
{
|
||||
protected \GuzzleHttp\Client $guzzleClient;
|
||||
|
||||
public function __construct(\GuzzleHttp\Client $guzzleClient)
|
||||
{
|
||||
$this->guzzleClient = $guzzleClient;
|
||||
public function __construct(
|
||||
protected \GuzzleHttp\Client $guzzleClient
|
||||
) {
|
||||
}
|
||||
|
||||
#[CachedJokes]
|
||||
|
||||
Reference in New Issue
Block a user