From 8027fb45804c1c48a258f9f6613e4ea8ebc25039 Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Fri, 19 Apr 2024 11:14:39 +0200 Subject: [PATCH 1/5] configre for kba-team and get phpunit working --- .gitignore | 1 + composer.json | 12 ++++++------ phpunit.xml.dist | 48 +++++++++++++++++++++++------------------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index bc959c53..4675966c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /composer.lock /phpunit.xml /vendor +/.phpunit.result.cache diff --git a/composer.json b/composer.json index 580f88de..4c9675b5 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "maiconpinto/cakephp-adminlte-theme", + "name": "kba-team/cakephp-adminlte-theme", "description": "CakePHP 4.x AdminLTE Theme.", "type": "cakephp-plugin", "keywords": ["cakephp", "templates", "plugin"], @@ -14,11 +14,11 @@ } ], "require": { - "php": ">=7.2.0", - "cakephp/cakephp": "^4.0" + "php": ">=8.1", + "cakephp/cakephp": "^5.0" }, "require-dev": { - "phpunit/phpunit": "~8.5.0" + "phpunit/phpunit": "^10.1.0" }, "autoload": { "psr-4": { @@ -26,7 +26,7 @@ } }, "support": { - "issues": "https://github.com/maiconpinto/cakephp-adminlte-theme/issues", - "source": "https://github.com/maiconpinto/cakephp-adminlte-theme" + "issues": "https://github.com/the-kbA-team/cakephp-adminlte-theme/issues", + "source": "https://github.com/the-kbA-team/cakephp-adminlte-theme" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5977852b..1c8b0ffe 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,25 @@ - - - - - - - - - - ./tests/TestCase/ - - - - - - ./src/ - - - + + + + + + + + + ./tests/TestCase/ + + + + + ./src/ + + From 79eb1673c7dffb31981b2edac973da822559e03f Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Fri, 19 Apr 2024 11:54:56 +0200 Subject: [PATCH 2/5] phpstan checked as well --- .gitattributes | 8 +++ phpstan.neon | 8 +++ phpstan_classes.php | 29 ++++++++++ src/Model/Behavior/DatepickerBehavior.php | 21 ++++--- src/View/AdminLTEView.php | 12 ++-- src/View/Helper/FormHelper.php | 67 ++++++++++++++--------- tests/TestCase/ConfiguresTest.php | 4 +- 7 files changed, 106 insertions(+), 43 deletions(-) create mode 100644 .gitattributes create mode 100644 phpstan.neon create mode 100644 phpstan_classes.php diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..441a7cd1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +tests/ export-ignore +.gitattributes export-ignore +.gitignore export-ignore +composer.* export-ignore +phpunit.* export-ignore +phpstan.neon export-ignore +phpstan_classes.php export-ignore +README.md export-ignore diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..bf5a5961 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,8 @@ +parameters: + level: 9 + checkGenericClassInNonGenericObjectType: false + bootstrapFiles: + - phpstan_classes.php + paths: + - src/ + - tests/ diff --git a/phpstan_classes.php b/phpstan_classes.php new file mode 100644 index 00000000..63236d38 --- /dev/null +++ b/phpstan_classes.php @@ -0,0 +1,29 @@ + */ - protected $_defaultConfig = [ + protected array $_defaultConfig = [ 'fields' => [], 'date_separator' => '/', ]; @@ -22,9 +23,10 @@ class DatepickerBehavior extends Behavior * also adds and merges config settings (direct + configure) * * @param \Cake\ORM\Table $table - * @param array $config + * @param array $config */ - public function __construct(Table $table, array $config = []) { + public function __construct(Table $table, array $config = []) + { $config += $this->_defaultConfig; parent::__construct($table, $config); } @@ -37,20 +39,21 @@ public function __construct(Table $table, array $config = []) { * @param \ArrayObject $options * @return void */ - public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) { - if (!empty($this->_config) && !empty($this->_config['fields'])) { - $separator = $this->_config['date_separator'] ? : '/'; + public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) + { + if (!empty($this->_config) && !empty($this->_config['fields']) && is_array($this->_config['fields'])) { + $separator = is_string($this->_config['date_separator']) && !empty($this->_config['date_separator']) ? $this->_config['date_separator'] : '/'; $locale = Configure::read('App.defaultLocale'); foreach ($this->_config['fields'] as $key) { - if (isset($data[$key])) { + if (isset($data[$key]) && is_string($data[$key])) { if ($locale == 'pt_BR') { list($d, $m, $y) = explode($separator, $data[$key]); } else { list($m, $d, $y) = explode($separator, $data[$key]); } - $data[$key] = $y .'-'. $m .'-'. $d; + $data[$key] = $y . '-' . $m . '-' . $d; } } } diff --git a/src/View/AdminLTEView.php b/src/View/AdminLTEView.php index fe95520c..24b2a860 100644 --- a/src/View/AdminLTEView.php +++ b/src/View/AdminLTEView.php @@ -1,4 +1,5 @@ request->getParam('prefix') ? Inflector::camelize($this->request->getParam('prefix')) : false; + $prefix = is_string($this->request->getParam('prefix')) ? Inflector::camelize($this->request->getParam('prefix')) : false; $theme = $this->theme; $templatePaths = App::path(static::NAME_TEMPLATE); $pluginPaths = []; + $themePaths = []; foreach ($templatePaths as $templateCurrent) { if (!empty($theme)) { if (!empty($plugin)) { for ($i = 0, $count = count($templatePaths); $i < $count; $i++) { if ($prefix) { - $pluginPaths[] = $templatePaths[$i] . 'plugin'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR; + $pluginPaths[] = $templatePaths[$i] . 'plugin' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR; } - $pluginPaths[] = $templatePaths[$i] . 'plugin'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR; + $pluginPaths[] = $templatePaths[$i] . 'plugin' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR; } } if ($prefix) { - $themePaths[] = $templateCurrent . 'plugin'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR; + $themePaths[] = $templateCurrent . 'plugin' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR; } - $themePaths[] = $templateCurrent . 'plugin'. DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR; + $themePaths[] = $templateCurrent . 'plugin' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR; } } diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 0885a428..615ff1a8 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -7,9 +7,13 @@ use Cake\View\View; use Cake\Utility\Inflector; -class FormHelper extends CakeFormHelper { +class FormHelper extends CakeFormHelper +{ - private $templates = [ + /** + * @var array|string[] + */ + private array $templates = [ 'button' => '{{text}}', 'checkbox' => '', 'checkboxFormGroup' => '{{label}}', @@ -46,11 +50,15 @@ class FormHelper extends CakeFormHelper { public function __construct(View $View, array $config = []) { - $this->_defaultConfig['templates'] = array_merge($this->_defaultConfig['templates'], $this->templates); + if (is_array($this->_defaultConfig['templates'])) { + $this->_defaultConfig['templates'] = array_merge($this->_defaultConfig['templates'], $this->templates); + } else { + throw new \Exception("\$this->_defaultConfig['templates'] is not an array"); + } parent::__construct($View, $config); } - public function create($context = null, array $options = []) : string + public function create($context = null, array $options = []): string { $options += ['role' => 'form']; return parent::create($context, $options); @@ -70,13 +78,17 @@ public function submit(?string $caption = null, array $options = []): string } /** - * - * {@inheritDoc} + * + * @param string $fieldName + * @param array $options + * @return string * @see \Cake\View\Helper\FormHelper::input() - * @deprecated 1.1.1 Use FormHelper::control() instead, due to \Cake\View\Helper\FormHelper::input() deprecation + * @deprecated 1.1.1 Use FormHelper::control() instead, due to \Cake\View\Helper\FormHelper::input() deprecation */ - public function input($fieldName, array $options = []) + + public function input(string $fieldName, array $options = []): string { + trigger_error(sprintf('%s is no longer supported', __METHOD__), E_USER_WARNING); $_options = []; @@ -84,7 +96,7 @@ public function input($fieldName, array $options = []) $options['type'] = $this->_inputType($fieldName, $options); } - switch($options['type']) { + switch ($options['type']) { case 'checkbox': case 'radio': case 'date': @@ -99,28 +111,29 @@ public function input($fieldName, array $options = []) return parent::control($fieldName, $options); } - public function control(string $fieldName, array $options = []): string - { - $_options = []; + public function control(string $fieldName, array $options = []): string + { - if (!isset($options['type'])) { - $options['type'] = $this->_inputType($fieldName, $options); - } + $_options = []; - switch($options['type']) { - case 'checkbox': - case 'radio': - case 'date': - break; - default: - $_options = ['class' => 'form-control']; - break; + if (!isset($options['type'])) { + $options['type'] = $this->_inputType($fieldName, $options); + } - } + switch ($options['type']) { + case 'checkbox': + case 'radio': + case 'date': + break; + default: + $_options = ['class' => 'form-control']; + break; - $options += $_options; + } + + $options += $_options; - return parent::control($fieldName, $options); - } + return parent::control($fieldName, $options); + } } diff --git a/tests/TestCase/ConfiguresTest.php b/tests/TestCase/ConfiguresTest.php index 24e55d24..ef05db88 100644 --- a/tests/TestCase/ConfiguresTest.php +++ b/tests/TestCase/ConfiguresTest.php @@ -11,7 +11,7 @@ class ConfiguresTest extends TestCase { - public function testDefaultConfigures() + public function testDefaultConfigures(): void { $expected = [ 'title' => 'AdminLTE', @@ -32,7 +32,7 @@ public function testDefaultConfigures() $this->assertEquals($expected, Configure::read('Theme')); } - public function testNotOverridingUserConfigures() + public function testNotOverridingUserConfigures(): void { $expected = [ 'title' => 'my site name', From 2da83e366ae66160c23923fe9e7d2962306d9f67 Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Fri, 19 Apr 2024 11:57:38 +0200 Subject: [PATCH 3/5] add .github workflow --- .gitattributes | 1 + .github/workflows/main.yml | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.gitattributes b/.gitattributes index 441a7cd1..47e0f7b2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ tests/ export-ignore .gitattributes export-ignore .gitignore export-ignore +.github export-ignore composer.* export-ignore phpunit.* export-ignore phpstan.neon export-ignore diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..ab5601e0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,73 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events + push: + pull_request: + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # Composer config validation + composer: + name: "Composer config validation" + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v3" + - name: "Validate composer.json" + run: "composer validate --strict" + + # PHP syntax validation + php: + name: "PHP syntax validation" + runs-on: "ubuntu-latest" + strategy: + matrix: + php_version: [ 8.1, 8.2, 8.3 ] + steps: + - uses: "actions/checkout@v3" + - uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php_version }}" + + - name: "Check PHP syntax of package" + run: | + php -l src/ + php -l tests/ + + phpunit: + name: "PHPUnit tests" + runs-on: "ubuntu-latest" + strategy: + matrix: + php_version: [ 8.1, 8.2, 8.3 ] + steps: + - uses: "actions/checkout@v3" + - uses: "php-actions/composer@v6" + with: + php_version: "${{ matrix.php_version }}" + php_extensions: intl + - run: "vendor/bin/phpunit" + + # phpstan for several php versions + phpstan: + runs-on: "ubuntu-latest" + strategy: + matrix: + php_version: [ 8.1, 8.2, 8.3 ] + steps: + - uses: "actions/checkout@v3" + - uses: "php-actions/composer@v6" + with: + php_version: "${{ matrix.php_version }}" + php_extensions: intl + - name: "PHPStan Static Analysis" + uses: "php-actions/phpstan@v3" + with: + php_version: "${{ matrix.php_version }}" + configuration: "phpstan.neon" From a1a6e9575238ba22ff2d2a0a9574f8bb9c42006f Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Wed, 24 Apr 2024 12:47:45 +0200 Subject: [PATCH 4/5] revert vendor name --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 4c9675b5..d9f65f9b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "kba-team/cakephp-adminlte-theme", + "name": "maiconpinto/cakephp-adminlte-theme", "description": "CakePHP 4.x AdminLTE Theme.", "type": "cakephp-plugin", "keywords": ["cakephp", "templates", "plugin"], @@ -26,7 +26,7 @@ } }, "support": { - "issues": "https://github.com/the-kbA-team/cakephp-adminlte-theme/issues", - "source": "https://github.com/the-kbA-team/cakephp-adminlte-theme" + "issues": "https://github.com/maiconpinto/cakephp-adminlte-theme/issues", + "source": "https://github.com/maiconpinto/cakephp-adminlte-theme" } } From 4ba2f3c626115f7300d221ed0a3a0451a74e3f8f Mon Sep 17 00:00:00 2001 From: Martin Mitterhauser Date: Wed, 21 Aug 2024 12:45:54 +0200 Subject: [PATCH 5/5] fix composer.json to use our namespace --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index d9f65f9b..94c94c16 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "maiconpinto/cakephp-adminlte-theme", - "description": "CakePHP 4.x AdminLTE Theme.", + "name": "kba-team/cakephp-adminlte-theme", + "description": "CakePHP 5.x AdminLTE Theme.", "type": "cakephp-plugin", "keywords": ["cakephp", "templates", "plugin"], - "homepage": "https://github.com/maiconpinto/cakephp-adminlte-theme", + "homepage": "https://github.com/the-kbA-team/cakephp-adminlte-theme", "license": "MIT", "authors": [ { @@ -26,7 +26,7 @@ } }, "support": { - "issues": "https://github.com/maiconpinto/cakephp-adminlte-theme/issues", - "source": "https://github.com/maiconpinto/cakephp-adminlte-theme" + "issues": "https://github.com/the-kbA-team/cakephp-adminlte-theme/issues", + "source": "https://github.com/the-kbA-team/cakephp-adminlte-theme" } }