Skip to content

Commit

Permalink
Modernize Deployer.php
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Oct 27, 2024
1 parent 1e78e77 commit 38eb101
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions src/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
use Throwable;

/**
* Deployer class represents DI container for configuring
*
* @property Application $console
* @property InputInterface $input
* @property OutputInterface $output
Expand All @@ -74,9 +72,6 @@
*/
class Deployer extends Container
{
/**
* Global instance of deployer. It's can be accessed only after constructor call.
*/
private static Deployer $instance;

public function __construct(Application $console)
Expand Down Expand Up @@ -192,10 +187,7 @@ public static function get(): self
return self::$instance;
}

/**
* Init console application
*/
public function init()
public function init(): void
{
$this->addTaskCommands();
$this->getConsole()->add(new BlackjackCommand());
Expand All @@ -218,7 +210,7 @@ public function init()
/**
* Transform tasks to console commands.
*/
public function addTaskCommands()
public function addTaskCommands(): void
{
foreach ($this->tasks as $name => $task) {
$command = new MainCommand($name, $task->getDescription(), $this);
Expand All @@ -228,11 +220,7 @@ public function addTaskCommands()
}
}

/**
* @return mixed
* @throws \InvalidArgumentException
*/
public function __get(string $name)
public function __get(string $name): mixed
{
if (isset($this[$name])) {
return $this[$name];
Expand All @@ -241,10 +229,7 @@ public function __get(string $name)
}
}

/**
* @param mixed $value
*/
public function __set(string $name, $value)
public function __set(string $name, mixed $value): void
{
$this[$name] = $value;
}
Expand All @@ -259,10 +244,7 @@ public function getHelper(string $name): Console\Helper\HelperInterface
return $this->getConsole()->getHelperSet()->get($name);
}

/**
* Run Deployer
*/
public static function run(string $version, ?string $deployFile)
public static function run(string $version, ?string $deployFile): void
{
if (str_contains($version, 'master')) {
// Get version from composer.lock
Expand Down Expand Up @@ -295,7 +277,6 @@ public static function run(string $version, ?string $deployFile)
$output = new ConsoleOutput();

try {
// Init Deployer
$console = new Application('Deployer', $version);
$deployer = new self($console);

Expand All @@ -304,7 +285,6 @@ public static function run(string $version, ?string $deployFile)
$deployer->importer->import($deployFile);
}

// Run Deployer
$deployer->init();
$console->run($input, $output);

Expand All @@ -318,7 +298,7 @@ public static function run(string $version, ?string $deployFile)
}
}

public static function printException(OutputInterface $output, Throwable $exception)
public static function printException(OutputInterface $output, Throwable $exception): void
{
$class = get_class($exception);
$file = basename($exception->getFile());
Expand All @@ -345,11 +325,9 @@ public static function isWorker(): bool
}

/**
* @param mixed ...$arguments
* @return array|bool|string
* @throws \Exception
*/
public static function masterCall(Host $host, string $func, ...$arguments)
public static function masterCall(Host $host, string $func, mixed ...$arguments): mixed
{
// As request to master will stop master permanently, wait a little bit
// in order for ticker gather worker outputs and print it to user.
Expand All @@ -368,6 +346,6 @@ public static function masterCall(Host $host, string $func, ...$arguments)

public static function isPharArchive(): bool
{
return 'phar:' === substr(__FILE__, 0, 5);
return str_starts_with(__FILE__, 'phar:');
}
}

0 comments on commit 38eb101

Please sign in to comment.