Corrections documentation

master
Julien Rosset 2 years ago
parent ddb2a7d4b5
commit f641fb26eb

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

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

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

@ -4,7 +4,7 @@ namespace jrosset\Tests\Commands;
use DateTimeImmutable;
use DateTimeInterface;
use jrosset\CliProgram\Monolog\ConsoleOutputWithMonolog;
use jrosset\CliProgram\Output\OutputWithLogger;
use jrosset\CliProgram\Validation\CommandWithValidation;
use jrosset\CliProgram\Validation\Validators\DateValidator;
use jrosset\CliProgram\Validation\Validators\EnumValidator;
@ -65,7 +65,7 @@ class Hello extends CommandWithValidation {
* @inheritDoc
*/
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;
$repeat = $input->getOption('repeat');
@ -79,7 +79,7 @@ class Hello extends CommandWithValidation {
for ($curr = 0; $curr < $repeat; $curr++) {
$output->writeln($text);
}
$output->writeln('FIN', ConsoleOutputWithMonolog::OPTION_SKIP_LOGGER);
$output->writeln('FIN', OutputWithLogger::OPTION_SKIP_LOGGER);
return Command::SUCCESS;
}
}
Loading…
Cancel
Save