Skip to content

Commit

Permalink
cs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Apr 7, 2019
1 parent adfe6c5 commit e51df0e
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.php_cs.cache
46 changes: 46 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'braces' => ['allow_single_line_closure' => false],
'comment_to_phpdoc' => true,
'declare_strict_types' => false,
'function_to_constant' => ['functions' => ['get_class', 'get_called_class', 'php_sapi_name', 'phpversion', 'pi']],
'heredoc_to_nowdoc' => true,
'list_syntax' => ['syntax' => 'short'],
'logical_operators' => true,
'no_blank_lines_after_phpdoc' => false,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_superfluous_elseif' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types_order' => true,
'phpdoc_var_annotation_correct_order' => true,
'psr4' => false,
'single_import_per_statement' => false,
'space_after_semicolon' => true,
'static_lambda' => true,
'string_line_ending' => true,
'void_return' => false,
'yoda_style' => true,
])
->setFinder($finder)
;
10 changes: 5 additions & 5 deletions deployer/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Deployer\Task\Context;

$baseDir = dirname(__DIR__, 5);
$baseDir = \dirname(__DIR__, 5);
if (0 === strpos($baseDir, getcwd())) {
$baseDir = substr($baseDir, strlen(getcwd()));
$baseDir = substr($baseDir, \strlen(getcwd()));
$baseDir = ltrim($baseDir.'/', '/');
}

Expand Down Expand Up @@ -46,18 +46,18 @@
'yarn.lock',
]);

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

set('allow_anonymous_stats', false);

after('deploy:failed', 'deploy:unlock');

