Skip to content

Commit

Permalink
Apply php-cs-fixer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan authored and rex-bot committed Sep 29, 2023
1 parent 56f9326 commit a955c66
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 131 deletions.
10 changes: 5 additions & 5 deletions deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

$version = ltrim(Deployer::get()->getConsole()->getVersion(), 'v');
if (6 !== (int) $version) {
throw new RuntimeException('YDeploy 1.x requires Deployer 6.x, but Deployer '.$version.' is used');
throw new RuntimeException('YDeploy 1.x requires Deployer 6.x, but Deployer ' . $version . ' is used');
}

/** @psalm-suppress MissingFile */
require 'recipe/common.php';

require __DIR__.'/deployer/config.php';
require __DIR__.'/deployer/functions.php';
require __DIR__ . '/deployer/config.php';
require __DIR__ . '/deployer/functions.php';

foreach (glob(__DIR__.'/deployer/tasks/**/*.php', GLOB_NOSORT) as $path) {
foreach (glob(__DIR__ . '/deployer/tasks/**/*.php', GLOB_NOSORT) as $path) {
require $path;
}
foreach (glob(__DIR__.'/deployer/tasks/*.php', GLOB_NOSORT) as $path) {
foreach (glob(__DIR__ . '/deployer/tasks/*.php', GLOB_NOSORT) as $path) {
require $path;
}
4 changes: 2 additions & 2 deletions deployer/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$baseDir = dirname(__DIR__, 5);
if (str_starts_with($baseDir, getcwd())) {

Check failure on line 11 in deployer/config.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

InvalidLiteralArgument

deployer/config.php:11:21: InvalidLiteralArgument: Argument 1 of str_starts_with expects a non-literal value, but '/home' provided (see https://psalm.dev/237)
$baseDir = substr($baseDir, strlen(getcwd()));
$baseDir = ltrim($baseDir.'/', '/');
$baseDir = ltrim($baseDir . '/', '/');
}

set('base_dir', $baseDir);
Expand Down Expand Up @@ -51,7 +51,7 @@
]);

set('url', static function () {
return 'https://'.Context::get()->getHost()->getRealHostname();
return 'https://' . Context::get()->getHost()->getRealHostname();
});

set('allow_anonymous_stats', false);
Expand Down
4 changes: 2 additions & 2 deletions deployer/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function uploadContent(string $destination, string $content): void
$destination = "$workingPath/$destination";
}

$path = tempnam(getcwd().'/'.get('data_dir').'/addons/ydeploy', 'tmp');
$path = tempnam(getcwd() . '/' . get('data_dir') . '/addons/ydeploy', 'tmp');
file_put_contents($path, $content);

try {
Expand All @@ -33,7 +33,7 @@ function downloadContent(string $source): string
$source = "$workingPath/$source";
}

$path = tempnam(getcwd().'/'.get('data_dir').'/addons/ydeploy', 'tmp');
$path = tempnam(getcwd() . '/' . get('data_dir') . '/addons/ydeploy', 'tmp');

download($source, $path);
$content = file_get_contents($path);
Expand Down
2 changes: 1 addition & 1 deletion deployer/tasks/build.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

desc('Prepare the next release in local subdir ".build"');
task('build', static function () {
set('deploy_path', getcwd().'/.build');
set('deploy_path', getcwd() . '/.build');
set('keep_releases', 1);

invoke('build:info');
Expand Down
2 changes: 1 addition & 1 deletion deployer/tasks/deploy/dump_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
$infos = json_encode($infos, JSON_PRETTY_PRINT);

run('mkdir -p {{release_path}}/{{data_dir}}/addons/ydeploy');
run('echo '.escapeshellarg($infos).' > {{release_path}}/{{data_dir}}/addons/ydeploy/info.json');
run('echo ' . escapeshellarg($infos) . ' > {{release_path}}/{{data_dir}}/addons/ydeploy/info.json');
});
58 changes: 29 additions & 29 deletions deployer/tasks/local/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __invoke(): void
{
writeln('');

$this->mysqlOptions = get('data_dir').'/addons/ydeploy/mysql-options';
$this->mysqlOptions = get('data_dir') . '/addons/ydeploy/mysql-options';

$this->chooseSource();

Expand All @@ -39,7 +39,7 @@ public function __invoke(): void
$this->replaceYrewriteDomains();
$this->copyMedia();
} finally {
run('rm -f '.escapeshellarg($this->mysqlOptions));
run('rm -f ' . escapeshellarg($this->mysqlOptions));
}
}

Expand All @@ -64,13 +64,13 @@ private function chooseSource(): void

