Skip to content

Commit

Permalink
Merge pull request #336 from jolicode/code-grooming
Browse files Browse the repository at this point in the history
chore: fix BC break about VerbosityLevel
  • Loading branch information
pyrech committed Mar 21, 2024
2 parents 811d46f + 213fea1 commit 0dd4eb7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Context.php
Expand Up @@ -3,6 +3,7 @@
namespace Castor;

use Castor\Console\Output\VerbosityLevel;
use Castor\VerbosityLevel as LegacyVerbosityLevel;

class Context implements \ArrayAccess
{
Expand All @@ -23,7 +24,7 @@ public function __construct(
public readonly bool $quiet = false,
public readonly bool $allowFailure = false,
public readonly bool $notify = false,
public readonly VerbosityLevel $verbosityLevel = VerbosityLevel::NOT_CONFIGURED,
public readonly VerbosityLevel|LegacyVerbosityLevel $verbosityLevel = VerbosityLevel::NOT_CONFIGURED,
// Do not use this argument, it is only used internally by the application
public readonly string $name = '',
) {
Expand Down Expand Up @@ -225,7 +226,7 @@ public function withNotify(bool $notify = true): self
);
}

public function withVerbosityLevel(VerbosityLevel $verbosityLevel): self
public function withVerbosityLevel(VerbosityLevel|LegacyVerbosityLevel $verbosityLevel): self
{
return new self(
$this->data,
Expand Down
56 changes: 56 additions & 0 deletions src/VerbosityLevel.php
@@ -0,0 +1,56 @@
<?php

namespace Castor;

use Symfony\Component\Console\Output\OutputInterface;

trigger_deprecation('castor/console', '0.15', 'The "%s" enum is deprecated and will be removed in 1.0. Use "%s" instead.', VerbosityLevel::class, Console\Output\VerbosityLevel::class);

/**
* @deprecated since castor/console 0.15, to be removed in 1.0. Use \Castor\Console\Output\VerbosityLevel instead.
*/
enum VerbosityLevel: int
{
case NOT_CONFIGURED = -1;
case QUIET = 0;
case NORMAL = 1;
case VERBOSE = 2;
case VERY_VERBOSE = 3;
case DEBUG = 4;

public static function fromSymfonyOutput(OutputInterface $output): self
{
return match ($output->getVerbosity()) {
OutputInterface::VERBOSITY_QUIET => self::QUIET,
OutputInterface::VERBOSITY_NORMAL => self::NORMAL,
OutputInterface::VERBOSITY_VERBOSE => self::VERBOSE,
OutputInterface::VERBOSITY_VERY_VERBOSE => self::VERY_VERBOSE,
OutputInterface::VERBOSITY_DEBUG => self::DEBUG,
};
}

public function isNotConfigured(): bool
{
return self::NOT_CONFIGURED === $this;
}

public function isQuiet(): bool
{
return self::QUIET->value === $this->value;
}

public function isVerbose(): bool
{
return self::VERBOSE->value <= $this->value;
}

public function isVeryVerbose(): bool
{
return self::VERY_VERBOSE->value <= $this->value;
}

public function isDebug(): bool
{
return self::DEBUG->value <= $this->value;
}
}

0 comments on commit 0dd4eb7

Please sign in to comment.