From d942f63b8a2648bcb8f39f1f0f226f2d52b71d34 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:26:14 +0000 Subject: [PATCH] style: format code with php-cs-fixer Format code with php-cs-fixer This commit fixes the style issues introduced in c88728f according to the output from php-cs-fixer. Details: https://app.deepsource.com/gh/thundersquared/apiscp-webapp-bedrock/transform/95f3af7a-3ec7-4ccf-9f12-769594b7515c/ --- src/lib/module.php | 112 +++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 69 deletions(-) diff --git a/src/lib/module.php b/src/lib/module.php index 00ef206..df6308f 100644 --- a/src/lib/module.php +++ b/src/lib/module.php @@ -26,8 +26,7 @@ class Bedrock_Module extends \Wordpress_Module protected function getAppRoot(string $hostname, string $path = ''): ?string { - if (file_exists($tmp = $this->getDocumentRoot($hostname, $path) . '/wp-config.php')) - { + if (file_exists($tmp = $this->getDocumentRoot($hostname, $path) . '/wp-config.php')) { return $tmp; } @@ -36,19 +35,14 @@ protected function getAppRoot(string $hostname, string $path = ''): ?string protected function getAppRootPath(string $hostname, string $path = ''): ?string { - if ($hostname[0] === '/') - { - if (!($path = realpath($this->domain_fs_path($hostname)))) - { + if ($hostname[0] === '/') { + if (!($path = realpath($this->domain_fs_path($hostname)))) { return null; } $approot = \dirname($path); - } - else - { + } else { $approot = $this->getAppRoot($hostname, $path); - if (!$approot) - { + if (!$approot) { return null; } $approot = $this->domain_fs_path($approot); @@ -66,8 +60,7 @@ protected function getAppRootPath(string $hostname, string $path = ''): ?string */ protected function parseLock(string $lockType, string $version): string { - switch ($lockType) - { + switch ($lockType) { case 'major': return '~' . Versioning::asMinor($version); case 'minor': @@ -98,11 +91,9 @@ protected function generateNewConfiguration(string $hostname, string $docroot, D 'set DB_PASSWORD' => ["dotenv set DB_PASSWORD '%(password)s'", ['password' => $dbcredentials->password]], ]; - foreach ($steps as $name => $actions) - { + foreach ($steps as $name => $actions) { $ret = $this->execCommand($docroot, $actions[0], $actions[1]); - if (!$ret['success']) - { + if (!$ret['success']) { return error('failed to %s, error: %s', $name, coalesce($hostname, $docroot, $ret['stderr'], $ret['stdout'])); } } @@ -120,31 +111,28 @@ protected function generateNewConfiguration(string $hostname, string $docroot, D */ public function install(string $hostname, string $path = '', array $opts = array()): bool { - if (!$this->mysql_enabled()) - { - return error('%(what)s must be enabled to install %(app)s', - ['what' => 'MySQL', 'app' => static::APP_NAME]); + if (!$this->mysql_enabled()) { + return error( + '%(what)s must be enabled to install %(app)s', + ['what' => 'MySQL', 'app' => static::APP_NAME] + ); } - if (!$this->php_composer_exists()) - { + if (!$this->php_composer_exists()) { return error('composer missing! contact sysadmin'); } // Same situation as with Ghost. We can't install under a path for fear of // leaking information - if ($path) - { + if ($path) { return error('Composer projects may only be installed directly on a subdomain or domain without a child path, e.g. https://domain.com but not https://domain.com/laravel'); } - if (!($docroot = $this->getDocumentRoot($hostname, $path))) - { + if (!($docroot = $this->getDocumentRoot($hostname, $path))) { return error("failed to normalize path for `%s'", $hostname); } - if (!$this->parseInstallOptions($opts, $hostname, $path)) - { + if (!$this->parseInstallOptions($opts, $hostname, $path)) { return false; } @@ -152,8 +140,7 @@ public function install(string $hostname, string $path = '', array $opts = array $ret = $this->execCommand($docroot, 'package install %(dotenvcmd)s ', [ 'dotenvcmd' => static::DOTENV_COMMAND, ]); - if (!$ret['success']) - { + if (!$ret['success']) { return error('failed to install dotenv command, error: %s', coalesce($ret['stderr'], $ret['stdout'])); } @@ -166,41 +153,37 @@ public function install(string $hostname, string $path = '', array $opts = array ]); // Rollback on failure - if (!$ret['success']) - { + if (!$ret['success']) { $this->file_delete($docroot, true); - return error('failed to download roots/bedrock package: %s %s', - $ret['stderr'], $ret['stdout'] + return error( + 'failed to download roots/bedrock package: %s %s', + $ret['stderr'], + $ret['stdout'] ); } // Create new database $dbCred = DatabaseGenerator::mysql($this->getAuthContext(), $hostname); - if (!$dbCred->create()) - { + if (!$dbCred->create()) { return false; } // Fill in .env file - if (!$this->generateNewConfiguration($hostname, $docroot, $dbCred)) - { + if (!$this->generateNewConfiguration($hostname, $docroot, $dbCred)) { info('removing temporary files'); - if (!array_get($opts, 'hold')) - { + if (!array_get($opts, 'hold')) { $this->file_delete($docroot, true); $dbCred->rollback(); } return false; } - if (!isset($opts['title'])) - { + if (!isset($opts['title'])) { $opts['title'] = 'A Random Blog for a Random Reason'; } - if (!isset($opts['password'])) - { + if (!isset($opts['password'])) { $opts['password'] = Password::generate(); info("autogenerated password `%s'", $opts['password']); } @@ -222,10 +205,8 @@ public function install(string $hostname, string $path = '', array $opts = array $ret = $this->execCommand($docroot, 'core %(mode)s --admin_email=%(email)s --skip-email ' . '--url=%(proto)s%(url)s --title=%(title)s --admin_user=%(user)s --exec=%(mysqli81)s ' . '--admin_password=%(password)s', $args); - if (!$ret['success']) - { - if (!array_get($opts, 'hold')) - { + if (!$ret['success']) { + if (!array_get($opts, 'hold')) { $dbCred->rollback(); } return error('failed to create database structure: %s', coalesce($ret['stderr'], $ret['stdout'])); @@ -235,16 +216,16 @@ public function install(string $hostname, string $path = '', array $opts = array $wpcli->setConfiguration(['apache_modules' => ['mod_rewrite']]); $ret = $this->execCommand($docroot, "rewrite structure --hard '/%%postname%%/'"); - if (!$ret['success']) - { + if (!$ret['success']) { return error('failed to set rewrite structure, error: %s', coalesce($ret['stderr'], $ret['stdout'])); } // Remap public to web dir instead of app dir - if (null === $this->remapPublic($hostname, $path, 'web/')) - { - return error("Failed to remap Bedrock to web/, manually remap from `%s' - Bedrock setup is incomplete!", - $docroot); + if (null === $this->remapPublic($hostname, $path, 'web/')) { + return error( + "Failed to remap Bedrock to web/, manually remap from `%s' - Bedrock setup is incomplete!", + $docroot + ); } return true; @@ -263,8 +244,7 @@ public function get_versions(): array // Attempt to retrieve cached versions $cache = \Cache_Super_Global::spawn(); - if (false !== ($ver = $cache->get($key))) - { + if (false !== ($ver = $cache->get($key))) { return $ver; } @@ -272,8 +252,7 @@ public function get_versions(): array $url = self::VERSION_CHECK_URL; $context = stream_context_create(['http' => ['timeout' => 5]]); $contents = file_get_contents($url, false, $context); - if (!$contents) - { + if (!$contents) { return array(); } $versions = json_decode($contents, true); @@ -305,16 +284,14 @@ public function valid(string $hostname, string $path = ''): bool public function get_version(string $hostname, string $path = ''): ?string { - if (!$this->valid($hostname, $path)) - { + if (!$this->valid($hostname, $path)) { return null; } $approot = $this->getAppRootPath($hostname, $path); // is composer.json file missing? - if (!file_exists($approot . '/composer.json')) - { + if (!file_exists($approot . '/composer.json')) { return null; } @@ -328,8 +305,7 @@ public function get_environment(string $hostname, string $path = ''): ?string // Read .env value $ret = $this->execCommand($approotpath, "dotenv get WP_ENV"); - if (!$ret['success']) - { + if (!$ret['success']) { return error('failed to read env: %s', coalesce($ret['stderr'], $ret['stdout'])); } @@ -345,8 +321,7 @@ public function set_environment(string $hostname, string $path = '', string $env 'environment' => $environment, ]); - if (!$ret['success']) - { + if (!$ret['success']) { return error('failed to update env: %s', coalesce($ret['stderr'], $ret['stdout'])); } @@ -361,8 +336,7 @@ public function get_environments(string $hostname, string $path = ''): ?array $approotpath = $this->getAppRootPath($hostname, $path); // is config/environments/ dir missing? - if (!is_dir($approotpath . '/config/environments/')) - { + if (!is_dir($approotpath . '/config/environments/')) { return null; }