if (!$fromHost) {
do {
$file = ask('Dump file', getcwd().'/dump.sql');
$file = ask('Dump file', getcwd() . '/dump.sql');

if (file_exists($file)) {
$this->sourceFile = $file;
} else {
writeln('');
writeln('<error>The file does not exist: '.$file.'</error>');
writeln('<error>The file does not exist: ' . $file . '</error>');
writeln('');
}
} while (!$this->sourceFile);
Expand Down Expand Up @@ -105,14 +105,14 @@ private function setConfigYml(): void
return downloadContent('{{data_dir}}/core/config.yml');
});
} else {
$config = file_get_contents(getcwd().'/'.get('src_dir').'/core/default.config.yml');
$config = file_get_contents(getcwd() . '/' . get('src_dir') . '/core/default.config.yml');
}

$config = Yaml::parse($config);

$config['setup'] = false;
$config['debug'] = true;
$config['instname'] = 'rex'.date('YmdHis');
$config['instname'] = 'rex' . date('YmdHis');

$config['server'] = ask('Server:', get('url'));
$config['servername'] = ask('Server name:', $config['servername']);
Expand All @@ -137,25 +137,25 @@ private function setConfigYml(): void
$db['password'] = askHiddenResponse('Database password:');

file_put_contents($this->mysqlOptions, implode("\n", [
'--host='.escapeshellarg($db['host']),
'--user='.escapeshellarg($db['login']),
'--password='.escapeshellarg($db['password']),
'--host=' . escapeshellarg($db['host']),
'--user=' . escapeshellarg($db['login']),
'--password=' . escapeshellarg($db['password']),
]));

try {
run('< '.escapeshellarg($this->mysqlOptions).' xargs {{bin/mysql}} -e "CREATE DATABASE IF NOT EXISTS '.escapeshellcmd($db['name']).' CHARACTER SET utf8 COLLATE utf8_general_ci"');
run('< ' . escapeshellarg($this->mysqlOptions) . ' xargs {{bin/mysql}} -e "CREATE DATABASE IF NOT EXISTS ' . escapeshellcmd($db['name']) . ' CHARACTER SET utf8 COLLATE utf8_general_ci"');
$dbValid = true;
} catch (ProcessFailedException $e) {
writeln('');
writeln('<error>Could not create/connect database: '.trim($e->getProcess()->getErrorOutput()).'</error>');
writeln('<error>Could not create/connect database: ' . trim($e->getProcess()->getErrorOutput()) . '</error>');
writeln('');
}
} while (!$dbValid);

file_put_contents($this->mysqlOptions, implode("\n", [
'--host='.escapeshellarg($db['host']),
'--user='.escapeshellarg($db['login']),
'--password='.escapeshellarg($db['password']),
'--host=' . escapeshellarg($db['host']),
'--user=' . escapeshellarg($db['login']),
'--password=' . escapeshellarg($db['password']),
escapeshellarg($db['name']),
]));

Expand All @@ -175,13 +175,13 @@ private function copyDatabase(): void
if ($this->source) {
$this->headline("Copy database from <fg=cyan>{$this->source}</fg=cyan> to <fg=cyan>local</fg=cyan>");

$path = get('data_dir').'/addons/ydeploy/'.date('YmdHis').'.sql';
$path = get('data_dir') . '/addons/ydeploy/' . date('YmdHis') . '.sql';

// export source database
onHost($this->source, static function () use ($path) {
run('{{bin/console}} db:connection-options | xargs {{bin/mysqldump}} > '.escapeshellarg($path));
run('{{bin/console}} db:connection-options | xargs {{bin/mysqldump}} > ' . escapeshellarg($path));
download("{{release_path}}/$path", $path);
run('rm -f '.escapeshellarg($path));
run('rm -f ' . escapeshellarg($path));
});
} else {
$this->headline('Import database dump');
Expand All @@ -190,9 +190,9 @@ private function copyDatabase(): void
}

// import the dump
run('< '.escapeshellarg($this->mysqlOptions).' xargs sh -c \'{{bin/mysql}} "$0" "$@" < '.escapeshellcmd(escapeshellarg($path)).'\'');
run('< ' . escapeshellarg($this->mysqlOptions) . ' xargs sh -c \'{{bin/mysql}} "$0" "$@" < ' . escapeshellcmd(escapeshellarg($path)) . '\'');

run('rm -f '.escapeshellarg($path));
run('rm -f ' . escapeshellarg($path));

$this->ok();
}
Expand All @@ -201,15 +201,15 @@ private function configureDeveloper(): void
{
$this->headline('Configure developer addon for local usage');

run('< '.escapeshellarg($this->mysqlOptions).' xargs {{bin/mysql}} -e "UPDATE rex_config SET value = \"true\" WHERE namespace=\"developer\" AND \`key\` IN (\"sync_frontend\", \"sync_backend\", \"rename\", \"dir_suffix\", \"delete\")"');
run('< ' . escapeshellarg($this->mysqlOptions) . ' xargs {{bin/mysql}} -e "UPDATE rex_config SET value = \"true\" WHERE namespace=\"developer\" AND \`key\` IN (\"sync_frontend\", \"sync_backend\", \"rename\", \"dir_suffix\", \"delete\")"');

$this->ok();
}

