diff --git a/src/Command/BootstrapCommand.php b/src/Command/BootstrapCommand.php index 031bfb74..a345b8fe 100644 --- a/src/Command/BootstrapCommand.php +++ b/src/Command/BootstrapCommand.php @@ -68,7 +68,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption return $parser ->setDescription( 'The BootstrapUI console provides commands for installing dependencies ' . - 'and samples, and for modifying your application to use BootstrapUI.' + 'and samples, and for modifying your application to use BootstrapUI.', ); } } diff --git a/src/Command/CopyLayoutsCommand.php b/src/Command/CopyLayoutsCommand.php index 7e07fcfe..d4ef4e1c 100644 --- a/src/Command/CopyLayoutsCommand.php +++ b/src/Command/CopyLayoutsCommand.php @@ -69,12 +69,12 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption { return $parser ->setDescription( - 'Copies the sample layouts into the application\'s layout templates folder.' + 'Copies the sample layouts into the application\'s layout templates folder.', ) ->addArgument('target', [ 'help' => sprintf( 'The target path into which to copy the layout files. Defaults to `%s`.', - $this->_getDefaultTargetPath() + $this->_getDefaultTargetPath(), ), 'required' => false, ]); diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index 247ac1fa..d06a39ac 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -303,7 +303,7 @@ protected function _bufferPackageAssets(ConsoleIo $io): bool preg_match( "/{$DS}font{$DS}(?P.+{$DS})?.+\\.(css|woff|woff2)$/", $file->getPathname(), - $matches + $matches, ) ) { $assetPath = $fontPath; @@ -376,7 +376,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption { return $parser ->setDescription( - 'Installs Bootstrap dependencies and links the assets to the application\'s webroot.' + 'Installs Bootstrap dependencies and links the assets to the application\'s webroot.', ) ->addOption('latest', [ 'help' => 'To install the latest minor versions of required assets.', diff --git a/src/Command/ModifyViewCommand.php b/src/Command/ModifyViewCommand.php index 3fb07dba..4ed5296b 100644 --- a/src/Command/ModifyViewCommand.php +++ b/src/Command/ModifyViewCommand.php @@ -55,17 +55,17 @@ protected function _modifyView(string $filePath): bool $content = str_replace( 'use Cake\\View\\View', 'use BootstrapUI\\View\\UIView', - $content + $content, ); $content = str_replace( 'class AppView extends View', 'class AppView extends UIView', - $content + $content, ); $content = str_replace( " public function initialize(): void\n {\n", " public function initialize(): void\n {\n parent::initialize();\n", - $content + $content, ); return $this->_writeFile($filePath, $content); @@ -122,17 +122,17 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption { return $parser ->setDescription( - 'Modifies `AppView.php` to extend this plugin\'s `UIView` class.' + 'Modifies `AppView.php` to extend this plugin\'s `UIView` class.', ) ->addArgument('file', [ 'help' => sprintf( 'The path of the `AppView.php` file. Defaults to `%s`.', - $this->_getDefaultFilePath() + $this->_getDefaultFilePath(), ), 'required' => false, ]) ->setEpilog( - 'Don\'t run this command if you have a already modified the `AppView` class!' + 'Don\'t run this command if you have a already modified the `AppView` class!', ); } } diff --git a/src/View/Helper/BreadcrumbsHelper.php b/src/View/Helper/BreadcrumbsHelper.php index f05f85db..0715774f 100644 --- a/src/View/Helper/BreadcrumbsHelper.php +++ b/src/View/Helper/BreadcrumbsHelper.php @@ -142,7 +142,7 @@ protected function _clearActiveCrumb(): void unset( $this->crumbs[$key]['options']['innerAttrs']['aria-current'], - $this->crumbs[$key]['options']['aria-current'] + $this->crumbs[$key]['options']['aria-current'], ); } } diff --git a/src/View/Helper/FlashHelper.php b/src/View/Helper/FlashHelper.php index 4fc393fe..3ea1f006 100644 --- a/src/View/Helper/FlashHelper.php +++ b/src/View/Helper/FlashHelper.php @@ -58,7 +58,7 @@ public function render(string $key = 'flash', array $options = []): ?string if (!is_array($stack)) { throw new UnexpectedValueException(sprintf( 'Value for flash setting key "%s" must be an array.', - $key + $key, )); } diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index f740a524..0c18ab77 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -3,6 +3,7 @@ namespace BootstrapUI\View\Helper; +use Cake\Core\Configure; use Cake\Core\Configure\Engine\PhpConfig; use Cake\Utility\Hash; use Cake\Utility\Inflector; @@ -214,6 +215,7 @@ class FormHelper extends CoreFormHelper '{{hidden}}{{input}}{{text}}{{tooltip}}', 'submitContainer' => '{{content}}', + 'errorClass' => 'is-invalid', ]; /** @@ -342,7 +344,7 @@ public function __construct(View $View, array $config = []) { $this->_defaultConfig = [ 'align' => static::ALIGN_DEFAULT, - 'errorClass' => 'is-invalid', + 'errorClass' => version_compare(Configure::version(), '5.2.0', '<') ? 'is-invalid' : null, 'grid' => [ static::GRID_COLUMN_ONE => 2, static::GRID_COLUMN_TWO => 10, @@ -380,6 +382,11 @@ public function create(mixed $context = null, array $options = []): string 'spacing' => null, ]; + // This is only for backwards compatibility with CakePHP < 5.2 + if ($this->getConfig('errorClass')) { + $this->setConfig('templates.errorClass', $this->getConfig('errorClass')); + } + return parent::create($context, $this->_processFormOptions($options)); } @@ -498,7 +505,7 @@ public function control(string $fieldName, array $options = []): string isset($options['append']) || isset($options['prepend']) ) { - $options['injectErrorClass'] = $this->_config['errorClass']; + $options['injectErrorClass'] = $this->getConfig('templates.errorClass'); } unset( @@ -507,7 +514,7 @@ public function control(string $fieldName, array $options = []): string $options['spacing'], $options['inline'], $options['nestedInput'], - $options['switch'] + $options['switch'], ); $result = parent::control($fieldName, $options); @@ -542,7 +549,7 @@ protected function _spacingOptions(string $fieldName, array $options): array $options['templates'] += [ 'multicheckboxWrapper' => sprintf( $this->templater()->getConfig('multicheckboxWrapper'), - $options['spacing'] + $options['spacing'], ), ]; } @@ -997,7 +1004,7 @@ protected function _tooltipOptions(string $fieldName, array $options): array ) { $tooltip = $this->templater()->format( 'tooltip', - ['content' => $options['tooltip']] + ['content' => $options['tooltip']], ); $options['label']['templateVars']['tooltip'] = ' ' . $tooltip; } @@ -1134,7 +1141,7 @@ public function staticControl(string $fieldName, array $options = []): string $options = $this->_initInputField( $fieldName, - ['secure' => static::SECURE_SKIP] + $options + ['secure' => static::SECURE_SKIP] + $options, ); $content = $options['escape'] ? h($options['val']) : $options['val']; @@ -1151,7 +1158,7 @@ public function staticControl(string $fieldName, array $options = []): string $this->formProtector->addField( $options['name'], true, - (string)$options['val'] + (string)$options['val'], ); } @@ -1246,7 +1253,7 @@ protected function _processFormOptions(array $options): array if (!in_array($options['align'], static::ALIGN_TYPES)) { throw new InvalidArgumentException( - 'Invalid valid for `align` option. Valid values are: ' . implode(', ', static::ALIGN_TYPES) + 'Invalid valid for `align` option. Valid values are: ' . implode(', ', static::ALIGN_TYPES), ); } @@ -1278,7 +1285,7 @@ protected function _processFormOptions(array $options): array $this->_spacing, 'align-items-center', ], - $options + $options, ); $options['templates'] += $templates; @@ -1287,19 +1294,19 @@ protected function _processFormOptions(array $options): array $templates['label'] = sprintf( $templates['label'], - $this->_gridClass(static::GRID_COLUMN_ONE) + $this->_gridClass(static::GRID_COLUMN_ONE), ); $templates['radioLabel'] = sprintf( $templates['radioLabel'], - $this->_gridClass(static::GRID_COLUMN_ONE) + $this->_gridClass(static::GRID_COLUMN_ONE), ); $templates['multicheckboxLabel'] = sprintf( $templates['multicheckboxLabel'], - $this->_gridClass(static::GRID_COLUMN_ONE) + $this->_gridClass(static::GRID_COLUMN_ONE), ); $templates['formGroup'] = sprintf( $templates['formGroup'], - $this->_gridClass(static::GRID_COLUMN_TWO) + $this->_gridClass(static::GRID_COLUMN_TWO), ); $offsetGridClass = implode(' ', [ diff --git a/src/View/Helper/HtmlHelper.php b/src/View/Helper/HtmlHelper.php index 2afe7430..9449bbec 100644 --- a/src/View/Helper/HtmlHelper.php +++ b/src/View/Helper/HtmlHelper.php @@ -101,7 +101,7 @@ public function icon(string $name, array $options = []): string 'tag' => $options['tag'], 'attrs' => $this->templater()->formatAttributes( $options, - ['tag', 'namespace', 'prefix', 'size'] + ['tag', 'namespace', 'prefix', 'size'], ), ]); } diff --git a/src/View/Widget/InputGroupTrait.php b/src/View/Widget/InputGroupTrait.php index 40535c28..dff49e01 100644 --- a/src/View/Widget/InputGroupTrait.php +++ b/src/View/Widget/InputGroupTrait.php @@ -174,7 +174,7 @@ protected function _processOptions(array $attachment, array $attrs): array unset( $attachment['options']['size'], - $attachment['options']['class'] + $attachment['options']['class'], ); $attrs += $attachment['options']; diff --git a/tests/TestCase/Command/BootstrapCommandTest.php b/tests/TestCase/Command/BootstrapCommandTest.php index a7b81d12..8ed5aaf5 100644 --- a/tests/TestCase/Command/BootstrapCommandTest.php +++ b/tests/TestCase/Command/BootstrapCommandTest.php @@ -17,7 +17,7 @@ public function testEntry() $this->assertOutputEmpty(); $this->assertEquals( ['No command provided. Run `bootstrap --help` to get a list of commands.'], - $this->_err->messages() + $this->_err->messages(), ); } @@ -40,7 +40,7 @@ public function testHelp() 'To get help on a specific command, type `bootstrap command_name --help`', '', ], - $this->_out->messages() + $this->_out->messages(), ); $this->assertErrorEmpty(); } diff --git a/tests/TestCase/Command/CopyLayoutsCommandTest.php b/tests/TestCase/Command/CopyLayoutsCommandTest.php index 5fcc11c7..cf813212 100644 --- a/tests/TestCase/Command/CopyLayoutsCommandTest.php +++ b/tests/TestCase/Command/CopyLayoutsCommandTest.php @@ -64,7 +64,7 @@ public function testCopyLayouts() 'Copying sample layouts...', "Sample layouts copied successfully to `$targetPath`.", ], - $this->_out->messages() + $this->_out->messages(), ); $this->assertErrorEmpty(); } @@ -99,7 +99,7 @@ public function testCustomTargetPath() 'Copying sample layouts...', "Sample layouts copied successfully to `$compatTargetPath`.", ], - $this->_out->messages() + $this->_out->messages(), ); $this->assertErrorEmpty(); } @@ -132,11 +132,11 @@ public function testFilesCannotBeCopied() $this->assertEquals(Command::CODE_ERROR, $result); $this->assertEquals( ['Copying sample layouts...'], - $out->messages() + $out->messages(), ); $this->assertEquals( ["Sample layouts could not be copied to `$targetPath`."], - $err->messages() + $err->messages(), ); } @@ -165,7 +165,7 @@ public function testHelp() `$targetPath`. (optional) "], - $this->_out->messages() + $this->_out->messages(), ); $this->assertErrorEmpty(); } diff --git a/tests/TestCase/Command/InstallCommandTest.php b/tests/TestCase/Command/InstallCommandTest.php index 21ce2ba6..bf8c1e44 100644 --- a/tests/TestCase/Command/InstallCommandTest.php +++ b/tests/TestCase/Command/InstallCommandTest.php @@ -395,13 +395,13 @@ public function testInstallLatest() $package = json_decode( file_get_contents($pluginPath . 'node_modules' . DS . 'bootstrap' . DS . 'package.json'), - true + true, ); $this->assertSame('5.3.3', $package['version']); $package = json_decode( file_get_contents($pluginPath . 'node_modules' . DS . 'bootstrap-icons' . DS . 'package.json'), - true + true, ); $this->assertSame('1.11.3', $package['version']); @@ -412,14 +412,14 @@ public function testInstallLatest() $package = json_decode( file_get_contents($pluginPath . 'node_modules' . DS . 'bootstrap' . DS . 'package.json'), - true + true, ); $this->assertTrue(version_compare($package['version'], '5.3.3', '>=')); $this->assertTrue(version_compare($package['version'], '6.0.0', '<')); $package = json_decode( file_get_contents($pluginPath . 'node_modules' . DS . 'bootstrap-icons' . DS . 'package.json'), - true + true, ); $this->assertTrue(version_compare($package['version'], '1.11.3', '>=')); $this->assertTrue(version_compare($package['version'], '2.0.0', '<')); @@ -459,7 +459,7 @@ public function testNPMNotAvailable() $this->assertEmpty($out->messages()); $this->assertEquals( ['NPM (https://www.npmjs.com/) is required, but not installed. Aborting.'], - $err->messages() + $err->messages(), ); } @@ -490,11 +490,11 @@ public function testDeleteNodeModulesFailure() $this->assertEquals(Command::CODE_ERROR, $result); $this->assertEquals( ['Clearing `node_modules` folder (this can take a while)...'], - $out->messages() + $out->messages(), ); $this->assertEquals( ['Could not clear `node_modules` folder.'], - $err->messages() + $err->messages(), ); } @@ -535,11 +535,11 @@ public function testChangeWorkingDirectoryFailure() 'Cleared `node_modules` folder.', 'Installing packages...', ], - $out->messages() + $out->messages(), ); $this->assertEquals( ["Could not change into plugin directory `$pluginPath`."], - $err->messages() + $err->messages(), ); } @@ -584,11 +584,11 @@ public function testNPMInstallFailure() 'Installing packages...', 'installer output', ], - $out->messages() + $out->messages(), ); $this->assertEquals( ['Package installation failed.'], - $err->messages() + $err->messages(), ); } @@ -627,14 +627,14 @@ public function testDeleteBufferedPackageAssetsFailure() [ 'Refreshing package asset buffer...', ], - $out->messages() + $out->messages(), ); $this->assertEquals( [ '`non-existent.file` could not be deleted.', 'Could not clear all buffered files.', ], - $err->messages() + $err->messages(), ); } @@ -684,7 +684,7 @@ public function testBufferPackageAssetsSkipUnsupportedFileTypes() '`script.js` successfully copied.', 'All files buffered.', ], - $out->messages() + $out->messages(), ); } @@ -724,14 +724,14 @@ public function testBufferPackageAssetsFailure() 'Refreshing package asset buffer...', 'All buffered files cleared.', ], - $out->messages() + $out->messages(), ); $this->assertEquals( [ '`non-existent.css` could not be copied.', 'Could not buffer all files.', ], - $err->messages() + $err->messages(), ); } @@ -761,11 +761,11 @@ public function testRemovePluginAssetsFailure() $this->assertEquals(1234, $result); $this->assertEquals( ['Removing possibly existing plugin assets...'], - $out->messages() + $out->messages(), ); $this->assertEquals( ['Removing plugin assets failed.'], - $err->messages() + $err->messages(), ); } @@ -795,11 +795,11 @@ public function testLinkPluginAssetsFailure() $this->assertEquals(1234, $result); $this->assertEquals( ['Linking plugin assets...'], - $out->messages() + $out->messages(), ); $this->assertEquals( ['Linking plugin assets failed.'], - $err->messages() + $err->messages(), ); } @@ -821,7 +821,7 @@ public function testHelp() --quiet, -q Enable quiet output. --verbose, -v Enable verbose output. "], - $this->_out->messages() + $this->_out->messages(), ); $this->assertErrorEmpty(); } diff --git a/tests/TestCase/Command/ModifyViewCommandTest.php b/tests/TestCase/Command/ModifyViewCommandTest.php index d1daac9d..c8585b60 100644 --- a/tests/TestCase/Command/ModifyViewCommandTest.php +++ b/tests/TestCase/Command/ModifyViewCommandTest.php @@ -23,7 +23,7 @@ public function tearDown(): void if (file_exists(APP . 'View' . DS . 'AppView.php.backup')) { rename( APP . 'View' . DS . 'AppView.php.backup', - APP . 'View' . DS . 'AppView.php' + APP . 'View' . DS . 'AppView.php', ); } @@ -41,16 +41,16 @@ public function testModifyView() copy( $filePath, - APP . 'View' . DS . 'AppView.php.backup' + APP . 'View' . DS . 'AppView.php.backup', ); copy( $comparisonsPath . 'AppView.skeleton.php', - $filePath + $filePath, ); $this->assertFileNotEquals( $comparisonsPath . 'AppView.bootstrap.php', - $filePath + $filePath, ); $this->exec('bootstrap modify_view'); @@ -60,13 +60,13 @@ public function testModifyView() 'Modifying view...', "Modified `$filePath`.", ], - $this->_out->messages() + $this->_out->messages(), ); $this->assertErrorEmpty(); $this->assertFileEquals( $comparisonsPath . 'AppView.bootstrap.php', - $filePath + $filePath, ); } @@ -79,12 +79,12 @@ public function testCustomFilePath() copy( $comparisonsPath . 'AppView.skeleton.php', - $filePath + $filePath, ); $this->assertFileNotEquals( $comparisonsPath . 'AppView.bootstrap.php', - $filePath + $filePath, ); $this->exec('bootstrap modify_view ' . escapeshellarg($filePath)); @@ -94,13 +94,13 @@ public function testCustomFilePath() 'Modifying view...', "Modified `$filePath`.", ], - $this->_out->messages() + $this->_out->messages(), ); $this->assertErrorEmpty(); $this->assertFileEquals( $comparisonsPath . 'AppView.bootstrap.php', - $filePath + $filePath, ); } @@ -132,11 +132,11 @@ public function testPathIsNotAFile() $this->assertEquals(Command::CODE_ERROR, $result); $this->assertEquals( ['Modifying view...'], - $out->messages() + $out->messages(), ); $this->assertEquals( ["Could not modify `$filePath`."], - $err->messages() + $err->messages(), ); } @@ -168,11 +168,11 @@ public function testFileCannotBeRead() $this->assertEquals(Command::CODE_ERROR, $result); $this->assertEquals( ['Modifying view...'], - $out->messages() + $out->messages(), ); $this->assertEquals( ["Could not modify `$filePath`."], - $err->messages() + $err->messages(), ); } @@ -204,11 +204,11 @@ public function testFileCannotBeWritten() $this->assertEquals(Command::CODE_ERROR, $result); $this->assertEquals( ['Modifying view...'], - $out->messages() + $out->messages(), ); $this->assertEquals( ["Could not modify `$filePath`."], - $err->messages() + $err->messages(), ); } @@ -239,7 +239,7 @@ public function testHelp() Don't run this command if you have a already modified the `AppView` class! "], - $this->_out->messages() + $this->_out->messages(), ); $this->assertErrorEmpty(); } diff --git a/tests/TestCase/View/Helper/FlashHelperTest.php b/tests/TestCase/View/Helper/FlashHelperTest.php index 55ee5c1b..7883d205 100644 --- a/tests/TestCase/View/Helper/FlashHelperTest.php +++ b/tests/TestCase/View/Helper/FlashHelperTest.php @@ -137,12 +137,12 @@ public function testRenderMultipleMessages() $this->assertStringContainsString( '