Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix BC break about VerbosityLevel #336

Merged
merged 1 commit into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}