private function replaceYrewriteDomains(): void
{
try {
$data = run('< '.escapeshellarg($this->mysqlOptions).' xargs {{bin/mysql}} --silent --raw --skip-column-names -e "SELECT id, domain FROM rex_yrewrite_domain"');
$data = run('< ' . escapeshellarg($this->mysqlOptions) . ' xargs {{bin/mysql}} --silent --raw --skip-column-names -e "SELECT id, domain FROM rex_yrewrite_domain"');
$data = trim($data);
} catch (ProcessFailedException $exception) {
if (str_contains($exception->getProcess()->getErrorOutput(), 'ERROR 1146')) {
Expand All @@ -229,8 +229,8 @@ private function replaceYrewriteDomains(): void
foreach (explode("\n", $data) as $line) {
[$id, $domain] = explode("\t", $line, 2);
$id = (int) $id;
$domain = ask($domain.':', $this->server ?: get('url'));
run('< '.escapeshellarg($this->mysqlOptions).' xargs {{bin/mysql}} -e "UPDATE rex_yrewrite_domain SET domain = \"'.addslashes($domain).'\" WHERE id = '.$id.'"');
$domain = ask($domain . ':', $this->server ?: get('url'));
run('< ' . escapeshellarg($this->mysqlOptions) . ' xargs {{bin/mysql}} -e "UPDATE rex_yrewrite_domain SET domain = \"' . addslashes($domain) . '\" WHERE id = ' . $id . '"');
}

writeln('');
Expand All @@ -245,32 +245,32 @@ private function copyMedia(): void

$this->headline("Copy media files from <fg=cyan>{$this->source}</fg=cyan> to <fg=cyan>local</fg=cyan>");

$path = get('data_dir').'/addons/ydeploy/media_'.date('YmdHis').'.tar.gz';
$path = get('data_dir') . '/addons/ydeploy/media_' . date('YmdHis') . '.tar.gz';

// create source archive
onHost($this->source, static function () use ($path) {
run('tar -zcvf '.escapeshellarg($path).' -C {{media_dir}} .');
run('tar -zcvf ' . escapeshellarg($path) . ' -C {{media_dir}} .');

try {
download("{{release_path}}/$path", $path);
} finally {
run('rm -f '.escapeshellarg($path));
run('rm -f ' . escapeshellarg($path));
}
});

try {
run('mkdir -p {{media_dir}}');
run('tar -zxvf '.escapeshellarg($path).' -C {{media_dir}}/');
run('tar -zxvf ' . escapeshellarg($path) . ' -C {{media_dir}}/');
} finally {
run('rm -f '.escapeshellarg($path));
run('rm -f ' . escapeshellarg($path));
}

$this->ok();
}

private function headline(string $headline): void
{
writeln('<comment>'.$headline.'</comment>');
writeln('<comment>' . $headline . '</comment>');
writeln('');
}

Expand Down
14 changes: 7 additions & 7 deletions deployer/tasks/server/clear_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ private function clearWebPhpCache(): void
}

$dir = '_clear_cache';
$htaccessFile = $dir.'/.htaccess';
$phpFile = $dir.'/_clear_cache.php';
$htaccessFile = $dir . '/.htaccess';
$phpFile = $dir . '/_clear_cache.php';

try {
foreach ($paths as $path) {
run('mkdir -p '.$path.$dir);
run('echo "Require all granted" > '.$path.$htaccessFile);
run('echo '.escapeshellarg("<?php\n\n".$this->getPhpClearCacheCode()).' > '.$path.$phpFile);
run('mkdir -p ' . $path . $dir);
run('echo "Require all granted" > ' . $path . $htaccessFile);
run('echo ' . escapeshellarg("<?php\n\n" . $this->getPhpClearCacheCode()) . ' > ' . $path . $phpFile);
}

run("curl -fsS {{url}}/$phpFile");
} finally {
foreach ($paths as $path) {
run('rm -rf '.$path.$dir);
run('rm -rf ' . $path . $dir);
}
}
}

private function clearCliPhpCache(): void
{
run('{{bin/php}} -r '.escapeshellarg($this->getPhpClearCacheCode()));
run('{{bin/php}} -r ' . escapeshellarg($this->getPhpClearCacheCode()));
}

private function getPhpClearCacheCode(): string
Expand Down
Loading

0 comments on commit a955c66

Please sign in to comment.