set('bin/mysql', function () {
set('bin/mysql', static function () {
return locateBinaryPath('mysql');
});

set('bin/mysqldump', function () {
set('bin/mysqldump', static function () {
return locateBinaryPath('mysqldump');
});
2 changes: 1 addition & 1 deletion deployer/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace YDeploy;

use function Deployer\{cd, download, get, upload};
use Deployer\Host\Host;
use Deployer\Host\Localhost;
use Deployer\Task\Context;
use function Deployer\{cd, download, get, upload};

function uploadContent(string $destination, string $content): void
{
Expand Down
2 changes: 1 addition & 1 deletion deployer/tasks/build.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Deployer;

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

Expand Down
2 changes: 1 addition & 1 deletion deployer/tasks/build/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
set('gulp_options', '');

desc('Load (yarn) and build (gulp) assets');
task('build:assets', function () {
task('build:assets', static function () {
cd('{{release_path}}');

if (get('yarn')) {
Expand Down
2 changes: 1 addition & 1 deletion deployer/tasks/build/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Deployer;

desc('Show branch info');
task('build:info', function () {
task('build:info', static function () {
$what = '';
$branch = get('branch');

Expand Down
2 changes: 1 addition & 1 deletion deployer/tasks/database/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Deployer;

desc('Migrate the database');
task('database:migration', function () {
task('database:migration', static function () {
cd('{{release_path}}');

run('{{bin/php}} {{bin/console}} ydeploy:migrate');
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 @@ -3,7 +3,7 @@
namespace Deployer;

desc('Dump info about current deployment');
task('deploy:dump_info', function () {
task('deploy:dump_info', static function () {
$infos = [
'host' => get('hostname'),
'stage' => get('stage', false) ?: null,
Expand Down
20 changes: 10 additions & 10 deletions deployer/tasks/local/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use Deployer\Host\Host;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Yaml\Yaml;
use function YDeploy\{downloadContent, uploadContent, onHost};
use function YDeploy\{downloadContent, onHost, uploadContent};

desc('Setup local redaxo instance');
task('local:setup', new class {
task('local:setup', new class() {
private $mysqlOptions;

/** @var null|Host */
Expand Down Expand Up @@ -45,7 +45,7 @@ private function chooseSource(): void

$hosts = Deployer::get()->hosts;

if (count($hosts) > 0) {
if (\count($hosts) > 0) {
writeln('The data can be imported from one of the hosts, or from dump file.');
writeln('');

Expand Down Expand Up @@ -76,7 +76,7 @@ private function chooseSource(): void
return;
}

if (count($hosts) === 1) {
if (1 === \count($hosts)) {
$this->source = $hosts->first();

return;
Expand All @@ -97,7 +97,7 @@ private function setConfigYml(): void
$this->headline('Create <fg=cyan>local</fg=cyan> config.yml');

if ($this->source) {
$config = onHost($this->source, function () {
$config = onHost($this->source, static function () {
return downloadContent('{{data_dir}}/core/config.yml');
});
} else {
Expand Down Expand Up @@ -152,7 +152,7 @@ private function setConfigYml(): void
'--host='.escapeshellarg($db['host']),
'--user='.escapeshellarg($db['login']),
'--password='.escapeshellarg($db['password']),
escapeshellarg($db['name'])
escapeshellarg($db['name']),
]));

$config['db'][1] = $db;
Expand All @@ -174,13 +174,13 @@ private function copyDatabase(): void
$path = get('data_dir').'/addons/ydeploy/'.date('YmdHis').'.sql';

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

$path = $this->sourceFile;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ private function replaceYrewriteDomains(): void
$this->headline('Replace yrewrite domains');

foreach (explode("\n", $data) as $line) {
list($id, $domain) = explode("\t", $line, 2);
[$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.'"');
Expand All @@ -244,7 +244,7 @@ private function copyMedia(): void
$path = get('data_dir').'/addons/ydeploy/media_'.date('YmdHis').'.tar.gz';

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

try {
Expand Down
4 changes: 2 additions & 2 deletions deployer/tasks/server/clear_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// (by calling a temp php file via curl)
set('clear_web_php_cache', false);

set('bin/apachectl', function () {
set('bin/apachectl', static function () {
return locateBinaryPath('apachectl');
});

desc('Clear the server cache');
task('server:clear_cache', new class {
task('server:clear_cache', new class() {
public function __invoke(): void
{
if (get('restart_apache')) {
Expand Down
14 changes: 7 additions & 7 deletions deployer/tasks/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Deployer\Host\Localhost;
use Deployer\Task\Context;
use Symfony\Component\Yaml\Yaml;
use function YDeploy\{downloadContent, uploadContent, onHost};
use function YDeploy\{downloadContent, onHost, uploadContent};

desc('Setup redaxo instance');
task('setup', new class {
task('setup', new class() {
private $mysqlOptions;

/** @var Host */
Expand Down Expand Up @@ -51,7 +51,7 @@ private function chooseSource(): Host
$hosts = Deployer::get()->hosts;
$localhost = new Localhost('local');

if (count($hosts) < 2) {
if (\count($hosts) < 2) {
writeln("The host <fg=cyan>{{hostname}}</fg=cyan> will be initialized by data from <fg=cyan>{$localhost}</fg=cyan>.");
writeln('');

Expand Down Expand Up @@ -81,7 +81,7 @@ private function setConfigYml(): void
if ($this->source instanceof Localhost) {
$config = file_get_contents(getcwd().'/'.get('data_dir').'/core/config.yml');
} else {
$config = onHost($this->source, function () {
$config = onHost($this->source, static function () {
return downloadContent('{{data_dir}}/core/config.yml');
});
}
Expand Down Expand Up @@ -149,7 +149,7 @@ private function copyDatabase(): void
$path = get('data_dir').'/addons/ydeploy/'.date('YmdHis').'.sql';

// export source database
onHost($this->source, function () use ($path) {
onHost($this->source, static function () use ($path) {
run('{{bin/console}} db:connection-options | xargs {{bin/mysqldump}} > '.escapeshellarg($path));

if (Context::get()->getHost() instanceof Localhost) {
Expand Down Expand Up @@ -200,7 +200,7 @@ private function replaceYrewriteDomains(): void
$this->headline('Replace yrewrite domains');

foreach (explode("\n", $data) as $line) {
list($id, $domain) = explode("\t", $line, 2);
[$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.'"');
Expand All @@ -217,7 +217,7 @@ private function copyMedia(): void
$path = get('data_dir').'/addons/ydeploy/media_'.date('YmdHis').'.tar.gz';

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

if (Context::get()->getHost() instanceof Localhost) {
Expand Down
2 changes: 1 addition & 1 deletion deployer/tasks/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Deployer;

desc('Upload locally prepared release to server');
task('upload', function () {
task('upload', static function () {
upload(getcwd().'/.build/current/', '{{release_path}}', [
'options' => ['--exclude=".git/"', '--delete'],
]);
Expand Down
5 changes: 0 additions & 5 deletions lib/command/abstract.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @internal
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/diff_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private function addAlterTables(): string
}

if (isset($alter['ensureColumn'])) {
foreach ($alter['ensureColumn'] as list($column, $after)) {
foreach ($alter['ensureColumn'] as [$column, $after]) {
$content .= $this->addEnsureColumn($column, $after);
}
}
Expand Down Expand Up @@ -243,7 +243,7 @@ private function addFixtures(): string
if (isset($changes['ensure'])) {
$rows = [];
foreach ($changes['ensure'] as $data) {
$data = array_map(function ($value) use ($sql) {
$data = array_map(static function ($value) use ($sql) {
if (is_int($value)) {
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static function handleUnlockedPage(rex_be_page $page, ?array $subpages =
}
}

rex_extension::register('PAGE_TITLE_SHOWN', function (rex_extension_point $ep) {
rex_extension::register('PAGE_TITLE_SHOWN', static function (rex_extension_point $ep) {
$url = rex_url::backendPage('system/ydeploy', rex_api_ydeploy_protected_page::getUrlParams() + [
'action' => 'lock',
'protected_page' => rex_be_controller::getCurrentPage(),
Expand Down
2 changes: 1 addition & 1 deletion pages/system.ydeploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
return;
}

$apiUrl = function (string $action, string $page, string $redirect = null) {
$apiUrl = static function (string $action, string $page, string $redirect = null) {
$params = rex_api_ydeploy_protected_page::getUrlParams();
$params['action'] = $action;
$params['protected_page'] = $page;
Expand Down

0 comments on commit e51df0e

Please sign in to comment.