Skip to content

Commit

Permalink
chore: Apply symfony coding styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Huber committed Dec 8, 2024
1 parent d6368fa commit 41bc84f
Show file tree
Hide file tree
Showing 243 changed files with 2,124 additions and 3,940 deletions.
14 changes: 9 additions & 5 deletions src/AppKernel.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Phabalicious;

use Phabalicious\DependencyInjection\CompilerPass\CollectCommandsToApplicationCompilerPass;
Expand All @@ -18,26 +19,29 @@ public function registerBundles(): iterable
{
return [];
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/../config/services.yml');
$loader->load(__DIR__.'/../config/services.yml');
}

/**
* Unique cache path for this Kernel
* Unique cache path for this Kernel.
*/
public function getCacheDir(): string
{
$dir = implode('-', [
sys_get_temp_dir() . '/phabalicious',
sys_get_temp_dir().'/phabalicious',
Utilities::FALLBACK_VERSION,
posix_getuid(),
md5(self::class)
md5(self::class),
]);

return $dir;
}

/**
* Unique logs path for this Kernel
* Unique logs path for this Kernel.
*/
public function getLogDir(): string
{
Expand Down
9 changes: 4 additions & 5 deletions src/Artifact/Actions/ActionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

abstract class ActionBase implements ActionInterface
{
protected $arguments= [];
protected $arguments = [];

public function setArguments($arguments)
{
$this->arguments = $arguments;
}

protected function getArguments() : array
protected function getArguments(): array
{
return $this->arguments;
}
Expand All @@ -37,7 +37,7 @@ public function validateConfig($host_config, array $action_config, ValidationErr
);
$service->hasKeys([
'action' => 'Every action needs the type of action to perform',
'arguments' => 'Missing arguments for an action'
'arguments' => 'Missing arguments for an action',
]);
if (isset($action_config['arguments'])) {
$service->isArray('arguments', 'arguments need to be an array!');
Expand All @@ -58,7 +58,6 @@ public function validateConfig($host_config, array $action_config, ValidationErr

abstract protected function validateArgumentsConfig(array $action_arguments, ValidationService $validation);


public function run(HostConfig $host_config, TaskContextInterface $context)
{
/** @var ShellProviderInterface $shell */
Expand All @@ -76,7 +75,7 @@ protected function runImplementation(
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
string $target_dir,
) {
throw new \RuntimeException('Missing run implementation');
}
Expand Down
4 changes: 1 addition & 3 deletions src/Artifact/Actions/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

class ActionFactory
{

protected static $availableActions = [];


public static function register($method, $name, $class)
{
self::$availableActions["$method--$name"] = $class;
}

public static function get($method, $name) : ActionInterface
public static function get($method, $name): ActionInterface
{
if (isset(self::$availableActions["$method--$name"])) {
return new self::$availableActions["$method--$name"]();
Expand Down
2 changes: 0 additions & 2 deletions src/Artifact/Actions/Base/ConfirmAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Phabalicious\Artifact\Actions\Base;

use Phabalicious\Artifact\Actions\ActionBase;
Expand All @@ -10,7 +9,6 @@

class ConfirmAction extends ActionBase
{

protected function validateArgumentsConfig(array $action_arguments, ValidationService $validation)
{
$validation->hasKey('question', 'The confirm action needs a question to ask.');
Expand Down
20 changes: 7 additions & 13 deletions src/Artifact/Actions/Base/CopyAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Phabalicious\Artifact\Actions\Base;

use Phabalicious\Artifact\Actions\ActionBase;
Expand All @@ -11,21 +10,16 @@

class CopyAction extends ActionBase
{

protected function validateArgumentsConfig(array $action_arguments, ValidationService $validation)
{
$validation->hasKey('to', 'Copy action needs a to argument');
$validation->hasKey('from', 'Copy action needs a from argument');
}

/**
* @param ShellProviderInterface $shell
* @param $install_dir
* @return array
*/
private function getDirectoryContents(ShellProviderInterface $shell, $install_dir): array
{
$contents = $shell->run('ls -1a ' . $install_dir, true);
$contents = $shell->run('ls -1a '.$install_dir, true);

return array_filter($contents->getOutput(), function ($elem) {
return !in_array($elem, ['.', '..']);
});
Expand All @@ -36,13 +30,13 @@ protected function runImplementation(
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
string $target_dir,
) {
$shell->pushWorkingDir($install_dir);

$files_to_copy = $this->getArgument('from');
if (!is_array($files_to_copy)) {
if ($files_to_copy == '*') {
if ('*' == $files_to_copy) {
$files_to_copy = $this->getDirectoryContents($shell, $install_dir);
} else {
$files_to_copy = [$files_to_copy];
Expand All @@ -52,15 +46,15 @@ protected function runImplementation(
$files_to_skip = $context->getConfigurationService()->getSetting('excludeFiles.gitSync', []);

// Make sure that git-related files are skipped.
$files_to_skip[] = ".git";
$to = $target_dir . '/' . $this->getArgument('to');
$files_to_skip[] = '.git';
$to = $target_dir.'/'.$this->getArgument('to');

// Make sure the target directory exists before copying.
$shell->run(sprintf('mkdir -p %s', $to));

foreach ($files_to_copy as $file) {
if (!in_array($file, $files_to_skip)) {
$shell->run(sprintf('rm -rf %s', $to . '/' . basename($file)));
$shell->run(sprintf('rm -rf %s', $to.'/'.basename($file)));
$shell->run(sprintf('cp -a %s %s', $file, $to));
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Artifact/Actions/Base/DeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class DeleteAction extends ActionBase
{

protected function validateArgumentsConfig(array $action_arguments, ValidationService $validation)
{
}
Expand All @@ -20,13 +19,13 @@ protected function runImplementation(
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
string $target_dir,
) {
$shell->pushWorkingDir($target_dir);

$files_to_delete = $this->getArguments();
foreach ($files_to_delete as $file) {
$full_path = $target_dir . '/' . $file;
$full_path = $target_dir.'/'.$file;
$shell->run(sprintf('rm -rf %s', $full_path));
}

Expand Down
12 changes: 6 additions & 6 deletions src/Artifact/Actions/Base/DockerCopyAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Phabalicious\Artifact\Actions\Base;

use Phabalicious\Artifact\Actions\ActionBase;
Expand Down Expand Up @@ -48,6 +47,7 @@ protected function getDirectoryContents(ShellProviderInterface $shell, string $p
if ($result->failed()) {
$result->throwException('Could not get directory contents from docker image!');
}

return $result->getOutput();
}

Expand All @@ -56,7 +56,7 @@ protected function runImplementation(
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
string $target_dir,
) {
$shell->pushWorkingDir($install_dir);

Expand All @@ -68,7 +68,7 @@ protected function runImplementation(
$files_to_copy = $this->getArgument('from');

if (!is_array($files_to_copy)) {
if ($files_to_copy === '*') {
if ('*' === $files_to_copy) {
$files_to_copy = array_filter(
$this->getDirectoryContents($shell, $image_root_path),
static function ($e) {
Expand All @@ -83,8 +83,8 @@ static function ($e) {
$files_to_skip = $context->getConfigurationService()->getSetting('excludeFiles.gitSync', []);

// Make sure that git-related files are skipped.
$files_to_skip[] = ".git";
$to = $target_dir . '/' . $this->getArgument('to');
$files_to_skip[] = '.git';
$to = $target_dir.'/'.$this->getArgument('to');

// Make sure the target directory exists before copying.
$shell->run(sprintf('mkdir -p %s', $to));
Expand All @@ -93,7 +93,7 @@ static function ($e) {
$shell->run(sprintf('docker create --name %s %s', $docker_container, $this->dockerImageName), RunOptions::NONE, true);
foreach ($files_to_copy as $file) {
if (!in_array($file, $files_to_skip)) {
$shell->run(sprintf('rm -rf %s', $to . '/' . basename($file)));
$shell->run(sprintf('rm -rf %s', $to.'/'.basename($file)));
$shell->run(sprintf('docker cp -a %s:%s/%s %s', $docker_container, $image_root_path, $file, $to));
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/Artifact/Actions/Base/InstallScriptAction.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
<?php


namespace Phabalicious\Artifact\Actions\Base;

use Phabalicious\Artifact\Actions\ActionBase;
use Phabalicious\Configuration\HostConfig;
use Phabalicious\Method\ScriptMethod;
use Phabalicious\Method\TaskContextInterface;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Phabalicious\Validation\ValidationService;

class InstallScriptAction extends ScriptAction
{
public function __construct()
Expand Down
9 changes: 3 additions & 6 deletions src/Artifact/Actions/Base/LogAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@

use Phabalicious\Artifact\Actions\ActionBase;
use Phabalicious\Configuration\HostConfig;
use Phabalicious\Method\ScriptMethod;
use Phabalicious\Method\TaskContextInterface;
use Phabalicious\ShellProvider\CommandResult;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Phabalicious\Validation\ValidationService;
use Psr\Log\LoggerInterface;

class LogAction extends ActionBase
{
const SEVERITY_MAPPINGS = [
public const SEVERITY_MAPPINGS = [
'error' => 'error',
'warning' => 'warning',
'notice' => 'notice',
'info' => 'info',
'debug' => 'debug'
'debug' => 'debug',
];

public function __construct()
Expand All @@ -41,7 +38,7 @@ protected function runImplementation(
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
string $target_dir,
) {
$severity = $this->getArguments()['severity'] ?? 'notice';
$message = $this->getArguments()['message'];
Expand Down
9 changes: 3 additions & 6 deletions src/Artifact/Actions/Base/MessageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@

use Phabalicious\Artifact\Actions\ActionBase;
use Phabalicious\Configuration\HostConfig;
use Phabalicious\Method\ScriptMethod;
use Phabalicious\Method\TaskContextInterface;
use Phabalicious\ShellProvider\CommandResult;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Phabalicious\Validation\ValidationService;
use Psr\Log\LoggerInterface;

class MessageAction extends ActionBase
{
const MESSAGE_TYPE_MAPPING = [
public const MESSAGE_TYPE_MAPPING = [
'error' => 'error',
'warning' => 'warning',
'note' => 'note',
'comment' => 'comment',
'success' => 'success'
'success' => 'success',
];

public function __construct()
Expand All @@ -41,7 +38,7 @@ protected function runImplementation(
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
string $target_dir,
) {
$severity = $this->getArguments()['type'] ?? 'note';
$message = $this->getArguments()['message'];
Expand Down
7 changes: 3 additions & 4 deletions src/Artifact/Actions/Base/ScriptAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Phabalicious\Artifact\Actions\Base;

use Phabalicious\Artifact\Actions\ActionBase;
Expand Down Expand Up @@ -39,7 +38,7 @@ protected function runImplementation(
TaskContextInterface $context,
ShellProviderInterface $shell,
string $install_dir,
string $target_dir
string $target_dir,
) {
$dir = $this->runInTargetDir ? $target_dir : $install_dir;
$shell->pushWorkingDir($dir);
Expand All @@ -51,12 +50,12 @@ protected function runImplementation(
$script = $context->getConfigurationService()->getMethodFactory()->getMethod('script');

if (!$script_data = $this->getArgument('script')) {
if (!$script_name = $this->getArgument('name')) {
if (!$script_name = $this->getArgument('name')) {
$script_data = $this->getArguments();
} else {
$script_data = $context->getConfigurationService()->findScript($host_config, $script_name);
if (!$script_data) {
throw new \InvalidArgumentException(sprintf("Could not find named script `%s`", $script_name));
throw new \InvalidArgumentException(sprintf('Could not find named script `%s`', $script_name));
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Artifact/Actions/Ftp/ExcludeAction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Phabalicious\Artifact\Actions\Ftp;

use Phabalicious\Artifact\Actions\ActionBase;
Expand All @@ -10,8 +9,7 @@

class ExcludeAction extends ActionBase
{

const FTP_SYNC_EXCLUDES = 'ftpSyncExcludes';
public const FTP_SYNC_EXCLUDES = 'ftpSyncExcludes';

protected function validateArgumentsConfig(array $action_arguments, ValidationService $validation)
{
Expand Down
Loading

0 comments on commit 41bc84f

Please sign in to comment.