From 1db73eb669626044c0f19f9b64f0d3c55ea367e8 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 18 Mar 2021 13:20:16 +0000 Subject: [PATCH 01/14] feat: simplify language --- app/Actions/UpgradeSavedConfiguration.php | 28 ++++++++----------- .../Feature/UpgradeSavedConfigurationTest.php | 4 +-- tests/TestCase.php | 5 +++- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/Actions/UpgradeSavedConfiguration.php b/app/Actions/UpgradeSavedConfiguration.php index 0b64f3c9..74c13911 100644 --- a/app/Actions/UpgradeSavedConfiguration.php +++ b/app/Actions/UpgradeSavedConfiguration.php @@ -9,14 +9,16 @@ class UpgradeSavedConfiguration { private $configurationVersion = 1; - + private $configDir; + private $configFilePath; + private $lastVersionUpdateFilePath; + private $commented = []; private $removedConfigurationKeys = [ 'NODE', 'MIX', 'AUTH', 'FRONTEND', ]; - private $newConfiguration = [ 'MIGRATE_DATABASE' => [ 'commented' => false, @@ -51,12 +53,6 @@ class UpgradeSavedConfiguration ], ]; - private $configDir; - private $configFilePath; - private $lastVersionUpdateFilePath; - - private $commented = []; - public function __construct() { $this->configDir = config('home_dir') . '/.lambo'; @@ -64,7 +60,7 @@ public function __construct() $this->lastVersionUpdateFilePath = "{$this->configDir}/.last_version_update"; } - public function __invoke() + public function __invoke(): bool { if (! $this->shouldUpgrade()) { return false; @@ -81,7 +77,7 @@ public function __invoke() return true; } - private function shouldUpgrade() + private function shouldUpgrade(): bool { if (! File::isFile($this->configFilePath)) { return false; @@ -98,10 +94,10 @@ private function shouldUpgrade() return false; } - public function upgrade(string $savedConfiguration, array $unusedConfigurationKeys, array $newConfiguration = []): string + public function upgrade(string $savedConfiguration, array $removedConfigurationKeys, array $newConfiguration = []): string { return implode(PHP_EOL, [ - $this->commentUnusedConfiguration($savedConfiguration, $unusedConfigurationKeys), + $this->commentRemovedConfiguration($savedConfiguration, $removedConfigurationKeys), "\n# ------------------------------------------------------------------------------", '# ' . Carbon::now()->format('j-M-Y g:i a') . ' (auto-generated by Lambo):', '# ------------------------------------------------------------------------------', @@ -110,7 +106,7 @@ public function upgrade(string $savedConfiguration, array $unusedConfigurationKe ]); } - private function commentUnusedConfiguration(string $savedConfiguration, array $oldConfigurationKeys): string + private function commentRemovedConfiguration(string $savedConfiguration, array $oldConfigurationKeys): string { return collect(explode("\n", $savedConfiguration))->transform(function ($item) use ($oldConfigurationKeys) { $matched = collect($oldConfigurationKeys)->reduce(function ($carry, $oldKey) use ($item) { @@ -124,15 +120,15 @@ private function commentUnusedConfiguration(string $savedConfiguration, array $o })->implode("\n"); } - private function summarizeComments() + private function summarizeComments(): string { if (count($this->commented) < 1) { return ''; } return implode(PHP_EOL, [ - '# Lambo has commented out the following configuration items; they are no', - '# longer used, and you may safely remove them:', + '# Lambo has commented out the following configuration items as they', + '# are no-longer used. You may safely remove them:', collect($this->commented)->reduce(function ($carry, $item) { return "$carry# {$item}\n"; }, '') diff --git a/tests/Feature/UpgradeSavedConfigurationTest.php b/tests/Feature/UpgradeSavedConfigurationTest.php index d9c7a09f..f19c8ad2 100644 --- a/tests/Feature/UpgradeSavedConfigurationTest.php +++ b/tests/Feature/UpgradeSavedConfigurationTest.php @@ -55,8 +55,8 @@ function it_upgrades_saved_configuration() # ------------------------------------------------------------------------------ # 1-Apr-2020 5:00 am (auto-generated by Lambo): # ------------------------------------------------------------------------------ -# Lambo has commented out the following configuration items; they are no -# longer used, and you may safely remove them: +# Lambo has commented out the following configuration items as they +# are no-longer used. You may safely remove them: # OLD_KEY=foo # ANOTHER_OLD_KEY=foo diff --git a/tests/TestCase.php b/tests/TestCase.php index aa6f48d0..0b6ebd48 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -45,11 +45,14 @@ protected function todo(array $lines) protected function skipWithMessage(array $lines, $title = 'SKIPPED'): void { + $lineLength = 80; $header = $this->center(" [ {$title} ] ", '=', $lineLength); + $testName = $this->center(str_replace('_', ' ', $this->getName()), ' ', $lineLength); $section = str_repeat('=', $lineLength); + $horizontalRule = str_repeat('-', $lineLength); $message = implode(PHP_EOL, $lines); - $this->markTestSkipped("{$header}\n{$message}\n{$section}"); + $this->markTestSkipped("{$header}\n{$testName}\n{$horizontalRule}\n{$message}\n{$section}"); } protected function center(string $title, string $padChar = ' ', int $lineLength = 80): string From 771a4072f14d6380018c30800d007d1505df122b Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 19 Mar 2021 12:14:40 +0000 Subject: [PATCH 02/14] Add and configure tightenco/duster. Fix any warnings/errors it highlights --- .gitignore | 1 + .phpcs.xml.dist | 8 + app/Actions/DisplayLamboWelcome.php | 8 +- app/Actions/UpgradeSavedConfiguration.php | 12 +- app/Actions/ValetLink.php | 1 + app/Actions/ValidateConfiguration.php | 28 +- app/Commands/Debug.php | 11 +- app/Commands/EditAfter.php | 10 +- app/Commands/EditConfig.php | 10 +- app/Configuration/LamboConfiguration.php | 50 +-- app/Configuration/SetConfig.php | 34 +- composer.json | 3 +- composer.lock | 349 +++++++++++++++++- .../ConfigureFrontendFrameworkTest.php | 2 +- tests/Feature/Fakes/FakeProcess.php | 1 + tests/Feature/SavedConfigTest.php | 1 - .../Feature/UpgradeSavedConfigurationTest.php | 4 +- tests/Unit/SetConfigTest.php | 2 +- tlint.json | 7 + 19 files changed, 456 insertions(+), 86 deletions(-) create mode 100644 .phpcs.xml.dist create mode 100644 tlint.json diff --git a/.gitignore b/.gitignore index c0a17182..9b07bb7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor .phpunit.result.cache /storage/framework/ +.php_cs.cache diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 00000000..1c872c74 --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,8 @@ + + + app + config + tests + + + diff --git a/app/Actions/DisplayLamboWelcome.php b/app/Actions/DisplayLamboWelcome.php index d91f25fa..52063275 100644 --- a/app/Actions/DisplayLamboWelcome.php +++ b/app/Actions/DisplayLamboWelcome.php @@ -4,12 +4,12 @@ class DisplayLamboWelcome { - protected $lamboLogo = " + protected $lamboLogo = ' __ __ :version: / / ____ _____ ___ / /_ ____ / / / __ `/ __ `__ \/ __ \/ __ \ / /___/ /_/ / / / / / / /_/ / /_/ / - /_____/\__,_/_/ /_/ /_/_.___/\____/"; + /_____/\__,_/_/ /_/ /_/_.___/\____/'; protected $welcomeText = " Lambo: Super-powered 'laravel new' for Laravel and Valet."; @@ -23,12 +23,12 @@ public function __invoke() { foreach (explode("\n", $this->lamboLogo) as $line) { // Extra space on the end fixes an issue with console when it ends with backslash - app('console-writer')->text("$line "); + app('console-writer')->text("{$line} "); } foreach (explode("\n", $this->welcomeText) as $line) { // Extra space on the end fixes an issue with console when it ends with backslash - app('console-writer')->text($line . " "); + app('console-writer')->text("{$line} "); } } } diff --git a/app/Actions/UpgradeSavedConfiguration.php b/app/Actions/UpgradeSavedConfiguration.php index 74c13911..af4f7875 100644 --- a/app/Actions/UpgradeSavedConfiguration.php +++ b/app/Actions/UpgradeSavedConfiguration.php @@ -28,28 +28,28 @@ class UpgradeSavedConfiguration 'options:', ' true, 1, "yes" or "on"', ' false (default), 0, "no" or "off"', - ] + ], ], 'DB_HOST' => [ 'commented' => false, 'default' => '127.0.0.1', 'description' => [ 'The database host.', - ] + ], ], 'DB_PORT' => [ 'commented' => true, 'default' => '', 'description' => [ 'The database port.', - ] + ], ], 'DB_NAME' => [ 'commented' => true, 'default' => '', 'description' => [ 'The database name.', - ] + ], ], ]; @@ -130,7 +130,7 @@ private function summarizeComments(): string '# Lambo has commented out the following configuration items as they', '# are no-longer used. You may safely remove them:', collect($this->commented)->reduce(function ($carry, $item) { - return "$carry# {$item}\n"; + return "{$carry}# {$item}\n"; }, '') ]); } @@ -143,7 +143,7 @@ private function addNewConfiguration(array $newConfiguration): string return collect(array_keys($newConfiguration))->reduce(function ($carry, $key) use ($newConfiguration) { $description = collect($newConfiguration[$key]['description'])->reduce(function ($carry, $item) { - return "$carry# {$item}\n"; + return "{$carry}# {$item}\n"; }, ''); $configurationItem = sprintf( diff --git a/app/Actions/ValetLink.php b/app/Actions/ValetLink.php index 6456ac6d..6bf12f57 100644 --- a/app/Actions/ValetLink.php +++ b/app/Actions/ValetLink.php @@ -10,6 +10,7 @@ class ValetLink use AbortsCommands; protected $shell; + private $consoleWriter; public function __construct(Shell $shell, ConsoleWriter $consoleWriter) diff --git a/app/Actions/ValidateConfiguration.php b/app/Actions/ValidateConfiguration.php index b74bc4bc..42c54f2e 100644 --- a/app/Actions/ValidateConfiguration.php +++ b/app/Actions/ValidateConfiguration.php @@ -30,6 +30,19 @@ public function __invoke() } } + protected function debugReport(): void + { + $this->consoleWriter->panel('Debug', 'Start', 'fg=black;bg=white'); + + $this->consoleWriter->text([ + 'Configuration may have changed after validation', + 'Configuration is now as follows:', + ]); + $this->configToTable(); + + $this->consoleWriter->panel('Debug', 'End', 'fg=black;bg=white'); + } + private function getFrontendConfiguration(): string { $inertia = config('lambo.store.inertia'); @@ -53,7 +66,7 @@ private function chooseBetweenFrontends() $options = [ 'use inertia' => 'inertia', 'use livewire' => 'livewire', - "continue without frontend scaffolding" => 'none', + 'continue without frontend scaffolding' => 'none', ]; $choice = app('console')->choice('What would you like to do?', array_keys($options), 2); @@ -68,17 +81,4 @@ private function checkTeamsConfiguration() $this->consoleWriter->note('You specified --teams but neither inertia or livewire are being used. Skipping...'); } } - - protected function debugReport(): void - { - $this->consoleWriter->panel('Debug', 'Start', 'fg=black;bg=white'); - - $this->consoleWriter->text([ - 'Configuration may have changed after validation', - 'Configuration is now as follows:', - ]); - $this->configToTable(); - - $this->consoleWriter->panel('Debug', 'End', 'fg=black;bg=white'); - } } diff --git a/app/Commands/Debug.php b/app/Commands/Debug.php index 861d02ed..cf061e91 100644 --- a/app/Commands/Debug.php +++ b/app/Commands/Debug.php @@ -87,7 +87,8 @@ protected function debugReport(): void 'livewire', 'with-teams', 'projectName', - ], '--' + ], + '--' ); $this->consoleWriter->text('Saved configuration:'); @@ -120,13 +121,7 @@ protected function debugReport(): void ); $this->consoleWriter->text('Shell environment variables:'); - $this->arrayToTable( - $_SERVER, - [ - 'EDITOR' - ], - '$' - ); + $this->arrayToTable($_SERVER, ['EDITOR',], '$'); $this->consoleWriter->panel('Debug', 'End', 'fg=black;bg=white'); } diff --git a/app/Commands/EditAfter.php b/app/Commands/EditAfter.php index 090a1540..f4ec9211 100644 --- a/app/Commands/EditAfter.php +++ b/app/Commands/EditAfter.php @@ -23,15 +23,15 @@ public function handle() }); $commandLineConfiguration = new CommandLineConfiguration([ - 'editor' => LamboConfiguration::EDITOR + 'editor' => LamboConfiguration::EDITOR, ]); $savedConfiguration = new SavedConfiguration([ - 'CODEEDITOR' => LamboConfiguration::EDITOR + 'CODEEDITOR' => LamboConfiguration::EDITOR, ]); $shellConfiguration = new ShellConfiguration([ - 'EDITOR' => LamboConfiguration::EDITOR + 'EDITOR' => LamboConfiguration::EDITOR, ]); (new SetConfig( @@ -39,11 +39,11 @@ public function handle() $savedConfiguration, $shellConfiguration ))([ - LamboConfiguration::EDITOR => 'nano' + LamboConfiguration::EDITOR => 'nano', ]); try { - app(SavedConfig::class)->createOrEditConfigFile("after"); + app(SavedConfig::class)->createOrEditConfigFile('after'); } catch (LamboException $e) { app('console-writer')->exception($e->getMessage()); } diff --git a/app/Commands/EditConfig.php b/app/Commands/EditConfig.php index 0fe0ead1..6d5ad553 100644 --- a/app/Commands/EditConfig.php +++ b/app/Commands/EditConfig.php @@ -23,15 +23,15 @@ public function handle() }); $commandLineConfiguration = new CommandLineConfiguration([ - 'editor' => LamboConfiguration::EDITOR + 'editor' => LamboConfiguration::EDITOR, ]); $savedConfiguration = new SavedConfiguration([ - 'CODEEDITOR' => LamboConfiguration::EDITOR + 'CODEEDITOR' => LamboConfiguration::EDITOR, ]); $shellConfiguration = new ShellConfiguration([ - 'EDITOR' => LamboConfiguration::EDITOR + 'EDITOR' => LamboConfiguration::EDITOR, ]); (new SetConfig( @@ -39,11 +39,11 @@ public function handle() $savedConfiguration, $shellConfiguration ))([ - LamboConfiguration::EDITOR => 'nano' + LamboConfiguration::EDITOR => 'nano', ]); try { - app(SavedConfig::class)->createOrEditConfigFile("config"); + app(SavedConfig::class)->createOrEditConfigFile('config'); } catch (LamboException $e) { app('console-writer')->exception($e->getMessage()); } diff --git a/app/Configuration/LamboConfiguration.php b/app/Configuration/LamboConfiguration.php index aaca0740..69d57f8b 100644 --- a/app/Configuration/LamboConfiguration.php +++ b/app/Configuration/LamboConfiguration.php @@ -6,29 +6,29 @@ abstract class LamboConfiguration { - const EDITOR = 'editor'; - const PROJECT_NAME = 'project_name'; - const ROOT_PATH = 'root_path'; - const WITH_OUTPUT = 'with_output'; - const USE_DEVELOP_BRANCH = 'dev'; - const CREATE_DATABASE = 'create_database'; - const MIGRATE_DATABASE = 'migrate_database'; - const DATABASE_HOST = 'database_host'; - const DATABASE_PORT = 'database_port'; - const DATABASE_NAME = 'database_name'; - const DATABASE_USERNAME = 'database_username'; - const DATABASE_PASSWORD = 'database_password'; - const FRONTEND_FRAMEWORK = 'frontend'; - const FULL = 'full'; - const TLD = 'tld'; - const COMMIT_MESSAGE = 'commit_message'; - const VALET_LINK = 'valet_link'; - const VALET_SECURE = 'valet_secure'; - const BROWSER = 'browser'; - const INERTIA = 'inertia'; - const LIVEWIRE = 'livewire'; - const TEAMS = 'teams'; - const COMMAND = 'command'; + public const EDITOR = 'editor'; + public const PROJECT_NAME = 'project_name'; + public const ROOT_PATH = 'root_path'; + public const WITH_OUTPUT = 'with_output'; + public const USE_DEVELOP_BRANCH = 'dev'; + public const CREATE_DATABASE = 'create_database'; + public const MIGRATE_DATABASE = 'migrate_database'; + public const DATABASE_HOST = 'database_host'; + public const DATABASE_PORT = 'database_port'; + public const DATABASE_NAME = 'database_name'; + public const DATABASE_USERNAME = 'database_username'; + public const DATABASE_PASSWORD = 'database_password'; + public const FRONTEND_FRAMEWORK = 'frontend'; + public const FULL = 'full'; + public const TLD = 'tld'; + public const COMMIT_MESSAGE = 'commit_message'; + public const VALET_LINK = 'valet_link'; + public const VALET_SECURE = 'valet_secure'; + public const BROWSER = 'browser'; + public const INERTIA = 'inertia'; + public const LIVEWIRE = 'livewire'; + public const TEAMS = 'teams'; + public const COMMAND = 'command'; public function __construct(array $keyMap) { @@ -53,11 +53,11 @@ protected function get(string $key, array $array) return null; } - if (in_array(Str::lower($array[$key]), ["1", "true", "on", "yes"])) { + if (in_array(Str::lower($array[$key]), ['1', 'true', 'on', 'yes'])) { return true; } - if (in_array(Str::lower($array[$key]), ["0", "false", "off", "no"])) { + if (in_array(Str::lower($array[$key]), ['0', 'false', 'off', 'no'])) { return false; } diff --git a/app/Configuration/SetConfig.php b/app/Configuration/SetConfig.php index 99ec9397..d97bed59 100644 --- a/app/Configuration/SetConfig.php +++ b/app/Configuration/SetConfig.php @@ -11,11 +11,7 @@ class SetConfig { - private $commandLineConfiguration; - private $savedConfiguration; - private $shellConfiguration; protected $consoleWriter; - protected $fullFlags = [ LamboConfiguration::CREATE_DATABASE, LamboConfiguration::MIGRATE_DATABASE, @@ -23,8 +19,16 @@ class SetConfig LamboConfiguration::VALET_SECURE, ]; - public function __construct(CommandLineConfiguration $commandLineConfiguration, SavedConfiguration $savedConfiguration, ShellConfiguration $shellConfiguration, ConsoleWriter $consoleWriter) - { + private $commandLineConfiguration; + private $savedConfiguration; + private $shellConfiguration; + + public function __construct( + CommandLineConfiguration $commandLineConfiguration, + SavedConfiguration $savedConfiguration, + ShellConfiguration $shellConfiguration, + ConsoleWriter $consoleWriter + ) { $this->commandLineConfiguration = $commandLineConfiguration; $this->savedConfiguration = $savedConfiguration; $this->shellConfiguration = $shellConfiguration; @@ -45,7 +49,8 @@ public function __invoke($defaultConfiguration) // If we're in the "new" command, generate a few config items which // require others to be set above first. if (config('lambo.store.command') === NewCommand::class) { - config(['lambo.store.project_path' => config('lambo.store.root_path') . '/' . config('lambo.store.project_name')]); + $projectPath = config('lambo.store.root_path') . '/' . config('lambo.store.project_name'); + config(['lambo.store.project_path' => $projectPath]); config(['lambo.store.project_url' => $this->getProjectURL()]); } @@ -86,7 +91,14 @@ private function getTld(): string return json_decode(File::get($legacyValetConfig))->domain; } - throw new LamboException("Unable to find valet domain (tld) configuration.\nNo Valet configuration located at either of the following locations: \n - {$valetConfig}\n - {$legacyValetConfig}"); + throw new LamboException( + implode(PHP_EOL, [ + 'Unable to find valet domain (tld) configuration.', + 'No Valet configuration located at either of the following locations:', + "- {$valetConfig}", + "- {$legacyValetConfig}", + ]) + ); } private function getRootPath(string $key, $default) @@ -105,10 +117,12 @@ private function getDatabaseName(string $key, $default) private function getProjectURL(): string { - return sprintf("http%s://%s.%s", + return sprintf( + 'http%s://%s.%s', config('lambo.store.valet_secure') ? 's' : '', config('lambo.store.project_name'), - config('lambo.store.tld')); + config('lambo.store.tld') + ); } private function getMigrateDatabase(string $key, $default) diff --git a/composer.json b/composer.json index 2cf8e57e..e3f465ae 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "require-dev": { "laravel-zero/framework": "^8.0", "mockery/mockery": "^1.0", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.0", + "tightenco/duster": "^0.2.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 43819b58..3ed758cb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6b5bd209ad53de03e6958030dc09c900", + "content-hash": "3881fe5f0f4fedc4fd14861106afa3c3", "packages": [ { "name": "laravel/installer", @@ -980,6 +980,76 @@ ], "time": "2020-08-18T23:57:15+00:00" }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.1", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2020-12-07T18:04:37+00:00" + }, { "name": "doctrine/inflector", "version": "2.0.3", @@ -2146,6 +2216,60 @@ }, "time": "2020-11-29T20:22:49+00:00" }, + { + "name": "illuminate/view", + "version": "v8.33.1", + "source": { + "type": "git", + "url": "https://github.com/illuminate/view.git", + "reference": "696a1d6d2213be192429e97245a3d2bb4d6d1849" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/view/zipball/696a1d6d2213be192429e97245a3d2bb4d6d1849", + "reference": "696a1d6d2213be192429e97245a3d2bb4d6d1849", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/collections": "^8.0", + "illuminate/container": "^8.0", + "illuminate/contracts": "^8.0", + "illuminate/events": "^8.0", + "illuminate/filesystem": "^8.0", + "illuminate/macroable": "^8.0", + "illuminate/support": "^8.0", + "php": "^7.3|^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\View\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate View package.", + "homepage": "https://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "time": "2020-11-02T14:01:41+00:00" + }, { "name": "jolicode/jolinotif", "version": "v2.2.0", @@ -5113,6 +5237,62 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.5.8", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2020-10-23T02:01:07+00:00" + }, { "name": "symfony/error-handler", "version": "v5.2.1", @@ -5552,6 +5732,168 @@ ], "time": "2020-07-12T23:59:07+00:00" }, + { + "name": "tightenco/duster", + "version": "v0.2.1", + "source": { + "type": "git", + "url": "https://github.com/tighten/duster.git", + "reference": "5edae567216bf4ebef7c42e2de39036a1bb04cee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tighten/duster/zipball/5edae567216bf4ebef7c42e2de39036a1bb04cee", + "reference": "5edae567216bf4ebef7c42e2de39036a1bb04cee", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpunit/phpunit": "^9.0", + "squizlabs/php_codesniffer": "^3.5", + "tightenco/tighten-coding-standard": "^1.0", + "tightenco/tlint": "^5.0" + }, + "bin": [ + "bin/duster" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Stauffer", + "email": "matt@tighten.co", + "homepage": "https://tighten.co", + "role": "Developer" + } + ], + "description": "Automatic configuration for Laravel apps to apply Tighten's standard linting & code standards.", + "homepage": "https://github.com/tighten/duster", + "keywords": [ + "Code style", + "duster", + "laravel", + "php", + "phpcs", + "tightenco" + ], + "support": { + "issues": "https://github.com/tighten/duster/issues", + "source": "https://github.com/tighten/duster/tree/v0.2.1" + }, + "time": "2021-02-13T21:34:10+00:00" + }, + { + "name": "tightenco/tighten-coding-standard", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/tighten/tighten-coding-standard.git", + "reference": "b2416c4d9cfcbedb1865c685a58ac637a6642a4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tighten/tighten-coding-standard/zipball/b2416c4d9cfcbedb1865c685a58ac637a6642a4e", + "reference": "b2416c4d9cfcbedb1865c685a58ac637a6642a4e", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "php": "^7.4|^8.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "require-dev": { + "phpunit/phpunit": "^9.0", + "tightenco/tlint": "^5.0" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "Tighten\\TightenCodingStandard\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Stauffer", + "email": "matt@tighten.co", + "homepage": "https://tighten.co", + "role": "Developer" + } + ], + "description": "A PHP Code_Sniffer configuration for the Tighten coding standard.", + "homepage": "https://github.com/tighten/tighten-coding-standard", + "keywords": [ + "php", + "tighten-coding-standard", + "tightenco" + ], + "support": { + "issues": "https://github.com/tighten/tighten-coding-standard/issues", + "source": "https://github.com/tighten/tighten-coding-standard/tree/v1.0.1" + }, + "time": "2021-02-21T15:18:16+00:00" + }, + { + "name": "tightenco/tlint", + "version": "v5.0.15", + "source": { + "type": "git", + "url": "https://github.com/tighten/tlint.git", + "reference": "d7452af38f9e212f93e3466d9f8ab17f32b72012" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tighten/tlint/zipball/d7452af38f9e212f93e3466d9f8ab17f32b72012", + "reference": "d7452af38f9e212f93e3466d9f8ab17f32b72012", + "shasum": "" + }, + "require": { + "illuminate/view": "*", + "nikic/php-parser": "^4.5", + "php": ">=7.3", + "symfony/console": "^4.3 || ^5.0", + "symfony/process": "^4.3 || ^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "bin": [ + "bin/tlint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Tighten\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Logan Henson", + "email": "logan@loganhenson.com", + "role": "Developer" + } + ], + "description": "Tighten linter for Laravel conventions", + "homepage": "https://github.com/tighten/tlint", + "support": { + "issues": "https://github.com/tighten/tlint/issues", + "source": "https://github.com/tighten/tlint/tree/v5.0.15" + }, + "time": "2021-02-26T22:07:45+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v5.2.0", @@ -5766,8 +6108,9 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.2.5|^8.0", - "ext-json": "*" + "php": "^7.3|^8.0", + "ext-json": "*", + "ext-pdo": "*" }, "platform-dev": [], "plugin-api-version": "2.0.0" diff --git a/tests/Feature/ConfigureFrontendFrameworkTest.php b/tests/Feature/ConfigureFrontendFrameworkTest.php index 4efb9662..dfcdf879 100644 --- a/tests/Feature/ConfigureFrontendFrameworkTest.php +++ b/tests/Feature/ConfigureFrontendFrameworkTest.php @@ -121,7 +121,7 @@ function it_throws_a_lambo_exception_if_ui_framework_installation_fails() $this->skipWithMessage([ 'Currently failing due to WIP refactor.', 'the App\Shell mock needs to return both a successful and a failed', - 'process execution.' + 'process execution.', ]); $this->shouldFailFrontendFrameworkInstallation('inertia'); diff --git a/tests/Feature/Fakes/FakeProcess.php b/tests/Feature/Fakes/FakeProcess.php index df394df0..c1d4989b 100644 --- a/tests/Feature/Fakes/FakeProcess.php +++ b/tests/Feature/Fakes/FakeProcess.php @@ -6,6 +6,7 @@ class FakeProcess { public $isSuccessful; public $failedCommand; + private $output; private $errorOutput; diff --git a/tests/Feature/SavedConfigTest.php b/tests/Feature/SavedConfigTest.php index 4cb85625..9d337fe9 100644 --- a/tests/Feature/SavedConfigTest.php +++ b/tests/Feature/SavedConfigTest.php @@ -4,7 +4,6 @@ use App\Actions\SavedConfig; use App\LamboException; -use App\Shell; use Illuminate\Support\Facades\File; use Tests\Feature\Fakes\FakeProcess; use Tests\TestCase; diff --git a/tests/Feature/UpgradeSavedConfigurationTest.php b/tests/Feature/UpgradeSavedConfigurationTest.php index f19c8ad2..5e25e6d5 100644 --- a/tests/Feature/UpgradeSavedConfigurationTest.php +++ b/tests/Feature/UpgradeSavedConfigurationTest.php @@ -25,7 +25,7 @@ class UpgradeSavedConfigurationTest extends TestCase 'description' => [ 'The THING parameter enables Lambo to do a thing.', 'Valid options are foo, bar and flibble (default if not specified).', - ] + ], ], 'ANOTHER_THING' => [ 'commented' => false, @@ -33,7 +33,7 @@ class UpgradeSavedConfigurationTest extends TestCase 'description' => [ 'The ANOTHER_THING parameter enables Lambo to do a another thing.', 'Valid options are true or false (default if not specified).', - ] + ], ], ]; diff --git a/tests/Unit/SetConfigTest.php b/tests/Unit/SetConfigTest.php index 8cc90a9b..d207e2a6 100644 --- a/tests/Unit/SetConfigTest.php +++ b/tests/Unit/SetConfigTest.php @@ -261,7 +261,7 @@ function it_replaces_hyphens_with_underscores_in_database_names() ))([ 'root_path' => getcwd(), 'project_name' => null, - 'database_name' => null + 'database_name' => null, ]); $this->assertEquals('h_y_p_h_e_n_s', config('lambo.store.database_name')); diff --git a/tlint.json b/tlint.json new file mode 100644 index 00000000..4bc66129 --- /dev/null +++ b/tlint.json @@ -0,0 +1,7 @@ +{ + "preset": "tighten", + "disabled": [], + "excluded": [ + "node_modules" + ] +} From 3a9ac6375b14135dd1cefdb14fa369b22c4cb77f Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 18 Mar 2021 13:20:16 +0000 Subject: [PATCH 03/14] feat: simplify language --- app/Actions/UpgradeSavedConfiguration.php | 28 ++++++++----------- .../Feature/UpgradeSavedConfigurationTest.php | 4 +-- tests/TestCase.php | 5 +++- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/Actions/UpgradeSavedConfiguration.php b/app/Actions/UpgradeSavedConfiguration.php index 46798fd1..29bb60d6 100644 --- a/app/Actions/UpgradeSavedConfiguration.php +++ b/app/Actions/UpgradeSavedConfiguration.php @@ -11,14 +11,16 @@ class UpgradeSavedConfiguration // IMPORTANT NOTE: Every time we make *any* changes to configuration, we need // to increment this configurationVersion so that users get upgraded config private $configurationVersion = 1; - + private $configDir; + private $configFilePath; + private $lastVersionUpdateFilePath; + private $commented = []; private $removedConfigurationKeys = [ 'NODE', 'MIX', 'AUTH', 'FRONTEND', ]; - private $newConfiguration = [ 'MIGRATE_DATABASE' => [ 'commented' => false, @@ -53,12 +55,6 @@ class UpgradeSavedConfiguration ], ]; - private $configDir; - private $configFilePath; - private $lastVersionUpdateFilePath; - - private $commented = []; - public function __construct() { $this->configDir = config('home_dir') . '/.lambo'; @@ -66,7 +62,7 @@ public function __construct() $this->lastVersionUpdateFilePath = "{$this->configDir}/.last_version_update"; } - public function __invoke() + public function __invoke(): bool { if (! $this->shouldUpgrade()) { return false; @@ -83,7 +79,7 @@ public function __invoke() return true; } - private function shouldUpgrade() + private function shouldUpgrade(): bool { if (! File::isFile($this->configFilePath)) { return false; @@ -100,10 +96,10 @@ private function shouldUpgrade() return false; } - public function upgrade(string $savedConfiguration, array $unusedConfigurationKeys, array $newConfiguration = []): string + public function upgrade(string $savedConfiguration, array $removedConfigurationKeys, array $newConfiguration = []): string { return implode(PHP_EOL, [ - $this->commentUnusedConfiguration($savedConfiguration, $unusedConfigurationKeys), + $this->commentRemovedConfiguration($savedConfiguration, $removedConfigurationKeys), "\n# ------------------------------------------------------------------------------", '# ' . Carbon::now()->format('j-M-Y g:i a') . ' (auto-generated by Lambo):', '# ------------------------------------------------------------------------------', @@ -112,7 +108,7 @@ public function upgrade(string $savedConfiguration, array $unusedConfigurationKe ]); } - private function commentUnusedConfiguration(string $savedConfiguration, array $oldConfigurationKeys): string + private function commentRemovedConfiguration(string $savedConfiguration, array $oldConfigurationKeys): string { return collect(explode("\n", $savedConfiguration))->transform(function ($item) use ($oldConfigurationKeys) { $matched = collect($oldConfigurationKeys)->reduce(function ($carry, $oldKey) use ($item) { @@ -126,15 +122,15 @@ private function commentUnusedConfiguration(string $savedConfiguration, array $o })->implode("\n"); } - private function summarizeComments() + private function summarizeComments(): string { if (count($this->commented) < 1) { return ''; } return implode(PHP_EOL, [ - '# Lambo has commented out the following configuration items; they are no', - '# longer used, and you may safely remove them:', + '# Lambo has commented out the following configuration items as they', + '# are no-longer used. You may safely remove them:', collect($this->commented)->reduce(function ($carry, $item) { return "$carry# {$item}\n"; }, '') diff --git a/tests/Feature/UpgradeSavedConfigurationTest.php b/tests/Feature/UpgradeSavedConfigurationTest.php index d9c7a09f..f19c8ad2 100644 --- a/tests/Feature/UpgradeSavedConfigurationTest.php +++ b/tests/Feature/UpgradeSavedConfigurationTest.php @@ -55,8 +55,8 @@ function it_upgrades_saved_configuration() # ------------------------------------------------------------------------------ # 1-Apr-2020 5:00 am (auto-generated by Lambo): # ------------------------------------------------------------------------------ -# Lambo has commented out the following configuration items; they are no -# longer used, and you may safely remove them: +# Lambo has commented out the following configuration items as they +# are no-longer used. You may safely remove them: # OLD_KEY=foo # ANOTHER_OLD_KEY=foo diff --git a/tests/TestCase.php b/tests/TestCase.php index aa6f48d0..0b6ebd48 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -45,11 +45,14 @@ protected function todo(array $lines) protected function skipWithMessage(array $lines, $title = 'SKIPPED'): void { + $lineLength = 80; $header = $this->center(" [ {$title} ] ", '=', $lineLength); + $testName = $this->center(str_replace('_', ' ', $this->getName()), ' ', $lineLength); $section = str_repeat('=', $lineLength); + $horizontalRule = str_repeat('-', $lineLength); $message = implode(PHP_EOL, $lines); - $this->markTestSkipped("{$header}\n{$message}\n{$section}"); + $this->markTestSkipped("{$header}\n{$testName}\n{$horizontalRule}\n{$message}\n{$section}"); } protected function center(string $title, string $padChar = ' ', int $lineLength = 80): string From c75b1c30bde0ab75fbc4f77b38a24c85ddb567c7 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 19 Mar 2021 12:14:40 +0000 Subject: [PATCH 04/14] Add and configure tightenco/duster. Fix any warnings/errors it highlights --- .gitignore | 1 + .phpcs.xml.dist | 8 + app/Actions/DisplayLamboWelcome.php | 8 +- app/Actions/UpgradeSavedConfiguration.php | 6 +- app/Actions/ValetLink.php | 1 + app/Actions/ValidateConfiguration.php | 28 +- app/Commands/Debug.php | 11 +- app/Configuration/LamboConfiguration.php | 50 +-- app/Configuration/SetConfig.php | 34 +- composer.json | 3 +- composer.lock | 349 +++++++++++++++++- .../ConfigureFrontendFrameworkTest.php | 2 +- tests/Feature/Fakes/FakeProcess.php | 1 + tests/Feature/SavedConfigTest.php | 1 - .../Feature/UpgradeSavedConfigurationTest.php | 4 +- tests/Unit/SetConfigTest.php | 2 +- tlint.json | 7 + 17 files changed, 443 insertions(+), 73 deletions(-) create mode 100644 .phpcs.xml.dist create mode 100644 tlint.json diff --git a/.gitignore b/.gitignore index c0a17182..9b07bb7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor .phpunit.result.cache /storage/framework/ +.php_cs.cache diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 00000000..1c872c74 --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,8 @@ + + + app + config + tests + + + diff --git a/app/Actions/DisplayLamboWelcome.php b/app/Actions/DisplayLamboWelcome.php index d91f25fa..52063275 100644 --- a/app/Actions/DisplayLamboWelcome.php +++ b/app/Actions/DisplayLamboWelcome.php @@ -4,12 +4,12 @@ class DisplayLamboWelcome { - protected $lamboLogo = " + protected $lamboLogo = ' __ __ :version: / / ____ _____ ___ / /_ ____ / / / __ `/ __ `__ \/ __ \/ __ \ / /___/ /_/ / / / / / / /_/ / /_/ / - /_____/\__,_/_/ /_/ /_/_.___/\____/"; + /_____/\__,_/_/ /_/ /_/_.___/\____/'; protected $welcomeText = " Lambo: Super-powered 'laravel new' for Laravel and Valet."; @@ -23,12 +23,12 @@ public function __invoke() { foreach (explode("\n", $this->lamboLogo) as $line) { // Extra space on the end fixes an issue with console when it ends with backslash - app('console-writer')->text("$line "); + app('console-writer')->text("{$line} "); } foreach (explode("\n", $this->welcomeText) as $line) { // Extra space on the end fixes an issue with console when it ends with backslash - app('console-writer')->text($line . " "); + app('console-writer')->text("{$line} "); } } } diff --git a/app/Actions/UpgradeSavedConfiguration.php b/app/Actions/UpgradeSavedConfiguration.php index 29bb60d6..f49bfd00 100644 --- a/app/Actions/UpgradeSavedConfiguration.php +++ b/app/Actions/UpgradeSavedConfiguration.php @@ -37,7 +37,7 @@ class UpgradeSavedConfiguration 'default' => '127.0.0.1', 'description' => [ 'The database host. Defaults to 127.0.0.1.', - ] + ], ], 'DB_PORT' => [ 'commented' => true, @@ -132,7 +132,7 @@ private function summarizeComments(): string '# Lambo has commented out the following configuration items as they', '# are no-longer used. You may safely remove them:', collect($this->commented)->reduce(function ($carry, $item) { - return "$carry# {$item}\n"; + return "{$carry}# {$item}\n"; }, '') ]); } @@ -145,7 +145,7 @@ private function addNewConfiguration(array $newConfiguration): string return collect(array_keys($newConfiguration))->reduce(function ($carry, $key) use ($newConfiguration) { $description = collect($newConfiguration[$key]['description'])->reduce(function ($carry, $item) { - return "$carry# {$item}\n"; + return "{$carry}# {$item}\n"; }, ''); $configurationItem = sprintf( diff --git a/app/Actions/ValetLink.php b/app/Actions/ValetLink.php index 6456ac6d..6bf12f57 100644 --- a/app/Actions/ValetLink.php +++ b/app/Actions/ValetLink.php @@ -10,6 +10,7 @@ class ValetLink use AbortsCommands; protected $shell; + private $consoleWriter; public function __construct(Shell $shell, ConsoleWriter $consoleWriter) diff --git a/app/Actions/ValidateConfiguration.php b/app/Actions/ValidateConfiguration.php index b74bc4bc..42c54f2e 100644 --- a/app/Actions/ValidateConfiguration.php +++ b/app/Actions/ValidateConfiguration.php @@ -30,6 +30,19 @@ public function __invoke() } } + protected function debugReport(): void + { + $this->consoleWriter->panel('Debug', 'Start', 'fg=black;bg=white'); + + $this->consoleWriter->text([ + 'Configuration may have changed after validation', + 'Configuration is now as follows:', + ]); + $this->configToTable(); + + $this->consoleWriter->panel('Debug', 'End', 'fg=black;bg=white'); + } + private function getFrontendConfiguration(): string { $inertia = config('lambo.store.inertia'); @@ -53,7 +66,7 @@ private function chooseBetweenFrontends() $options = [ 'use inertia' => 'inertia', 'use livewire' => 'livewire', - "continue without frontend scaffolding" => 'none', + 'continue without frontend scaffolding' => 'none', ]; $choice = app('console')->choice('What would you like to do?', array_keys($options), 2); @@ -68,17 +81,4 @@ private function checkTeamsConfiguration() $this->consoleWriter->note('You specified --teams but neither inertia or livewire are being used. Skipping...'); } } - - protected function debugReport(): void - { - $this->consoleWriter->panel('Debug', 'Start', 'fg=black;bg=white'); - - $this->consoleWriter->text([ - 'Configuration may have changed after validation', - 'Configuration is now as follows:', - ]); - $this->configToTable(); - - $this->consoleWriter->panel('Debug', 'End', 'fg=black;bg=white'); - } } diff --git a/app/Commands/Debug.php b/app/Commands/Debug.php index 861d02ed..cf061e91 100644 --- a/app/Commands/Debug.php +++ b/app/Commands/Debug.php @@ -87,7 +87,8 @@ protected function debugReport(): void 'livewire', 'with-teams', 'projectName', - ], '--' + ], + '--' ); $this->consoleWriter->text('Saved configuration:'); @@ -120,13 +121,7 @@ protected function debugReport(): void ); $this->consoleWriter->text('Shell environment variables:'); - $this->arrayToTable( - $_SERVER, - [ - 'EDITOR' - ], - '$' - ); + $this->arrayToTable($_SERVER, ['EDITOR',], '$'); $this->consoleWriter->panel('Debug', 'End', 'fg=black;bg=white'); } diff --git a/app/Configuration/LamboConfiguration.php b/app/Configuration/LamboConfiguration.php index aaca0740..69d57f8b 100644 --- a/app/Configuration/LamboConfiguration.php +++ b/app/Configuration/LamboConfiguration.php @@ -6,29 +6,29 @@ abstract class LamboConfiguration { - const EDITOR = 'editor'; - const PROJECT_NAME = 'project_name'; - const ROOT_PATH = 'root_path'; - const WITH_OUTPUT = 'with_output'; - const USE_DEVELOP_BRANCH = 'dev'; - const CREATE_DATABASE = 'create_database'; - const MIGRATE_DATABASE = 'migrate_database'; - const DATABASE_HOST = 'database_host'; - const DATABASE_PORT = 'database_port'; - const DATABASE_NAME = 'database_name'; - const DATABASE_USERNAME = 'database_username'; - const DATABASE_PASSWORD = 'database_password'; - const FRONTEND_FRAMEWORK = 'frontend'; - const FULL = 'full'; - const TLD = 'tld'; - const COMMIT_MESSAGE = 'commit_message'; - const VALET_LINK = 'valet_link'; - const VALET_SECURE = 'valet_secure'; - const BROWSER = 'browser'; - const INERTIA = 'inertia'; - const LIVEWIRE = 'livewire'; - const TEAMS = 'teams'; - const COMMAND = 'command'; + public const EDITOR = 'editor'; + public const PROJECT_NAME = 'project_name'; + public const ROOT_PATH = 'root_path'; + public const WITH_OUTPUT = 'with_output'; + public const USE_DEVELOP_BRANCH = 'dev'; + public const CREATE_DATABASE = 'create_database'; + public const MIGRATE_DATABASE = 'migrate_database'; + public const DATABASE_HOST = 'database_host'; + public const DATABASE_PORT = 'database_port'; + public const DATABASE_NAME = 'database_name'; + public const DATABASE_USERNAME = 'database_username'; + public const DATABASE_PASSWORD = 'database_password'; + public const FRONTEND_FRAMEWORK = 'frontend'; + public const FULL = 'full'; + public const TLD = 'tld'; + public const COMMIT_MESSAGE = 'commit_message'; + public const VALET_LINK = 'valet_link'; + public const VALET_SECURE = 'valet_secure'; + public const BROWSER = 'browser'; + public const INERTIA = 'inertia'; + public const LIVEWIRE = 'livewire'; + public const TEAMS = 'teams'; + public const COMMAND = 'command'; public function __construct(array $keyMap) { @@ -53,11 +53,11 @@ protected function get(string $key, array $array) return null; } - if (in_array(Str::lower($array[$key]), ["1", "true", "on", "yes"])) { + if (in_array(Str::lower($array[$key]), ['1', 'true', 'on', 'yes'])) { return true; } - if (in_array(Str::lower($array[$key]), ["0", "false", "off", "no"])) { + if (in_array(Str::lower($array[$key]), ['0', 'false', 'off', 'no'])) { return false; } diff --git a/app/Configuration/SetConfig.php b/app/Configuration/SetConfig.php index 99ec9397..d97bed59 100644 --- a/app/Configuration/SetConfig.php +++ b/app/Configuration/SetConfig.php @@ -11,11 +11,7 @@ class SetConfig { - private $commandLineConfiguration; - private $savedConfiguration; - private $shellConfiguration; protected $consoleWriter; - protected $fullFlags = [ LamboConfiguration::CREATE_DATABASE, LamboConfiguration::MIGRATE_DATABASE, @@ -23,8 +19,16 @@ class SetConfig LamboConfiguration::VALET_SECURE, ]; - public function __construct(CommandLineConfiguration $commandLineConfiguration, SavedConfiguration $savedConfiguration, ShellConfiguration $shellConfiguration, ConsoleWriter $consoleWriter) - { + private $commandLineConfiguration; + private $savedConfiguration; + private $shellConfiguration; + + public function __construct( + CommandLineConfiguration $commandLineConfiguration, + SavedConfiguration $savedConfiguration, + ShellConfiguration $shellConfiguration, + ConsoleWriter $consoleWriter + ) { $this->commandLineConfiguration = $commandLineConfiguration; $this->savedConfiguration = $savedConfiguration; $this->shellConfiguration = $shellConfiguration; @@ -45,7 +49,8 @@ public function __invoke($defaultConfiguration) // If we're in the "new" command, generate a few config items which // require others to be set above first. if (config('lambo.store.command') === NewCommand::class) { - config(['lambo.store.project_path' => config('lambo.store.root_path') . '/' . config('lambo.store.project_name')]); + $projectPath = config('lambo.store.root_path') . '/' . config('lambo.store.project_name'); + config(['lambo.store.project_path' => $projectPath]); config(['lambo.store.project_url' => $this->getProjectURL()]); } @@ -86,7 +91,14 @@ private function getTld(): string return json_decode(File::get($legacyValetConfig))->domain; } - throw new LamboException("Unable to find valet domain (tld) configuration.\nNo Valet configuration located at either of the following locations: \n - {$valetConfig}\n - {$legacyValetConfig}"); + throw new LamboException( + implode(PHP_EOL, [ + 'Unable to find valet domain (tld) configuration.', + 'No Valet configuration located at either of the following locations:', + "- {$valetConfig}", + "- {$legacyValetConfig}", + ]) + ); } private function getRootPath(string $key, $default) @@ -105,10 +117,12 @@ private function getDatabaseName(string $key, $default) private function getProjectURL(): string { - return sprintf("http%s://%s.%s", + return sprintf( + 'http%s://%s.%s', config('lambo.store.valet_secure') ? 's' : '', config('lambo.store.project_name'), - config('lambo.store.tld')); + config('lambo.store.tld') + ); } private function getMigrateDatabase(string $key, $default) diff --git a/composer.json b/composer.json index 2cf8e57e..e3f465ae 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "require-dev": { "laravel-zero/framework": "^8.0", "mockery/mockery": "^1.0", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.0", + "tightenco/duster": "^0.2.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 43819b58..3ed758cb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6b5bd209ad53de03e6958030dc09c900", + "content-hash": "3881fe5f0f4fedc4fd14861106afa3c3", "packages": [ { "name": "laravel/installer", @@ -980,6 +980,76 @@ ], "time": "2020-08-18T23:57:15+00:00" }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.1", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2020-12-07T18:04:37+00:00" + }, { "name": "doctrine/inflector", "version": "2.0.3", @@ -2146,6 +2216,60 @@ }, "time": "2020-11-29T20:22:49+00:00" }, + { + "name": "illuminate/view", + "version": "v8.33.1", + "source": { + "type": "git", + "url": "https://github.com/illuminate/view.git", + "reference": "696a1d6d2213be192429e97245a3d2bb4d6d1849" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/view/zipball/696a1d6d2213be192429e97245a3d2bb4d6d1849", + "reference": "696a1d6d2213be192429e97245a3d2bb4d6d1849", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/collections": "^8.0", + "illuminate/container": "^8.0", + "illuminate/contracts": "^8.0", + "illuminate/events": "^8.0", + "illuminate/filesystem": "^8.0", + "illuminate/macroable": "^8.0", + "illuminate/support": "^8.0", + "php": "^7.3|^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\View\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate View package.", + "homepage": "https://laravel.com", + "support": { + "issues": "https://github.com/laravel/framework/issues", + "source": "https://github.com/laravel/framework" + }, + "time": "2020-11-02T14:01:41+00:00" + }, { "name": "jolicode/jolinotif", "version": "v2.2.0", @@ -5113,6 +5237,62 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.5.8", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2020-10-23T02:01:07+00:00" + }, { "name": "symfony/error-handler", "version": "v5.2.1", @@ -5552,6 +5732,168 @@ ], "time": "2020-07-12T23:59:07+00:00" }, + { + "name": "tightenco/duster", + "version": "v0.2.1", + "source": { + "type": "git", + "url": "https://github.com/tighten/duster.git", + "reference": "5edae567216bf4ebef7c42e2de39036a1bb04cee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tighten/duster/zipball/5edae567216bf4ebef7c42e2de39036a1bb04cee", + "reference": "5edae567216bf4ebef7c42e2de39036a1bb04cee", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpunit/phpunit": "^9.0", + "squizlabs/php_codesniffer": "^3.5", + "tightenco/tighten-coding-standard": "^1.0", + "tightenco/tlint": "^5.0" + }, + "bin": [ + "bin/duster" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Stauffer", + "email": "matt@tighten.co", + "homepage": "https://tighten.co", + "role": "Developer" + } + ], + "description": "Automatic configuration for Laravel apps to apply Tighten's standard linting & code standards.", + "homepage": "https://github.com/tighten/duster", + "keywords": [ + "Code style", + "duster", + "laravel", + "php", + "phpcs", + "tightenco" + ], + "support": { + "issues": "https://github.com/tighten/duster/issues", + "source": "https://github.com/tighten/duster/tree/v0.2.1" + }, + "time": "2021-02-13T21:34:10+00:00" + }, + { + "name": "tightenco/tighten-coding-standard", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/tighten/tighten-coding-standard.git", + "reference": "b2416c4d9cfcbedb1865c685a58ac637a6642a4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tighten/tighten-coding-standard/zipball/b2416c4d9cfcbedb1865c685a58ac637a6642a4e", + "reference": "b2416c4d9cfcbedb1865c685a58ac637a6642a4e", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "php": "^7.4|^8.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "require-dev": { + "phpunit/phpunit": "^9.0", + "tightenco/tlint": "^5.0" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "Tighten\\TightenCodingStandard\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Stauffer", + "email": "matt@tighten.co", + "homepage": "https://tighten.co", + "role": "Developer" + } + ], + "description": "A PHP Code_Sniffer configuration for the Tighten coding standard.", + "homepage": "https://github.com/tighten/tighten-coding-standard", + "keywords": [ + "php", + "tighten-coding-standard", + "tightenco" + ], + "support": { + "issues": "https://github.com/tighten/tighten-coding-standard/issues", + "source": "https://github.com/tighten/tighten-coding-standard/tree/v1.0.1" + }, + "time": "2021-02-21T15:18:16+00:00" + }, + { + "name": "tightenco/tlint", + "version": "v5.0.15", + "source": { + "type": "git", + "url": "https://github.com/tighten/tlint.git", + "reference": "d7452af38f9e212f93e3466d9f8ab17f32b72012" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tighten/tlint/zipball/d7452af38f9e212f93e3466d9f8ab17f32b72012", + "reference": "d7452af38f9e212f93e3466d9f8ab17f32b72012", + "shasum": "" + }, + "require": { + "illuminate/view": "*", + "nikic/php-parser": "^4.5", + "php": ">=7.3", + "symfony/console": "^4.3 || ^5.0", + "symfony/process": "^4.3 || ^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "bin": [ + "bin/tlint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Tighten\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Logan Henson", + "email": "logan@loganhenson.com", + "role": "Developer" + } + ], + "description": "Tighten linter for Laravel conventions", + "homepage": "https://github.com/tighten/tlint", + "support": { + "issues": "https://github.com/tighten/tlint/issues", + "source": "https://github.com/tighten/tlint/tree/v5.0.15" + }, + "time": "2021-02-26T22:07:45+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v5.2.0", @@ -5766,8 +6108,9 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.2.5|^8.0", - "ext-json": "*" + "php": "^7.3|^8.0", + "ext-json": "*", + "ext-pdo": "*" }, "platform-dev": [], "plugin-api-version": "2.0.0" diff --git a/tests/Feature/ConfigureFrontendFrameworkTest.php b/tests/Feature/ConfigureFrontendFrameworkTest.php index 4efb9662..dfcdf879 100644 --- a/tests/Feature/ConfigureFrontendFrameworkTest.php +++ b/tests/Feature/ConfigureFrontendFrameworkTest.php @@ -121,7 +121,7 @@ function it_throws_a_lambo_exception_if_ui_framework_installation_fails() $this->skipWithMessage([ 'Currently failing due to WIP refactor.', 'the App\Shell mock needs to return both a successful and a failed', - 'process execution.' + 'process execution.', ]); $this->shouldFailFrontendFrameworkInstallation('inertia'); diff --git a/tests/Feature/Fakes/FakeProcess.php b/tests/Feature/Fakes/FakeProcess.php index df394df0..c1d4989b 100644 --- a/tests/Feature/Fakes/FakeProcess.php +++ b/tests/Feature/Fakes/FakeProcess.php @@ -6,6 +6,7 @@ class FakeProcess { public $isSuccessful; public $failedCommand; + private $output; private $errorOutput; diff --git a/tests/Feature/SavedConfigTest.php b/tests/Feature/SavedConfigTest.php index 4cb85625..9d337fe9 100644 --- a/tests/Feature/SavedConfigTest.php +++ b/tests/Feature/SavedConfigTest.php @@ -4,7 +4,6 @@ use App\Actions\SavedConfig; use App\LamboException; -use App\Shell; use Illuminate\Support\Facades\File; use Tests\Feature\Fakes\FakeProcess; use Tests\TestCase; diff --git a/tests/Feature/UpgradeSavedConfigurationTest.php b/tests/Feature/UpgradeSavedConfigurationTest.php index f19c8ad2..5e25e6d5 100644 --- a/tests/Feature/UpgradeSavedConfigurationTest.php +++ b/tests/Feature/UpgradeSavedConfigurationTest.php @@ -25,7 +25,7 @@ class UpgradeSavedConfigurationTest extends TestCase 'description' => [ 'The THING parameter enables Lambo to do a thing.', 'Valid options are foo, bar and flibble (default if not specified).', - ] + ], ], 'ANOTHER_THING' => [ 'commented' => false, @@ -33,7 +33,7 @@ class UpgradeSavedConfigurationTest extends TestCase 'description' => [ 'The ANOTHER_THING parameter enables Lambo to do a another thing.', 'Valid options are true or false (default if not specified).', - ] + ], ], ]; diff --git a/tests/Unit/SetConfigTest.php b/tests/Unit/SetConfigTest.php index 8cc90a9b..d207e2a6 100644 --- a/tests/Unit/SetConfigTest.php +++ b/tests/Unit/SetConfigTest.php @@ -261,7 +261,7 @@ function it_replaces_hyphens_with_underscores_in_database_names() ))([ 'root_path' => getcwd(), 'project_name' => null, - 'database_name' => null + 'database_name' => null, ]); $this->assertEquals('h_y_p_h_e_n_s', config('lambo.store.database_name')); diff --git a/tlint.json b/tlint.json new file mode 100644 index 00000000..4bc66129 --- /dev/null +++ b/tlint.json @@ -0,0 +1,7 @@ +{ + "preset": "tighten", + "disabled": [], + "excluded": [ + "node_modules" + ] +} From 1e713e62ce52cd1741f0bfab61ffd2c2cea25d64 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 19 Mar 2021 18:52:19 +0000 Subject: [PATCH 05/14] add Spatie/Ray --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e3f465ae..e3ca30ac 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,15 @@ ], "require": { "php": "^7.3|^8.0", - "laravel/installer": "^4.0", "ext-json": "*", - "ext-pdo": "*" + "ext-pdo": "*", + "laravel/installer": "^4.0" }, "require-dev": { "laravel-zero/framework": "^8.0", "mockery/mockery": "^1.0", "phpunit/phpunit": "^9.0", + "spatie/laravel-ray": "^1.17", "tightenco/duster": "^0.2.1" }, "autoload": { From 106175409880654f6e436343fc4f95887c27dd3a Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 19 Mar 2021 18:55:01 +0000 Subject: [PATCH 06/14] Fix Duster lints --- app/Actions/ConfigureFrontendFramework.php | 4 +-- app/Actions/DisplayHelpScreen.php | 10 +++---- app/Actions/OpenInBrowser.php | 2 +- app/Actions/OpenInEditor.php | 4 +-- app/Actions/RunAfterScript.php | 2 +- app/Actions/RunLaravelInstaller.php | 11 +++---- app/Actions/SavedConfig.php | 2 +- app/Actions/SilentDevScript.php | 2 +- app/Actions/ValetSecure.php | 2 +- app/Actions/VerifyDependencies.php | 5 ++-- app/Commands/NewCommand.php | 9 +++--- app/Configuration/SavedConfiguration.php | 1 - app/Options.php | 34 +++++++++++----------- 13 files changed, 44 insertions(+), 44 deletions(-) diff --git a/app/Actions/ConfigureFrontendFramework.php b/app/Actions/ConfigureFrontendFramework.php index a4a164ee..f1007136 100644 --- a/app/Actions/ConfigureFrontendFramework.php +++ b/app/Actions/ConfigureFrontendFramework.php @@ -33,7 +33,7 @@ public function __invoke() $this->ensureJetstreamInstalled(); $process = $this->shell->execInProject(sprintf( - "php artisan jetstream:install %s%s%s", + 'php artisan jetstream:install %s%s%s', $configuredFrontend, config('lambo.store.teams') ? ' --teams' : '', config('lambo.store.with_output') ? '' : ' --quiet' @@ -60,7 +60,7 @@ public function ensureJetstreamInstalled() $process = $this->shell->execInProject('composer require laravel/jetstream' . (config('lambo.store.with_output') ? '' : ' --quiet')); - $this->abortIf(! $process->isSuccessful(), "Installation of laravel/jetstream did not complete successfully.", $process); + $this->abortIf(! $process->isSuccessful(), 'Installation of laravel/jetstream did not complete successfully.', $process); $this->consoleWriter->success('laravel/jetstream installed.'); } diff --git a/app/Actions/DisplayHelpScreen.php b/app/Actions/DisplayHelpScreen.php index 25ab469d..9be15737 100644 --- a/app/Actions/DisplayHelpScreen.php +++ b/app/Actions/DisplayHelpScreen.php @@ -17,9 +17,9 @@ class DisplayHelpScreen public function __invoke() { app('console-writer')->newLine(); - app('console-writer')->text("Usage:"); + app('console-writer')->text('Usage:'); app('console-writer')->text(" lambo new myApplication [arguments]\n"); - app('console-writer')->text("Commands (lambo COMMANDNAME):"); + app('console-writer')->text('Commands (lambo COMMANDNAME):'); foreach ($this->commands as $command => $description) { $spaces = $this->makeSpaces(strlen($command)); @@ -27,9 +27,9 @@ public function __invoke() } app('console-writer')->newLine(); - app('console-writer')->text("Options (lambo new myApplication OPTIONS):"); + app('console-writer')->text('Options (lambo new myApplication OPTIONS):'); - foreach ((new Options)->all() as $option) { + foreach ((new Options())->all() as $option) { app('console-writer')->text($this->createCliStringForOption($option)); } } @@ -54,6 +54,6 @@ public function createCliStringForOption($option) public function makeSpaces($count) { - return str_repeat(" ", $this->indent - $count); + return str_repeat(' ', $this->indent - $count); } } diff --git a/app/Actions/OpenInBrowser.php b/app/Actions/OpenInBrowser.php index 56ac5e0a..47f41205 100644 --- a/app/Actions/OpenInBrowser.php +++ b/app/Actions/OpenInBrowser.php @@ -35,7 +35,7 @@ public function __invoke() return; } - $this->shell->execInProject("valet open"); + $this->shell->execInProject('valet open'); } public function browser() diff --git a/app/Actions/OpenInEditor.php b/app/Actions/OpenInEditor.php index f93a3c78..e335a74b 100644 --- a/app/Actions/OpenInEditor.php +++ b/app/Actions/OpenInEditor.php @@ -26,8 +26,8 @@ public function __invoke() $this->consoleWriter->logStep('Opening In Editor'); - $process = $this->shell->withTTY()->execInProject(sprintf("%s .", config('lambo.store.editor'))); - $this->abortIf(! $process->isSuccessful(), sprintf("Failed to open editor %s", config('lambo.store.editor')), $process); + $process = $this->shell->withTTY()->execInProject(sprintf('%s .', config('lambo.store.editor'))); + $this->abortIf(! $process->isSuccessful(), sprintf('Failed to open editor %s', config('lambo.store.editor')), $process); $this->consoleWriter->success('Opening your project in ' . config('lambo.store.editor')); } diff --git a/app/Actions/RunAfterScript.php b/app/Actions/RunAfterScript.php index 196c83a6..412a6e71 100644 --- a/app/Actions/RunAfterScript.php +++ b/app/Actions/RunAfterScript.php @@ -28,7 +28,7 @@ public function __invoke() $this->consoleWriter->logStep('Running after script'); - $process = $this->shell->execInProject("sh " . $afterScriptPath); + $process = $this->shell->execInProject('sh ' . $afterScriptPath); $this->abortIf(! $process->isSuccessful(), 'After file did not complete successfully', $process); $this->consoleWriter->success('After script has completed.'); diff --git a/app/Actions/RunLaravelInstaller.php b/app/Actions/RunLaravelInstaller.php index 881fda3e..0affa77d 100644 --- a/app/Actions/RunLaravelInstaller.php +++ b/app/Actions/RunLaravelInstaller.php @@ -20,17 +20,18 @@ public function __construct(Shell $shell, ConsoleWriter $consoleWriter) public function __invoke() { - $this->consoleWriter->logStep("Running the Laravel installer"); + $this->consoleWriter->logStep('Running the Laravel installer'); $process = $this->shell->execInRoot('laravel new ' . config('lambo.store.project_name') . $this->extraOptions()); - $this->abortIf(! $process->isSuccessful(), "The laravel installer did not complete successfully.", $process); + $this->abortIf(! $process->isSuccessful(), 'The laravel installer did not complete successfully.', $process); $this->consoleWriter->success($this->getFeedback()); } public function extraOptions() { - return sprintf('%s%s', + return sprintf( + '%s%s', config('lambo.store.dev') ? ' --dev' : '', config('lambo.store.with_output') ? '' : ' --quiet' ); @@ -38,10 +39,10 @@ public function extraOptions() public function getFeedback(): string { - return sprintf("A new application '%s' has been created from the %s branch.", + return sprintf( + "A new application '%s' has been created from the %s branch.", config('lambo.store.project_name'), config('lambo.store.dev') ? 'develop' : 'release' ); } - } diff --git a/app/Actions/SavedConfig.php b/app/Actions/SavedConfig.php index 7f57cbd6..edba68d0 100644 --- a/app/Actions/SavedConfig.php +++ b/app/Actions/SavedConfig.php @@ -19,7 +19,7 @@ public function __construct(Shell $shell) public function createOrEditConfigFile(string $fileName) { $configDir = config('home_dir') . '/.lambo'; - $configFilePath = $configDir . "/" . $fileName; + $configFilePath = $configDir . '/' . $fileName; if (! File::isDirectory($configDir)) { app('console-writer')->note("Configuration directory '{$configDir}' does not exist, creating it now..."); diff --git a/app/Actions/SilentDevScript.php b/app/Actions/SilentDevScript.php index f10efe1c..c231f38f 100644 --- a/app/Actions/SilentDevScript.php +++ b/app/Actions/SilentDevScript.php @@ -33,6 +33,6 @@ private function getSilentPackageJson(string $originalPackageJson) $silentDevelopmentCommand = str_replace('--progress', '--no-progress', Arr::get($packageJson, 'scripts.development')); Arr::set($packageJson, 'scripts.development', $silentDevelopmentCommand); - return json_encode($packageJson, JSON_UNESCAPED_SLASHES); + return json_encode($packageJson, JSON_UNESCAPED_SLASHES); } } diff --git a/app/Actions/ValetSecure.php b/app/Actions/ValetSecure.php index 41083a10..f83d2c34 100644 --- a/app/Actions/ValetSecure.php +++ b/app/Actions/ValetSecure.php @@ -26,7 +26,7 @@ public function __invoke() $this->consoleWriter->logStep('Running valet secure'); - $process = $this->shell->execInProject("valet secure"); + $process = $this->shell->execInProject('valet secure'); $this->abortIf(! $process->isSuccessful(), 'valet secure did not complete successfully', $process); $this->consoleWriter->success('valet secure successful'); diff --git a/app/Actions/VerifyDependencies.php b/app/Actions/VerifyDependencies.php index 83b7b5d6..eb92113a 100644 --- a/app/Actions/VerifyDependencies.php +++ b/app/Actions/VerifyDependencies.php @@ -38,7 +38,7 @@ public function __construct(ExecutableFinder $finder, ConsoleWriter $consoleWrit public function __invoke() { - $this->consoleWriter->logStep("Verifying dependencies"); + $this->consoleWriter->logStep('Verifying dependencies'); $this->abortIf( collect($this->dependencies)->reduce(function ($carry, $dependency) { @@ -50,6 +50,7 @@ public function __invoke() $this->consoleWriter->success("{$label} found at:\n {$installedDependency}"); return $carry ?? false; }), - 'Please install missing dependencies and try again.'); + 'Please install missing dependencies and try again.' + ); } } diff --git a/app/Commands/NewCommand.php b/app/Commands/NewCommand.php index 954e8129..36bcb483 100644 --- a/app/Commands/NewCommand.php +++ b/app/Commands/NewCommand.php @@ -51,9 +51,8 @@ public function __construct() public function buildSignature() { - return collect((new Options)->all())->reduce( - function ($carry, $option) - { + return collect((new Options())->all())->reduce( + function ($carry, $option) { return $carry . $this->buildSignatureOption($option); }, "new\n{projectName? : Name of the Laravel project}" @@ -87,8 +86,8 @@ public function handle() $this->consoleWriter->newLine(); $this->consoleWriter->note('Your Lambo configuration (~/.lambo/config) has been updated.'); $this->consoleWriter->note('Please review the changes then run lambo again.'); - if ($this->confirm(sprintf("Review the changes now in %s?", config('lambo.store.editor')))) { - app(SavedConfig::class)->createOrEditConfigFile("config"); + if ($this->confirm(sprintf('Review the changes now in %s?', config('lambo.store.editor')))) { + app(SavedConfig::class)->createOrEditConfigFile('config'); } return; } diff --git a/app/Configuration/SavedConfiguration.php b/app/Configuration/SavedConfiguration.php index da29bc4b..4e4404b0 100644 --- a/app/Configuration/SavedConfiguration.php +++ b/app/Configuration/SavedConfiguration.php @@ -3,7 +3,6 @@ namespace App\Configuration; use Dotenv\Dotenv; - use Illuminate\Support\Facades\File; class SavedConfiguration extends LamboConfiguration diff --git a/app/Options.php b/app/Options.php index 52a3b100..b674e0c5 100644 --- a/app/Options.php +++ b/app/Options.php @@ -16,83 +16,83 @@ class Options 'short' => 'm', 'long' => 'message', 'param_description' => '"message"', - 'cli_description' => "Customize the initial commit message (wrap with quotes!)", + 'cli_description' => 'Customize the initial commit message (wrap with quotes!)', ], [ 'short' => 'p', 'long' => 'path', 'param_description' => 'PATH', - 'cli_description' => "Customize the path in which the new project will be created", + 'cli_description' => 'Customize the path in which the new project will be created', ], [ 'short' => 'b', 'long' => 'browser', 'param_description' => '"BROWSER"', - 'cli_description' => "Open the site in the specified BROWSER. E.g. firefox", + 'cli_description' => 'Open the site in the specified BROWSER. E.g. firefox', ], [ 'long' => 'dbhost', 'param_description' => 'HOST', - 'cli_description' => "Specify the database host", + 'cli_description' => 'Specify the database host', ], [ 'long' => 'dbport', 'param_description' => 'PORT', - 'cli_description' => "Specify the database port", + 'cli_description' => 'Specify the database port', ], [ 'long' => 'dbname', 'param_description' => 'DBNAME', - 'cli_description' => "Specify the database name", + 'cli_description' => 'Specify the database name', ], [ 'long' => 'dbuser', 'param_description' => 'USERNAME', - 'cli_description' => "Specify the database user", + 'cli_description' => 'Specify the database user', ], [ 'long' => 'dbpassword', 'param_description' => 'PASSWORD', - 'cli_description' => "Specify the database password", + 'cli_description' => 'Specify the database password', ], [ 'long' => 'create-db', - 'cli_description' => "Create a new MySQL database", + 'cli_description' => 'Create a new MySQL database', ], [ 'long' => 'migrate-db', - 'cli_description' => "Run database migrations", + 'cli_description' => 'Run database migrations', ], [ 'long' => 'inertia', - 'cli_description' => "Use inertia frontend scaffolding", + 'cli_description' => 'Use inertia frontend scaffolding', ], [ 'long' => 'livewire', - 'cli_description' => "Use livewire frontend scaffolding", + 'cli_description' => 'Use livewire frontend scaffolding', ], [ 'long' => 'teams', - 'cli_description' => "Use team features with inertia or livewire", + 'cli_description' => 'Use team features with inertia or livewire', ], [ 'short' => 'l', 'long' => 'link', - 'cli_description' => "Create a Valet link to the project directory", + 'cli_description' => 'Create a Valet link to the project directory', ], [ 'short' => 's', 'long' => 'secure', - 'cli_description' => "Generate and use an HTTPS cert with Valet", + 'cli_description' => 'Generate and use an HTTPS cert with Valet', ], [ 'short' => 'd', 'long' => 'dev', - 'cli_description' => "Install Laravel using the develop branch", + 'cli_description' => 'Install Laravel using the develop branch', ], [ 'long' => 'full', - 'cli_description' => "Shortcut of --create-db --migrate-db --link --secure", + 'cli_description' => 'Shortcut of --create-db --migrate-db --link --secure', ], ]; From ff1598cd857ffe1894f094c745bdfbc60bb794e6 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 24 Mar 2021 17:13:28 +0000 Subject: [PATCH 07/14] feat: determine the timezone that Lambo should use during execution. Fixes: #146 --- app/Commands/Debug.php | 35 ++++++++++++++++++++++++++++++++++- app/Helpers/GetTimezone.php | 16 ++++++++++++++++ composer.json | 3 ++- config/app.php | 15 +++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 app/Helpers/GetTimezone.php diff --git a/app/Commands/Debug.php b/app/Commands/Debug.php index cf061e91..b88f2872 100644 --- a/app/Commands/Debug.php +++ b/app/Commands/Debug.php @@ -2,9 +2,11 @@ namespace App\Commands; +use Carbon\Carbon; use Dotenv\Dotenv; use Illuminate\Support\Arr; use Illuminate\Support\Facades\File; +use IntlTimeZone; trait Debug { @@ -121,7 +123,9 @@ protected function debugReport(): void ); $this->consoleWriter->text('Shell environment variables:'); - $this->arrayToTable($_SERVER, ['EDITOR',], '$'); + $this->arrayToTable($_SERVER, ['EDITOR'], '$'); + + $this->logTimezoneData(); $this->consoleWriter->panel('Debug', 'End', 'fg=black;bg=white'); } @@ -131,4 +135,33 @@ protected function configToTable(): void $config = Arr::prepend(config('lambo.store'), config('home_dir'), 'home_dir'); $this->arrayToTable($config, null, 'lambo.store.', ['Configuration key', 'Value', 'Type']); } + + protected function logTimezoneData(string $offset = null) + { + $this->consoleWriter->sectionTitle('Timezone configuration'); + $this->consoleWriter->newLine(); + $this->consoleWriter->text('System settings'); + $this->arrayToTable([ + 'OS Config ("/etc/localtime")' => exec('/bin/ls -l /etc/localtime|/usr/bin/cut -d"/" -f8-'), + "ini_get('date.timezone')" => ini_get('date.timezone') ?: 'Not configured', + 'IntlTimeZone::createDefault()' => IntlTimeZone::createDefault()->getID(), + 'date_default_timezone_get()' => date_default_timezone_get(), + 'config->get("app.timezone")' => config()->get('app.timezone'), + ]); + + $this->consoleWriter->text('Carbon'); + $this->arrayToTable([ + // UTC, GMT, Atlantic/Azores + 'Carbon (Timezone identifier)' => Carbon::now()->format('e'), + + // 1 if Daylight Saving Time, 0 otherwise. + 'Carbon (Daylight savings)' => (bool)Carbon::now()->format('I'), + + // Difference to Greenwich time (GMT) + 'Carbon (Difference to GMT w/O)' => Carbon::now()->format('O'), // +0200'Carbon (Difference to GMT w/P)' => Carbon::now()->format('P'), // +02:00 + + // Examples: EST, MDT + 'Carbon (tz abbreviation)' => Carbon::now()->format('T'), + ]); + } } diff --git a/app/Helpers/GetTimezone.php b/app/Helpers/GetTimezone.php new file mode 100644 index 00000000..2971766d --- /dev/null +++ b/app/Helpers/GetTimezone.php @@ -0,0 +1,16 @@ +getID(); + } +} diff --git a/composer.json b/composer.json index 10dfa48d..de67c339 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "php": "^7.3|^8.0", "laravel/installer": "^4.0", "ext-json": "*", - "ext-pdo": "*" + "ext-pdo": "*", + "ext-intl": "*" }, "require-dev": { "laravel-zero/framework": "^8.0", diff --git a/config/app.php b/config/app.php index 11c44428..62bbafcb 100644 --- a/config/app.php +++ b/config/app.php @@ -1,5 +1,7 @@ 'development', + /* + |-------------------------------------------------------------------------- + | Timezone + |-------------------------------------------------------------------------- + | + | This value determines the timezone that Lambo is currently running in. + | It will be the value of "date.timezone" in php.ini or the value set + | by your operating system. If php cannot determine the value set + | by your operating system, then UTC will be used. You may set + | this value manually to use a timezone of your choosing. + */ + 'timezone' => app(GetTimezone::class)(), + /* |-------------------------------------------------------------------------- | Autoloaded Service Providers From 5c6ae77a9e2e8745521fbfaa5a7c6843e7e9af1d Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 25 Mar 2021 14:40:53 -0400 Subject: [PATCH 08/14] test: ensure the appropriate timezone is selected by App\Helpers\GetTimezone --- .../Feature/UpgradeSavedConfigurationTest.php | 5 ++- tests/Unit/GetTimezoneTest.php | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/Unit/GetTimezoneTest.php diff --git a/tests/Feature/UpgradeSavedConfigurationTest.php b/tests/Feature/UpgradeSavedConfigurationTest.php index 5e25e6d5..3df5afc2 100644 --- a/tests/Feature/UpgradeSavedConfigurationTest.php +++ b/tests/Feature/UpgradeSavedConfigurationTest.php @@ -40,8 +40,7 @@ class UpgradeSavedConfigurationTest extends TestCase /** @test */ function it_upgrades_saved_configuration() { - $dateTime = Carbon::parse('1-Apr-2020 5:00 am'); - $this->travelTo($dateTime); + $this->travelTo(Carbon::parse('17-Jul-2016 20:51:08', 'America/New_York')); $upgradedConfiguration = app(UpgradeSavedConfiguration::class)->upgrade($this->getConfiguration(), $this->removedConfigurationKeys, $this->newConfiguration); @@ -53,7 +52,7 @@ function it_upgrades_saved_configuration() # ------------------------------------------------------------------------------ -# 1-Apr-2020 5:00 am (auto-generated by Lambo): +# 17-Jul-2016 8:51 pm (auto-generated by Lambo): # ------------------------------------------------------------------------------ # Lambo has commented out the following configuration items as they # are no-longer used. You may safely remove them: diff --git a/tests/Unit/GetTimezoneTest.php b/tests/Unit/GetTimezoneTest.php new file mode 100644 index 00000000..e90e3591 --- /dev/null +++ b/tests/Unit/GetTimezoneTest.php @@ -0,0 +1,31 @@ +getId()] + ); + $expectedTimezone = array_pop($availableTimezones); + + ini_set('date.timezone', $expectedTimezone); + $this->assertEquals($expectedTimezone, app(GetTimezone::class)()); + } + + /** @test */ + function it_uses_the_timezone_of_the_host_operating_system() + { + ini_set('date.timezone', ''); + $expectedTimezone = IntlTimeZone::createDefault()->getId(); + $this->assertEquals($expectedTimezone, app(GetTimezone::class)()); + } +} From baebd7e8bb96d62b6f0f18db8dec2e106e6f80c0 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 26 Mar 2021 14:38:48 +0000 Subject: [PATCH 09/14] style(phpcs): fix lints --- tests/Feature/ConfigureFrontendFrameworkTest.php | 6 ++++-- tests/Feature/CustomizeDotEnvTest.php | 4 ++-- tests/Feature/InstallNpmDependenciesTest.php | 4 ++-- tests/Feature/OpenInEditorTest.php | 6 +++--- tests/Feature/SignatureBuilderTest.php | 10 +++++----- tests/Feature/UpgradeSavedConfigurationTest.php | 3 +-- tests/Feature/VerifyPathAvailableTest.php | 6 +++--- tests/Unit/SavedConfigurationTest.php | 2 +- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/Feature/ConfigureFrontendFrameworkTest.php b/tests/Feature/ConfigureFrontendFrameworkTest.php index dfcdf879..a9df443d 100644 --- a/tests/Feature/ConfigureFrontendFrameworkTest.php +++ b/tests/Feature/ConfigureFrontendFrameworkTest.php @@ -168,10 +168,12 @@ private function shouldInstallFramework(string $frontendFramework, bool $withTea config(['lambo.store.frontend' => $frontendFramework]); config(['lambo.store.teams' => $withTeams]); - $command = sprintf("php artisan jetstream:install %s%s%s", + $command = sprintf( + 'php artisan jetstream:install %s%s%s', $frontendFramework, $withTeams ? ' --teams' : '', - $withOutput ? '' : ' --quiet'); + $withOutput ? '' : ' --quiet' + ); $expectation = $this->shell->shouldReceive('execInProject') ->with($command) diff --git a/tests/Feature/CustomizeDotEnvTest.php b/tests/Feature/CustomizeDotEnvTest.php index 52f22807..62dc5850 100644 --- a/tests/Feature/CustomizeDotEnvTest.php +++ b/tests/Feature/CustomizeDotEnvTest.php @@ -40,9 +40,9 @@ function it_replaces_static_strings() config()->set('lambo.store.database_username', 'root'); $customizeDotEnv = app(CustomizeDotEnv::class); - $contents = "DB_USERNAME=previous"; + $contents = 'DB_USERNAME=previous'; $contents = $customizeDotEnv->customize($contents); - $this->assertEquals("DB_USERNAME=root", $contents); + $this->assertEquals('DB_USERNAME=root', $contents); } /** @test */ diff --git a/tests/Feature/InstallNpmDependenciesTest.php b/tests/Feature/InstallNpmDependenciesTest.php index 3e31aca6..ec1f5583 100644 --- a/tests/Feature/InstallNpmDependenciesTest.php +++ b/tests/Feature/InstallNpmDependenciesTest.php @@ -15,7 +15,7 @@ function it_installs_npm_dependencies() config(['lambo.store.with_output' => false]); $this->shell->shouldReceive('execInProject') - ->with("npm install --silent") + ->with('npm install --silent') ->once() ->andReturn(FakeProcess::success()); @@ -28,7 +28,7 @@ function it_installs_npm_dependencies_and_shows_console_output() config(['lambo.store.with_output' => true]); $this->shell->shouldReceive('execInProject') - ->with("npm install") + ->with('npm install') ->once() ->andReturn(FakeProcess::success()); diff --git a/tests/Feature/OpenInEditorTest.php b/tests/Feature/OpenInEditorTest.php index 0d69a988..f2429a5c 100644 --- a/tests/Feature/OpenInEditorTest.php +++ b/tests/Feature/OpenInEditorTest.php @@ -19,7 +19,7 @@ function it_opens_the_project_folder_in_the_specified_editor() ->andReturnSelf(); $this->shell->shouldReceive('execInProject') - ->with("my-editor .") + ->with('my-editor .') ->once() ->andReturn(FakeProcess::success()); @@ -36,9 +36,9 @@ function it_throws_an_exception_if_it_fails_to_open_the_editor() ->andReturnSelf(); $this->shell->shouldReceive('execInProject') - ->with("my-editor .") + ->with('my-editor .') ->once() - ->andReturn(FakeProcess::fail("my-editor .")); + ->andReturn(FakeProcess::fail('my-editor .')); $this->expectException(LamboException::class); diff --git a/tests/Feature/SignatureBuilderTest.php b/tests/Feature/SignatureBuilderTest.php index 5317f489..3a1a36da 100644 --- a/tests/Feature/SignatureBuilderTest.php +++ b/tests/Feature/SignatureBuilderTest.php @@ -10,7 +10,7 @@ class SignatureBuilderTest extends TestCase /** @test */ function it_offers_short_and_long_codes() { - $newCommand = new NewCommand; + $newCommand = new NewCommand(); $output = $newCommand->buildSignatureOption([ 'short' => 'e', 'long' => 'editor', @@ -23,7 +23,7 @@ function it_offers_short_and_long_codes() /** @test */ function it_functions_given_only_long_code() { - $newCommand = new NewCommand; + $newCommand = new NewCommand(); $output = $newCommand->buildSignatureOption([ 'long' => 'editor', 'cli_description' => '', @@ -35,7 +35,7 @@ function it_functions_given_only_long_code() /** @test */ function it_sets_expectation_for_values_if_option_expects_parameters() { - $newCommand = new NewCommand; + $newCommand = new NewCommand(); $output = $newCommand->buildSignatureOption([ 'long' => 'editor', 'param_description' => 'a', @@ -48,7 +48,7 @@ function it_sets_expectation_for_values_if_option_expects_parameters() /** @test */ function it_does_not_set_expectation_for_values_if_option_does_not_expect_parameters() { - $newCommand = new NewCommand; + $newCommand = new NewCommand(); $output = $newCommand->buildSignatureOption([ 'long' => 'editor', 'cli_description' => '', @@ -60,7 +60,7 @@ function it_does_not_set_expectation_for_values_if_option_does_not_expect_parame /** @test */ function it_defines_description() { - $newCommand = new NewCommand; + $newCommand = new NewCommand(); $output = $newCommand->buildSignatureOption([ 'long' => 'editor', 'cli_description' => 'The Option Description', diff --git a/tests/Feature/UpgradeSavedConfigurationTest.php b/tests/Feature/UpgradeSavedConfigurationTest.php index 3df5afc2..14b2a49a 100644 --- a/tests/Feature/UpgradeSavedConfigurationTest.php +++ b/tests/Feature/UpgradeSavedConfigurationTest.php @@ -45,7 +45,7 @@ function it_upgrades_saved_configuration() $upgradedConfiguration = app(UpgradeSavedConfiguration::class)->upgrade($this->getConfiguration(), $this->removedConfigurationKeys, $this->newConfiguration); $commented = -'VALID_KEY=foo + 'VALID_KEY=foo ANOTHER_VALID_KEY=foo #OLD_KEY=foo #ANOTHER_OLD_KEY=foo @@ -84,5 +84,4 @@ private function getConfiguration(): string return "{$carry}{$configurationKey}=foo\n"; }, ''); } - } diff --git a/tests/Feature/VerifyPathAvailableTest.php b/tests/Feature/VerifyPathAvailableTest.php index 9385254e..cbfc7023 100644 --- a/tests/Feature/VerifyPathAvailableTest.php +++ b/tests/Feature/VerifyPathAvailableTest.php @@ -62,7 +62,7 @@ function it_throws_a_lambo_exception_if_the_project_path_already_exists() ->once() ->andReturn(true) ->globally() - ->ordered();; + ->ordered(); $this->expectException(LamboException::class); @@ -84,7 +84,7 @@ function it_throws_an_exception_if_project_path_is_empty() $this->expectException(Exception::class); - app( VerifyPathAvailable::class)(); + app(VerifyPathAvailable::class)(); } /** @test */ @@ -102,6 +102,6 @@ function it_throws_an_exception_if_project_path_is_null() $this->expectException(Exception::class); - app( VerifyPathAvailable::class)(); + app(VerifyPathAvailable::class)(); } } diff --git a/tests/Unit/SavedConfigurationTest.php b/tests/Unit/SavedConfigurationTest.php index 4b56eab7..5cb1598f 100644 --- a/tests/Unit/SavedConfigurationTest.php +++ b/tests/Unit/SavedConfigurationTest.php @@ -64,7 +64,7 @@ function it_returns_null_when_the_configuration_file_does_not_exist() 'CONFIGURATION_VALUE' => 'genericOption', ]); - $this->assertNull((new SavedConfiguration)->genericOption); + $this->assertNull((new SavedConfiguration())->genericOption); } /** @test */ From 2870f973b2cedb26f429266a8b39fc7b625a5d01 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 26 Mar 2021 14:43:12 +0000 Subject: [PATCH 10/14] refactor: improve naming and readability fixes: #140 --- .../{SavedConfig.php => EditConfigFile.php} | 4 ++-- app/Commands/EditAfter.php | 4 ++-- app/Commands/EditConfig.php | 4 ++-- app/Commands/NewCommand.php | 4 ++-- ...edConfigTest.php => EditConfigFileTest.php} | 18 +++++++++--------- 5 files changed, 17 insertions(+), 17 deletions(-) rename app/Actions/{SavedConfig.php => EditConfigFile.php} (93%) rename tests/Feature/{SavedConfigTest.php => EditConfigFileTest.php} (91%) diff --git a/app/Actions/SavedConfig.php b/app/Actions/EditConfigFile.php similarity index 93% rename from app/Actions/SavedConfig.php rename to app/Actions/EditConfigFile.php index edba68d0..697b5a06 100644 --- a/app/Actions/SavedConfig.php +++ b/app/Actions/EditConfigFile.php @@ -5,7 +5,7 @@ use App\Shell; use Illuminate\Support\Facades\File; -class SavedConfig +class EditConfigFile { use AbortsCommands; @@ -16,7 +16,7 @@ public function __construct(Shell $shell) $this->shell = $shell; } - public function createOrEditConfigFile(string $fileName) + public function __invoke(string $fileName) { $configDir = config('home_dir') . '/.lambo'; $configFilePath = $configDir . '/' . $fileName; diff --git a/app/Commands/EditAfter.php b/app/Commands/EditAfter.php index 40d68edc..32b44754 100644 --- a/app/Commands/EditAfter.php +++ b/app/Commands/EditAfter.php @@ -2,7 +2,7 @@ namespace App\Commands; -use App\Actions\SavedConfig; +use App\Actions\EditConfigFile; use App\Configuration\CommandLineConfiguration; use App\Configuration\LamboConfiguration; use App\Configuration\SavedConfiguration; @@ -44,7 +44,7 @@ public function handle() ]); try { - app(SavedConfig::class)->createOrEditConfigFile('after'); + app(EditConfigFile::class)('after'); } catch (LamboException $e) { app('console-writer')->exception($e->getMessage()); } diff --git a/app/Commands/EditConfig.php b/app/Commands/EditConfig.php index 3f5f5c5d..ed6aab19 100644 --- a/app/Commands/EditConfig.php +++ b/app/Commands/EditConfig.php @@ -2,7 +2,7 @@ namespace App\Commands; -use App\Actions\SavedConfig; +use App\Actions\EditConfigFile; use App\Configuration\CommandLineConfiguration; use App\Configuration\LamboConfiguration; use App\Configuration\SavedConfiguration; @@ -44,7 +44,7 @@ public function handle() ]); try { - app(SavedConfig::class)->createOrEditConfigFile('config'); + app(EditConfigFile::class)('config'); } catch (LamboException $e) { app('console-writer')->exception($e->getMessage()); } diff --git a/app/Commands/NewCommand.php b/app/Commands/NewCommand.php index 36bcb483..abf5e1c1 100644 --- a/app/Commands/NewCommand.php +++ b/app/Commands/NewCommand.php @@ -7,6 +7,7 @@ use App\Actions\CustomizeDotEnv; use App\Actions\DisplayHelpScreen; use App\Actions\DisplayLamboWelcome; +use App\Actions\EditConfigFile; use App\Actions\GenerateAppKey; use App\Actions\InitializeGitRepo; use App\Actions\MigrateDatabase; @@ -14,7 +15,6 @@ use App\Actions\OpenInEditor; use App\Actions\RunAfterScript; use App\Actions\RunLaravelInstaller; -use App\Actions\SavedConfig; use App\Actions\UpgradeSavedConfiguration; use App\Actions\ValetLink; use App\Actions\ValetSecure; @@ -87,7 +87,7 @@ public function handle() $this->consoleWriter->note('Your Lambo configuration (~/.lambo/config) has been updated.'); $this->consoleWriter->note('Please review the changes then run lambo again.'); if ($this->confirm(sprintf('Review the changes now in %s?', config('lambo.store.editor')))) { - app(SavedConfig::class)->createOrEditConfigFile('config'); + app(EditConfigFile::class)('config'); } return; } diff --git a/tests/Feature/SavedConfigTest.php b/tests/Feature/EditConfigFileTest.php similarity index 91% rename from tests/Feature/SavedConfigTest.php rename to tests/Feature/EditConfigFileTest.php index 9d337fe9..049c43c2 100644 --- a/tests/Feature/SavedConfigTest.php +++ b/tests/Feature/EditConfigFileTest.php @@ -2,13 +2,13 @@ namespace Tests\Feature; -use App\Actions\SavedConfig; +use App\Actions\EditConfigFile; use App\LamboException; use Illuminate\Support\Facades\File; use Tests\Feature\Fakes\FakeProcess; use Tests\TestCase; -class SavedConfigTest extends TestCase +class EditConfigFileTest extends TestCase { private $fileName; private $configDirectory; @@ -42,7 +42,7 @@ function it_creates_the_config_directory_and_file_then_opens_the_file_for_editin $then->the_config_file_is_opened_for_editing(); - app(SavedConfig::class)->createOrEditConfigFile($this->fileName); + app(EditConfigFile::class)($this->fileName); } /** @test */ @@ -53,7 +53,7 @@ function it_creates_a_config_file_then_opens_the_file_for_editing() $this->successfullyCreateConfigFile(); $this->successfullyOpenInEditor(); - app(SavedConfig::class)->createOrEditConfigFile($this->fileName); + app(EditConfigFile::class)($this->fileName); } /** @test */ @@ -63,7 +63,7 @@ function it_opens_a_config_file_for_editing() $this->configFileExists(); $this->successfullyOpenInEditor(); - app(SavedConfig::class)->createOrEditConfigFile($this->fileName); + app(EditConfigFile::class)($this->fileName); } /** @test */ @@ -75,7 +75,7 @@ function it_throws_an_exception_if_the_configured_editor_fails_to_open() $this->expectException(LamboException::class); - app(SavedConfig::class)->createOrEditConfigFile($this->fileName); + app(EditConfigFile::class)($this->fileName); } /** @test */ @@ -86,11 +86,11 @@ function failing_to_create_the_configuration_directory_throws_an_exception() $this->expectException(LamboException::class); - app(SavedConfig::class)->createOrEditConfigFile($this->fileName); + app(EditConfigFile::class)($this->fileName); } /** @test */ - function failing_to_create_the_configuration_file_throws_an_exception() + public function failing_to_create_the_configuration_file_throws_an_exception() { $this->configDirectoryExists(); $this->configFileExists(false); @@ -98,7 +98,7 @@ function failing_to_create_the_configuration_file_throws_an_exception() $this->expectException(LamboException::class); - app(SavedConfig::class)->createOrEditConfigFile($this->fileName); + app(EditConfigFile::class)($this->fileName); } private function configDirectoryExists(bool $exists = true): void From 062879247baacb8104b92050d8cce12b42647104 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 26 Mar 2021 15:08:25 +0000 Subject: [PATCH 11/14] refactor: improve naming and readability fixes: #138 --- app/Actions/CompileAssets.php | 10 +++++----- app/Actions/{SilentDevScript.php => SilenceNpm.php} | 6 +++--- tests/Feature/CompileAssetsTest.php | 12 ++++++------ tests/Feature/SilentDevScriptTest.php | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) rename app/Actions/{SilentDevScript.php => SilenceNpm.php} (93%) diff --git a/app/Actions/CompileAssets.php b/app/Actions/CompileAssets.php index 22ab8941..3d562fc9 100644 --- a/app/Actions/CompileAssets.php +++ b/app/Actions/CompileAssets.php @@ -10,13 +10,13 @@ class CompileAssets use AbortsCommands; protected $shell; - protected $silentDevScript; + protected $npm; protected $consoleWriter; - public function __construct(Shell $shell, SilentDevScript $silentDevScript, ConsoleWriter $consoleWriter) + public function __construct(Shell $shell, SilenceNpm $silenceNpm, ConsoleWriter $consoleWriter) { $this->shell = $shell; - $this->silentDevScript = $silentDevScript; + $this->npm = $silenceNpm; $this->consoleWriter = $consoleWriter; } @@ -24,10 +24,10 @@ public function __invoke() { $this->consoleWriter->logStep('Compiling project assets'); - $this->silentDevScript->add(); + $this->npm->silence(); $process = $this->shell->execInProject("npm run dev{$this->extraOptions()}"); $this->abortIf(! $process->isSuccessful(), 'Compilation of project assets did not complete successfully', $process); - $this->silentDevScript->remove(); + $this->npm->unsilence(); $this->consoleWriter->success('Project assets compiled successfully.'); } diff --git a/app/Actions/SilentDevScript.php b/app/Actions/SilenceNpm.php similarity index 93% rename from app/Actions/SilentDevScript.php rename to app/Actions/SilenceNpm.php index c231f38f..8ce8fd4b 100644 --- a/app/Actions/SilentDevScript.php +++ b/app/Actions/SilenceNpm.php @@ -5,7 +5,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Facades\File; -class SilentDevScript +class SilenceNpm { private $packageJsonPath; private $backupPackageJsonPath; @@ -16,13 +16,13 @@ public function __construct() $this->backupPackageJsonPath = config('lambo.store.project_path') . '/package-original.json'; } - public function add() + public function silence() { File::copy($this->packageJsonPath, $this->backupPackageJsonPath); File::replace($this->packageJsonPath, $this->getSilentPackageJson($this->packageJsonPath)); } - public function remove() + public function unsilence() { File::move($this->backupPackageJsonPath, $this->packageJsonPath); } diff --git a/tests/Feature/CompileAssetsTest.php b/tests/Feature/CompileAssetsTest.php index bc1dce5e..477b22cf 100644 --- a/tests/Feature/CompileAssetsTest.php +++ b/tests/Feature/CompileAssetsTest.php @@ -3,25 +3,25 @@ namespace Tests\Feature; use App\Actions\CompileAssets; -use App\Actions\SilentDevScript; +use App\Actions\SilenceNpm; use App\LamboException; use Tests\Feature\Fakes\FakeProcess; use Tests\TestCase; class CompileAssetsTest extends TestCase { - private $silentDevScript; + private $npm; public function setUp(): void { parent::setUp(); - $this->silentDevScript = $this->mock(SilentDevScript::class); + $this->npm = $this->mock(SilenceNpm::class); } /** @test */ function it_compiles_project_assets_and_hides_console_output() { - $this->silentDevScript->shouldReceive('add') + $this->npm->shouldReceive('silence') ->once() ->globally() ->ordered(); @@ -33,7 +33,7 @@ function it_compiles_project_assets_and_hides_console_output() ->globally() ->ordered(); - $this->silentDevScript->shouldReceive('remove') + $this->npm->shouldReceive('unsilence') ->once() ->globally() ->ordered(); @@ -44,7 +44,7 @@ function it_compiles_project_assets_and_hides_console_output() /** @test */ function it_throws_an_exception_if_asset_compilation_fails() { - $this->silentDevScript->shouldReceive('add') + $this->npm->shouldReceive('silence') ->once() ->globally() ->ordered(); diff --git a/tests/Feature/SilentDevScriptTest.php b/tests/Feature/SilentDevScriptTest.php index db8c3d1d..1ed16bc9 100644 --- a/tests/Feature/SilentDevScriptTest.php +++ b/tests/Feature/SilentDevScriptTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature; -use App\Actions\SilentDevScript; +use App\Actions\SilenceNpm; use Illuminate\Support\Facades\File; use Tests\TestCase; @@ -35,7 +35,7 @@ function it_adds_a_silent_asset_compilation_script_and_makes_a_backup_of_the_ori ->globally() ->ordered(); - app(SilentDevScript::class)->add(); + app(SilenceNpm::class)->silence(); } /** @test */ @@ -47,6 +47,6 @@ function it_replaces_the_silent_compilation_script_with_the_original() ->with('/some/project/path/package-original.json', '/some/project/path/package.json') ->once(); - app(SilentDevScript::class)->remove(); + app(SilenceNpm::class)->unsilence(); } } From 0124feee2e12bff6c2053ed77a73de86e6b3f1d5 Mon Sep 17 00:00:00 2001 From: Jon Sugar Date: Fri, 26 Mar 2021 20:05:43 +0000 Subject: [PATCH 12/14] Update app/Actions/ValidateConfiguration.php Co-authored-by: Matt Stauffer --- app/Actions/ValidateConfiguration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Actions/ValidateConfiguration.php b/app/Actions/ValidateConfiguration.php index 42c54f2e..841d8e00 100644 --- a/app/Actions/ValidateConfiguration.php +++ b/app/Actions/ValidateConfiguration.php @@ -35,9 +35,9 @@ protected function debugReport(): void $this->consoleWriter->panel('Debug', 'Start', 'fg=black;bg=white'); $this->consoleWriter->text([ - 'Configuration may have changed after validation', - 'Configuration is now as follows:', - ]); + 'Configuration may have changed after validation', + 'Configuration is now as follows:', + ]); $this->configToTable(); $this->consoleWriter->panel('Debug', 'End', 'fg=black;bg=white'); From 7218decc14515eef6b8a5708cba73e9c1a159b69 Mon Sep 17 00:00:00 2001 From: Jon Sugar Date: Fri, 26 Mar 2021 20:05:51 +0000 Subject: [PATCH 13/14] Update app/Helpers/GetTimezone.php Co-authored-by: Matt Stauffer --- app/Helpers/GetTimezone.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Helpers/GetTimezone.php b/app/Helpers/GetTimezone.php index 2971766d..4445ef23 100644 --- a/app/Helpers/GetTimezone.php +++ b/app/Helpers/GetTimezone.php @@ -11,6 +11,7 @@ public function __invoke(): string if ($timezone = ini_get('date.timezone')) { return $timezone; } + return IntlTimeZone::createDefault()->getID(); } } From fdaf1c864462c51fc713be5e29a9174da003fc72 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 26 Mar 2021 20:15:15 +0000 Subject: [PATCH 14/14] Remove extra line. --- tests/TestCase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 0b6ebd48..f00adc4d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -45,7 +45,6 @@ protected function todo(array $lines) protected function skipWithMessage(array $lines, $title = 'SKIPPED'): void { - $lineLength = 80; $header = $this->center(" [ {$title} ] ", '=', $lineLength); $testName = $this->center(str_replace('_', ' ', $this->getName()), ' ', $lineLength);