From 6d9fc934707fdb4128e6ff29eb4753e4cbfb4e15 Mon Sep 17 00:00:00 2001 From: Mischa Braam Date: Sun, 28 Jan 2024 12:11:55 +0100 Subject: [PATCH] Add phpcs check with PSR12 --- .../{test-workflow.yml => test-commands.yml} | 2 +- .github/workflows/test-static.yml | 28 ++++++++++ cli/ValetPlus/AbstractDockerService.php | 10 ++-- cli/ValetPlus/AbstractPhpExtension.php | 5 +- cli/ValetPlus/AbstractService.php | 6 +-- cli/ValetPlus/Binary.php | 14 +++-- .../DriverConfigs/Magento2ValetDriver.php | 1 + .../DriverConfigs/Shopware5ValetDriver.php | 1 + cli/ValetPlus/DriverConfigurator.php | 8 +-- cli/ValetPlus/Elasticsearch.php | 17 +++--- cli/ValetPlus/Extended/Configuration.php | 2 +- cli/ValetPlus/Extended/PhpFpm.php | 16 +++--- cli/ValetPlus/Extended/Status.php | 16 +++--- cli/ValetPlus/Mailhog.php | 15 +++--- cli/ValetPlus/Mysql.php | 54 +++++++++++-------- cli/ValetPlus/PhpExtension.php | 17 +++--- cli/ValetPlus/Rabbitmq.php | 2 +- cli/ValetPlus/Redis.php | 2 +- cli/ValetPlus/Varnish.php | 2 +- cli/ValetPlus/Xdebug.php | 9 ++-- .../drivers/custom/PimcoreValetDriver.php | 13 +++-- .../custom/ShopwarePlatformValetDriver.php | 16 +++--- cli/stubs/drivers/magento2/env.php | 1 + composer.json | 9 ++-- phpcs.xml | 10 ++++ 25 files changed, 175 insertions(+), 101 deletions(-) rename .github/workflows/{test-workflow.yml => test-commands.yml} (98%) create mode 100644 .github/workflows/test-static.yml create mode 100644 phpcs.xml diff --git a/.github/workflows/test-workflow.yml b/.github/workflows/test-commands.yml similarity index 98% rename from .github/workflows/test-workflow.yml rename to .github/workflows/test-commands.yml index e7c2e4f8..9aa2838c 100644 --- a/.github/workflows/test-workflow.yml +++ b/.github/workflows/test-commands.yml @@ -1,4 +1,4 @@ -name: Valet+ tests +name: Test commands on: push: diff --git a/.github/workflows/test-static.yml b/.github/workflows/test-static.yml new file mode 100644 index 00000000..bdfc8426 --- /dev/null +++ b/.github/workflows/test-static.yml @@ -0,0 +1,28 @@ +name: Static analysis + +on: + push: + branches: [ 3.x ] + pull_request: + branches: [ 3.x ] + +jobs: + test: + runs-on: macos-12 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: '[INSTALL] Install PHP 8.0' + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + extensions: dom, curl, libxml, mbstring, zip, fileinfo + ini-values: error_reporting=E_ALL, max_execution_time=-1, memory_limit=512M + tools: composer:v2 + coverage: none + - name: '[INSTALL] Composer install' + run: composer install --no-interaction --prefer-dist + + - name: '[TEST] Phpcs' + run: ./vendor/bin/phpcs diff --git a/cli/ValetPlus/AbstractDockerService.php b/cli/ValetPlus/AbstractDockerService.php index d0b12ad8..ad17b269 100644 --- a/cli/ValetPlus/AbstractDockerService.php +++ b/cli/ValetPlus/AbstractDockerService.php @@ -8,19 +8,21 @@ use Illuminate\Support\Collection; use Valet\CommandLine; use Valet\Filesystem; + use function Valet\info; use function Valet\warning; /** - * Docker container service. Please note that container names are restricted to the following characters [a-zA-Z0-9][a-zA-Z0-9_.-]. + * Docker container service. + * Please note that container names are restricted to the following characters [a-zA-Z0-9][a-zA-Z0-9_.-]. * Obviously this has a dependency on the installation of Docker. For convenience install Docker Desktop. */ abstract class AbstractDockerService { /** @var string */ - const DOCKER_COMPOSE_STUB = __DIR__ . '/../stubs/%s/%s/docker-compose.yml'; + protected const DOCKER_COMPOSE_STUB = __DIR__ . '/../stubs/%s/%s/docker-compose.yml'; /** @var string */ - const DOCKER_COMPOSE_PATH = VALET_HOME_PATH . '/Docker/%s/%s/docker-compose.yml'; + protected const DOCKER_COMPOSE_PATH = VALET_HOME_PATH . '/Docker/%s/%s/docker-compose.yml'; /** @var CommandLine */ protected $cli; @@ -35,7 +37,7 @@ abstract class AbstractDockerService */ public function __construct( CommandLine $cli, - Filesystem $files + Filesystem $files ) { $this->cli = $cli; $this->files = $files; diff --git a/cli/ValetPlus/AbstractPhpExtension.php b/cli/ValetPlus/AbstractPhpExtension.php index fda951ac..7ab57b14 100644 --- a/cli/ValetPlus/AbstractPhpExtension.php +++ b/cli/ValetPlus/AbstractPhpExtension.php @@ -6,6 +6,7 @@ use Valet\Brew; use Valet\PhpFpm; + use function Valet\info; use function Valet\output; use function Valet\warning; @@ -33,8 +34,8 @@ abstract class AbstractPhpExtension * @param PhpExtension $phpExtension */ public function __construct( - Brew $brew, - PhpFpm $phpFpm, + Brew $brew, + PhpFpm $phpFpm, PhpExtension $phpExtension ) { $this->brew = $brew; diff --git a/cli/ValetPlus/AbstractService.php b/cli/ValetPlus/AbstractService.php index 3eb5bc0a..e4433c2a 100644 --- a/cli/ValetPlus/AbstractService.php +++ b/cli/ValetPlus/AbstractService.php @@ -36,9 +36,9 @@ abstract class AbstractService */ public function __construct( Configuration $configuration, - Brew $brew, - Filesystem $files, - CommandLine $cli + Brew $brew, + Filesystem $files, + CommandLine $cli ) { $this->configuration = $configuration; $this->brew = $brew; diff --git a/cli/ValetPlus/Binary.php b/cli/ValetPlus/Binary.php index 703c5caf..9b20d615 100644 --- a/cli/ValetPlus/Binary.php +++ b/cli/ValetPlus/Binary.php @@ -8,6 +8,7 @@ use Valet\Brew; use Valet\CommandLine; use Valet\Filesystem; + use function Valet\info; use function Valet\warning; @@ -68,9 +69,9 @@ class Binary * @param Filesystem $files */ public function __construct( - Brew $brew, + Brew $brew, CommandLine $cli, - Filesystem $files + Filesystem $files ) { $this->brew = $brew; $this->cli = $cli; @@ -150,7 +151,10 @@ public function installBinary($binary) // Check the checksum of downloaded file. if (!$this->checkShasum($binary, $fileName)) { $this->cli->runAsUser("rm /tmp/$fileName"); - warning("Binary $binary could not be installed, $fileName checksum does not match: " . $this->getShasum($binary)); + warning( + "Binary $binary could not be installed, $fileName checksum does not match: " . + $this->getShasum($binary) + ); return; } @@ -195,7 +199,9 @@ public function uninstallBinary($binary) $binaryLocation = $this->getBinLocation($binary); $this->cli->runAsUser('rm ' . $binaryLocation); if ($this->files->exists($binaryLocation)) { - throw new DomainException('Could not remove binary! Please remove manually using: rm ' . $binaryLocation); + throw new DomainException( + 'Could not remove binary! Please remove manually using: rm ' . $binaryLocation + ); } info("Binary $binary successfully uninstalled!"); } diff --git a/cli/ValetPlus/DriverConfigs/Magento2ValetDriver.php b/cli/ValetPlus/DriverConfigs/Magento2ValetDriver.php index e5ad874c..acbb8e4a 100644 --- a/cli/ValetPlus/DriverConfigs/Magento2ValetDriver.php +++ b/cli/ValetPlus/DriverConfigs/Magento2ValetDriver.php @@ -5,6 +5,7 @@ namespace WeProvide\ValetPlus\DriverConfigs; use WeProvide\ValetPlus\DriverConfigurator; + use function Valet\info; use function Valet\output; diff --git a/cli/ValetPlus/DriverConfigs/Shopware5ValetDriver.php b/cli/ValetPlus/DriverConfigs/Shopware5ValetDriver.php index 838dbd98..beac4e19 100644 --- a/cli/ValetPlus/DriverConfigs/Shopware5ValetDriver.php +++ b/cli/ValetPlus/DriverConfigs/Shopware5ValetDriver.php @@ -5,6 +5,7 @@ namespace WeProvide\ValetPlus\DriverConfigs; use WeProvide\ValetPlus\DriverConfigurator; + use function Valet\info; use function Valet\output; diff --git a/cli/ValetPlus/DriverConfigurator.php b/cli/ValetPlus/DriverConfigurator.php index 14a4c7a1..47b43bfe 100644 --- a/cli/ValetPlus/DriverConfigurator.php +++ b/cli/ValetPlus/DriverConfigurator.php @@ -8,6 +8,7 @@ use Valet\Drivers\ValetDriver; use Valet\Filesystem; use Valet\Site; + use function Valet\info; class DriverConfigurator @@ -29,9 +30,9 @@ class DriverConfigurator */ public function __construct( CommandLine $cli, - Filesystem $files, - Site $site, - Redis $redis + Filesystem $files, + Site $site, + Redis $redis ) { $this->cli = $cli; $this->files = $files; @@ -61,7 +62,6 @@ public function configure() return $driver->configure(); } catch (\Throwable $throwable) { - } info('No configuration settings found.'); diff --git a/cli/ValetPlus/Elasticsearch.php b/cli/ValetPlus/Elasticsearch.php index e60b03eb..57257b57 100644 --- a/cli/ValetPlus/Elasticsearch.php +++ b/cli/ValetPlus/Elasticsearch.php @@ -8,14 +8,15 @@ use Valet\Brew; use Valet\CommandLine; use Valet\Filesystem; + use function Valet\info; class Elasticsearch extends AbstractDockerService { /** @var string */ - const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/elasticsearch/elasticsearch.conf'; + protected const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/elasticsearch/elasticsearch.conf'; /** @var string */ - const NGINX_CONFIGURATION_PATH = VALET_HOME_PATH . '/Nginx/elasticsearch.conf'; + protected const NGINX_CONFIGURATION_PATH = VALET_HOME_PATH . '/Nginx/elasticsearch.conf'; /** @var string */ protected const ES_DEFAULT_VERSION = 'opensearch'; // which is v2 in Brew, @todo; maybe support v1.2 using docker? @@ -36,8 +37,8 @@ class Elasticsearch extends AbstractDockerService */ public function __construct( CommandLine $cli, - Filesystem $files, - Brew $brew + Filesystem $files, + Brew $brew ) { parent::__construct($cli, $files); @@ -122,7 +123,10 @@ public function useVersion($version = self::ES_DEFAULT_VERSION, $tld = 'test') { if (!$this->isSupportedVersion($version)) { throw new DomainException( - sprintf('Invalid Elasticsearch version given. Available versions: %s', implode(', ', static::ES_SUPPORTED_VERSIONS)) + sprintf( + 'Invalid Elasticsearch version given. Available versions: %s', + implode(', ', static::ES_SUPPORTED_VERSIONS) + ) ); } @@ -217,7 +221,8 @@ public function install($version = self::ES_DEFAULT_VERSION, $tld = 'test') // opensearch requires openjdk (installed automatically) // elasticsearch@6 requires openjdk@17 (installed automatically) // seems like there can be only one openjdk when installing. after installing it doesn't matter. - // if this dependency is installed we need to launch es with this java version, see https://github.com/Homebrew/homebrew-core/issues/100260 + // if this dependency is installed we need to launch es with this java version, + // see https://github.com/Homebrew/homebrew-core/issues/100260 $this->brew->ensureInstalled($version); diff --git a/cli/ValetPlus/Extended/Configuration.php b/cli/ValetPlus/Extended/Configuration.php index 122e0476..e06e4e6d 100644 --- a/cli/ValetPlus/Extended/Configuration.php +++ b/cli/ValetPlus/Extended/Configuration.php @@ -75,6 +75,6 @@ protected function installNewsysLogRotation(): void $contents ); - //@todo; Set up log rotation for BREW_PREFIX . '/var/log/' to rotate elasticsearch logs + //@todo; Set up log rotation for BREW_PREFIX . '/var/log/' to rotate elasticsearch logs } } diff --git a/cli/ValetPlus/Extended/PhpFpm.php b/cli/ValetPlus/Extended/PhpFpm.php index fc116492..0b0b78be 100644 --- a/cli/ValetPlus/Extended/PhpFpm.php +++ b/cli/ValetPlus/Extended/PhpFpm.php @@ -33,13 +33,13 @@ class PhpFpm extends ValetPhpFpm * @param PhpExtension $phpExtension */ public function __construct( - Brew $brew, - CommandLine $cli, - Filesystem $files, + Brew $brew, + CommandLine $cli, + Filesystem $files, Configuration $config, - Site $site, - Nginx $nginx, - PhpExtension $phpExtension + Site $site, + Nginx $nginx, + PhpExtension $phpExtension ) { parent::__construct($brew, $cli, $files, $config, $site, $nginx); @@ -117,7 +117,7 @@ public function createConfigurationFiles(string $phpVersion): void $event = new DataEvent(); $event->set('php_version', $phpVersion); $event->set('php_dir', $destDir); - - $this->eventDispatcher->dispatch($event, 'after_create_php_config'); //@todo; dispatch event when config should be removed? + //@todo; dispatch event when config should be removed? + $this->eventDispatcher->dispatch($event, 'after_create_php_config'); } } diff --git a/cli/ValetPlus/Extended/Status.php b/cli/ValetPlus/Extended/Status.php index 29f4fc7c..35c63198 100644 --- a/cli/ValetPlus/Extended/Status.php +++ b/cli/ValetPlus/Extended/Status.php @@ -41,14 +41,14 @@ class Status extends ValetStatus */ public function __construct( Configuration $config, - Brew $brew, - CommandLine $cli, - Filesystem $files, - Mysql $mysql, - Mailhog $mailhog, - Varnish $varnish, - Redis $redis, - Rabbitmq $rabbitmq + Brew $brew, + CommandLine $cli, + Filesystem $files, + Mysql $mysql, + Mailhog $mailhog, + Varnish $varnish, + Redis $redis, + Rabbitmq $rabbitmq ) { parent::__construct($config, $brew, $cli, $files); diff --git a/cli/ValetPlus/Mailhog.php b/cli/ValetPlus/Mailhog.php index 3a5766f8..53934212 100644 --- a/cli/ValetPlus/Mailhog.php +++ b/cli/ValetPlus/Mailhog.php @@ -11,19 +11,20 @@ use Valet\Configuration; use Valet\Filesystem; use WeProvide\ValetPlus\Event\DataEvent; + use function Valet\info; class Mailhog extends AbstractService { /** @var string */ - const SERVICE_NAME = 'mailhog'; + protected const SERVICE_NAME = 'mailhog'; /** @var string */ - const PHP_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.ini'; + protected const PHP_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.ini'; /** @var string */ - const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.conf'; + protected const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.conf'; /** @var string */ - const NGINX_CONFIGURATION_PATH = VALET_HOME_PATH . '/Nginx/mailhog.conf'; + protected const NGINX_CONFIGURATION_PATH = VALET_HOME_PATH . '/Nginx/mailhog.conf'; /** @var EventDispatcher */ protected $eventDispatcher; @@ -36,9 +37,9 @@ class Mailhog extends AbstractService */ public function __construct( Configuration $configuration, - Brew $brew, - Filesystem $files, - CommandLine $cli + Brew $brew, + Filesystem $files, + CommandLine $cli ) { parent::__construct($configuration, $brew, $files, $cli); diff --git a/cli/ValetPlus/Mysql.php b/cli/ValetPlus/Mysql.php index 7b0f7105..502ca839 100644 --- a/cli/ValetPlus/Mysql.php +++ b/cli/ValetPlus/Mysql.php @@ -11,6 +11,7 @@ use Valet\Configuration; use Valet\Filesystem; use Valet\Site; + use function Valet\info; use function Valet\table; use function Valet\tap; @@ -18,13 +19,13 @@ class Mysql { - const MYSQL_CONF_DIR = 'etc'; - const MYSQL_CONF = 'etc/my.cnf'; - const MAX_FILES_CONF = '/Library/LaunchDaemons/limit.maxfiles.plist'; - const MYSQL_DATA_DIR = 'var/mysql'; - const MYSQL_ROOT_PASSWORD = 'root'; - const MYSQL_DEFAULT_VERSION = 'mysql@5.7'; - const MYSQL_SUPPORTED_VERSIONS = ['mysql', 'mysql@8.0', 'mysql@5.7', 'mariadb']; + private const MYSQL_CONF_DIR = 'etc'; + private const MYSQL_CONF = 'etc/my.cnf'; + private const MAX_FILES_CONF = '/Library/LaunchDaemons/limit.maxfiles.plist'; + private const MYSQL_DATA_DIR = 'var/mysql'; + private const MYSQL_ROOT_PASSWORD = 'root'; + private const MYSQL_DEFAULT_VERSION = 'mysql@5.7'; + private const MYSQL_SUPPORTED_VERSIONS = ['mysql', 'mysql@8.0', 'mysql@5.7', 'mariadb']; /** @var Brew */ protected $brew; @@ -50,11 +51,11 @@ class Mysql * @param Site $site */ public function __construct( - Brew $brew, - CommandLine $cli, - Filesystem $files, + Brew $brew, + CommandLine $cli, + Filesystem $files, Configuration $configuration, - Site $site + Site $site ) { $this->brew = $brew; $this->cli = $cli; @@ -199,17 +200,23 @@ public function setRootPassword($oldPwd = '', $newPwd = self::MYSQL_ROOT_PASSWOR switch ($version) { case 'mariadb': - $this->cli->run("mysqladmin -u root --password='" . $oldPwd . "' password " . $newPwd, function () use (&$success) { - warning('Setting mysql password for root user failed. '); - $success = false; - }); + $this->cli->run( + "mysqladmin -u root --password='" . $oldPwd . "' password " . $newPwd, + function () use (&$success) { + warning('Setting mysql password for root user failed. '); + $success = false; + } + ); break; case 'mysql@5.7': - $this->cli->runAsUser("mysqladmin -u root --password='" . $oldPwd . "' password " . $newPwd, function () use (&$success) { - warning('Setting mysql password for root user failed. '); - $success = false; - }); + $this->cli->runAsUser( + "mysqladmin -u root --password='" . $oldPwd . "' password " . $newPwd, + function () use (&$success) { + warning('Setting mysql password for root user failed. '); + $success = false; + } + ); break; case 'mysql@8.0': @@ -372,8 +379,8 @@ public function createDatabase($name) public function isDatabaseExists($name) { $name = $this->getDatabaseName($name); - - $query = $this->query("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" . $this->escape($name) . "'", false); + $sql = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" . $this->escape($name) . "'"; + $query = $this->query($sql, false); return (bool)$query->num_rows; } @@ -401,7 +408,10 @@ public function exportDatabase($filename, $database) $filename = $filename . '.gz'; } - $this->cli->passthru('mysqldump ' . \escapeshellarg($database) . ' | gzip > ' . \escapeshellarg($filename ?: $database)); + $this->cli->passthru( + 'mysqldump ' . \escapeshellarg($database) . ' | ' . + 'gzip > ' . \escapeshellarg($filename ?: $database) + ); return [ 'database' => $database, diff --git a/cli/ValetPlus/PhpExtension.php b/cli/ValetPlus/PhpExtension.php index 8988b000..14e0b49f 100644 --- a/cli/ValetPlus/PhpExtension.php +++ b/cli/ValetPlus/PhpExtension.php @@ -7,13 +7,14 @@ use Valet\Brew; use Valet\CommandLine; use Valet\Filesystem; + use function Valet\info; use function Valet\output; class PhpExtension { /** @var string */ - const PHP_EXTENSIONS_BREW_TAP = 'shivammathur/extensions'; + protected const PHP_EXTENSIONS_BREW_TAP = 'shivammathur/extensions'; /** @var string */ public const XDEBUG_EXTENSION = 'xdebug'; @@ -26,7 +27,7 @@ class PhpExtension /** @var string */ public const DATASTRUCTURE_EXTENSION = 'ds'; - const PHP_EXTENSIONS = [ + protected const PHP_EXTENSIONS = [ self::XDEBUG_EXTENSION => [ 'default' => false, 'ini_files' => [ @@ -70,9 +71,9 @@ class PhpExtension * @param Filesystem $files */ public function __construct( - Brew $brew, + Brew $brew, CommandLine $cli, - Filesystem $files + Filesystem $files ) { $this->brew = $brew; $this->cli = $cli; @@ -92,7 +93,6 @@ public function installExtensions($phpVersion, $onlyDefaults = true) } if ($this->installExtension($extension, $phpVersion)) { - } } } @@ -125,7 +125,6 @@ public function uninstallExtensions($phpVersion, $phpIniConfigPath) info("Uninstalling extensions for PHP " . $phpVersion); foreach (static::PHP_EXTENSIONS as $extension => $settings) { if ($this->uninstallExtension($extension, $phpVersion, $phpIniConfigPath)) { - } } } @@ -239,8 +238,10 @@ protected function uninstall($extension, $phpVersion, $phpIniConfigPath) */ protected function isDefaultExtension($extension) { - if (array_key_exists('default', static::PHP_EXTENSIONS[$extension]) && - static::PHP_EXTENSIONS[$extension]['default'] === true) { + if ( + array_key_exists('default', static::PHP_EXTENSIONS[$extension]) && + static::PHP_EXTENSIONS[$extension]['default'] === true + ) { return true; } elseif (array_key_exists('default', static::PHP_EXTENSIONS[$extension]) === false) { return true; diff --git a/cli/ValetPlus/Rabbitmq.php b/cli/ValetPlus/Rabbitmq.php index c1910315..2ca6071e 100644 --- a/cli/ValetPlus/Rabbitmq.php +++ b/cli/ValetPlus/Rabbitmq.php @@ -9,7 +9,7 @@ class Rabbitmq extends AbstractService { /** @var string */ - const SERVICE_NAME = 'rabbitmq'; + protected const SERVICE_NAME = 'rabbitmq'; /** * @inheritdoc diff --git a/cli/ValetPlus/Redis.php b/cli/ValetPlus/Redis.php index a13e4ae7..a1c8a7be 100644 --- a/cli/ValetPlus/Redis.php +++ b/cli/ValetPlus/Redis.php @@ -9,7 +9,7 @@ class Redis extends AbstractService { /** @var string */ - const SERVICE_NAME = 'redis'; + protected const SERVICE_NAME = 'redis'; /** * @inheritdoc diff --git a/cli/ValetPlus/Varnish.php b/cli/ValetPlus/Varnish.php index fe0409a6..e7779c61 100644 --- a/cli/ValetPlus/Varnish.php +++ b/cli/ValetPlus/Varnish.php @@ -9,7 +9,7 @@ class Varnish extends AbstractService { /** @var string */ - const SERVICE_NAME = 'varnish'; + protected const SERVICE_NAME = 'varnish'; /** * @inheritdoc diff --git a/cli/ValetPlus/Xdebug.php b/cli/ValetPlus/Xdebug.php index 14c346b1..ec3d7527 100644 --- a/cli/ValetPlus/Xdebug.php +++ b/cli/ValetPlus/Xdebug.php @@ -8,6 +8,7 @@ use Valet\CommandLine; use Valet\Filesystem; use Valet\PhpFpm; + use function Valet\warning; class Xdebug extends AbstractPhpExtension @@ -28,11 +29,11 @@ class Xdebug extends AbstractPhpExtension * @param Filesystem $files */ public function __construct( - Brew $brew, - PhpFpm $phpFpm, + Brew $brew, + PhpFpm $phpFpm, PhpExtension $phpExtension, - CommandLine $cli, - Filesystem $files + CommandLine $cli, + Filesystem $files ) { parent::__construct($brew, $phpFpm, $phpExtension); diff --git a/cli/stubs/drivers/custom/PimcoreValetDriver.php b/cli/stubs/drivers/custom/PimcoreValetDriver.php index b67d607a..115bff1b 100644 --- a/cli/stubs/drivers/custom/PimcoreValetDriver.php +++ b/cli/stubs/drivers/custom/PimcoreValetDriver.php @@ -17,7 +17,7 @@ class PimcoreValetDriver extends ValetDriver */ public function serves(string $sitePath, string $siteName, string $uri): bool { - if (file_exists($sitePath.'/pimcore')) { + if (file_exists($sitePath . '/pimcore')) { return true; } @@ -38,9 +38,12 @@ public function isStaticFile(string $sitePath, string $siteName, string $uri) if (strpos($uri, '/cache-buster') === 0) { // https://stackoverflow.com/questions/25543974/how-to-get-string-after-second-slash-in-url-using-php $last = explode("/", $uri, 3); - $uri = '/'.$last[2]; + $uri = '/' . $last[2]; } - if (file_exists($staticFilePath = $sitePath.'/var/assets'.$uri) || file_exists($staticFilePath = $sitePath.$uri)) { + if ( + file_exists($staticFilePath = $sitePath . '/var/assets' . $uri) || + file_exists($staticFilePath = $sitePath . $uri) + ) { return $staticFilePath; } @@ -60,9 +63,9 @@ public function frontControllerPath(string $sitePath, string $siteName, string $ $this->loadServerEnvironmentVariables($sitePath, $siteName); if (strpos($uri, '/install') === 0) { - return $sitePath.'/install.php'; + return $sitePath . '/install.php'; } - return $sitePath.'/app.php'; + return $sitePath . '/app.php'; } } diff --git a/cli/stubs/drivers/custom/ShopwarePlatformValetDriver.php b/cli/stubs/drivers/custom/ShopwarePlatformValetDriver.php index 48a05f37..54ebb848 100644 --- a/cli/stubs/drivers/custom/ShopwarePlatformValetDriver.php +++ b/cli/stubs/drivers/custom/ShopwarePlatformValetDriver.php @@ -16,9 +16,9 @@ class ShopwarePlatformValetDriver extends ValetDriver */ public function serves(string $sitePath, string $siteName, string $uri): bool { - $corePath = realpath($sitePath.'/vendor/shopware/core'); - $platformPath = realpath($sitePath.'/vendor/shopware/platform'); - + $corePath = realpath($sitePath . '/vendor/shopware/core'); + $platformPath = realpath($sitePath . '/vendor/shopware/platform'); + if (($corePath !== false && is_dir($corePath)) || ($platformPath !== false && is_dir($platformPath))) { return true; } @@ -34,9 +34,9 @@ public function serves(string $sitePath, string $siteName, string $uri): bool */ public function isStaticFile(string $sitePath, string $siteName, string $uri) { - if (file_exists($staticFilePath = $sitePath.'/public'.$uri)) { + if (file_exists($staticFilePath = $sitePath . '/public' . $uri)) { return $staticFilePath; - } elseif ($this->isActualFile($staticFilePath = $sitePath.$uri)) { + } elseif ($this->isActualFile($staticFilePath = $sitePath . $uri)) { return $staticFilePath; } return false; @@ -56,7 +56,7 @@ public function frontControllerPath(string $sitePath, string $siteName, string $ if ($this->isInstallPath($sitePath, $uri)) { $installPath = $this->buildInstallPath($sitePath, $uri); $_SERVER['SCRIPT_FILENAME'] = $installPath; - $_SERVER['SCRIPT_NAME'] = str_replace($sitePath.'/public', '', $installPath); + $_SERVER['SCRIPT_NAME'] = str_replace($sitePath . '/public', '', $installPath); $_SERVER['DOCUMENT_ROOT'] = $sitePath; return $installPath; } @@ -64,12 +64,12 @@ public function frontControllerPath(string $sitePath, string $siteName, string $ if ($this->isUpdatePath($sitePath, $uri)) { $updatePath = $this->buildUpdatePath($sitePath, $uri); $_SERVER['SCRIPT_FILENAME'] = $updatePath; - $_SERVER['SCRIPT_NAME'] = str_replace($sitePath.'/public', '', $updatePath); + $_SERVER['SCRIPT_NAME'] = str_replace($sitePath . '/public', '', $updatePath); $_SERVER['DOCUMENT_ROOT'] = $sitePath; return $updatePath; } - return $sitePath.'/public/index.php'; + return $sitePath . '/public/index.php'; } /** * check if uri contains shopware install path diff --git a/cli/stubs/drivers/magento2/env.php b/cli/stubs/drivers/magento2/env.php index 6875a25a..a2761d59 100644 --- a/cli/stubs/drivers/magento2/env.php +++ b/cli/stubs/drivers/magento2/env.php @@ -1,4 +1,5 @@ [ 'frontName' => 'admin' diff --git a/composer.json b/composer.json index 8f2ea50b..2b6f0331 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,14 @@ "config": { "platform-check": false }, + "bin": [ + "valet-plus" + ], "require": { "php": ">=7.1 <8.3", "laravel/valet": "^4.5" }, - "bin": [ - "valet-plus" - ] + "require-dev": { + "squizlabs/php_codesniffer": "^3.8" + } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..bcded264 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,10 @@ + + + cli/ValetPlus + cli/stubs/drivers + + + + + +