Corrections documentation

master
Julien Rosset 2 years ago
parent ddb2a7d4b5
commit f641fb26eb

@ -50,7 +50,7 @@ trait TMonologApplication {
* *
* @return $this * @return $this
*/ */
public function setLogMainDirectory (string $logMainDirectory): self { public function setLogMainDirectory (string $logMainDirectory): static {
$this->logMainDirectory = $logMainDirectory; $this->logMainDirectory = $logMainDirectory;
return $this; return $this;
} }

@ -31,8 +31,10 @@ class OutputWithLogger extends OutputWrapper {
* *
* @param OutputInterface $output The real output interface * @param OutputInterface $output The real output interface
* @param TLogger|null $logger The logger * @param TLogger|null $logger The logger
*
* @noinspection PhpDocSignatureInspection
*/ */
public function __construct (OutputInterface $output, $logger = null) { public function __construct (OutputInterface $output, LoggerInterface $logger = null) {
parent::__construct($output); parent::__construct($output);
$this->setLogger($logger); $this->setLogger($logger);
} }
@ -53,12 +55,10 @@ class OutputWithLogger extends OutputWrapper {
* @return $this * @return $this
* *
* @throws InvalidArgumentException If the logger is not null or an instance for {@see LoggerInterface} * @throws InvalidArgumentException If the logger is not null or an instance for {@see LoggerInterface}
*
* @noinspection PhpDocSignatureInspection
*/ */
public function setLogger ($logger): self { public function setLogger (LoggerInterface $logger): self {
if ($logger !== null && !$logger instanceof LoggerInterface) {
throw new InvalidArgumentException('The logger must be null or a ' . LoggerInterface::class . ' instance');
}
$this->logger = $logger; $this->logger = $logger;
return $this; return $this;
} }
@ -118,8 +118,8 @@ class OutputWithLogger extends OutputWrapper {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function writeLn (iterable|string $messages, int $options = 0) { public function writeln (iterable|string $messages, int $options = 0) {
$this->writeToLogger($messages, true, $options); $this->writeToLogger($messages, true, $options);
return parent::writeLn($messages, $options); return parent::writeln($messages, $options);
} }
} }

@ -2,7 +2,6 @@
namespace jrosset\CliProgram\Output; namespace jrosset\CliProgram\Output;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -19,7 +18,6 @@ abstract class OutputWrapper implements OutputInterface {
* Initialization * Initialization
* *
* @param OutputInterface $output The real output interface * @param OutputInterface $output The real output interface
* @param LoggerInterface|null $logger The logger
*/ */
public function __construct (OutputInterface $output) { public function __construct (OutputInterface $output) {
$this->output = $output; $this->output = $output;

@ -4,7 +4,7 @@ namespace jrosset\Tests\Commands;
use DateTimeImmutable; use DateTimeImmutable;
use DateTimeInterface; use DateTimeInterface;
use jrosset\CliProgram\Monolog\ConsoleOutputWithMonolog; use jrosset\CliProgram\Output\OutputWithLogger;
use jrosset\CliProgram\Validation\CommandWithValidation; use jrosset\CliProgram\Validation\CommandWithValidation;
use jrosset\CliProgram\Validation\Validators\DateValidator; use jrosset\CliProgram\Validation\Validators\DateValidator;
use jrosset\CliProgram\Validation\Validators\EnumValidator; use jrosset\CliProgram\Validation\Validators\EnumValidator;
@ -65,7 +65,7 @@ class Hello extends CommandWithValidation {
* @inheritDoc * @inheritDoc
*/ */
protected function execute (InputInterface $input, OutputInterface $output): int { protected function execute (InputInterface $input, OutputInterface $output): int {
$output->writeln('Command : ' . __CLASS__, OutputInterface::VERBOSITY_DEBUG); $output->writeln('<info>Command : ' . __CLASS__ . '</info>', OutputInterface::VERBOSITY_DEBUG);
$text = ($input->getOption('lang') ?? Lang::English)->value; $text = ($input->getOption('lang') ?? Lang::English)->value;
$repeat = $input->getOption('repeat'); $repeat = $input->getOption('repeat');
@ -79,7 +79,7 @@ class Hello extends CommandWithValidation {
for ($curr = 0; $curr < $repeat; $curr++) { for ($curr = 0; $curr < $repeat; $curr++) {
$output->writeln($text); $output->writeln($text);
} }
$output->writeln('FIN', ConsoleOutputWithMonolog::OPTION_SKIP_LOGGER); $output->writeln('FIN', OutputWithLogger::OPTION_SKIP_LOGGER);
return Command::SUCCESS; return Command::SUCCESS;
} }
} }
Loading…
Cancel
Save