Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| HasCommandLogger | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| getLogger | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\Console\Command\Traits; |
| 21 | |
| 22 | use FastForward\DevTools\Container\ContainerFactory; |
| 23 | use Psr\Log\LoggerInterface; |
| 24 | |
| 25 | /** |
| 26 | * Resolves the logger expected by command result helper traits. |
| 27 | * |
| 28 | * The trait caches the shared logger lazily so consuming commands do not need |
| 29 | * to carry constructor wiring for internal logging helpers. |
| 30 | */ |
| 31 | trait HasCommandLogger |
| 32 | { |
| 33 | /** |
| 34 | * Caches the logger resolved for the consuming command. |
| 35 | */ |
| 36 | private ?LoggerInterface $logger = null; |
| 37 | |
| 38 | /** |
| 39 | * Returns the logger configured for the consuming command. |
| 40 | */ |
| 41 | public function getLogger(): LoggerInterface |
| 42 | { |
| 43 | return $this->logger ??= ContainerFactory::get(LoggerInterface::class); |
| 44 | } |
| 45 | } |