Skip to content

Commit

Permalink
fixed issues reported by phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
arusinowski committed Feb 2, 2024
1 parent 8387e6d commit 338ebd2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
9 changes: 0 additions & 9 deletions config/aliases.php

This file was deleted.

2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ parameters:
level: 8
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
bootstrapFiles:
- tests/bootstrap.php
paths:
- src/
33 changes: 16 additions & 17 deletions src/Datatable/Datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Cake\Core\InstanceConfigTrait;
use Cake\Utility\Inflector;
use Cake\Utility\Text;
use Cake\View\Helper;
use CakeDC\Datatables\Datatables;
use CakeDC\Datatables\Exception\MissConfiguredException;
use CakeDC\Datatables\View\Helper\DatatableHelper;
Expand All @@ -25,8 +24,8 @@ class Datatable
{
use InstanceConfigTrait;

const MULTI_SELECT_TYPE_SELECT2 = 'select2';
const MULTI_SELECT_TYPE_JQUERY_UI = 'jquery-ui';
public const MULTI_SELECT_TYPE_SELECT2 = 'select2';
public const MULTI_SELECT_TYPE_JQUERY_UI = 'jquery-ui';

/**
* @var string
Expand Down Expand Up @@ -85,7 +84,7 @@ class Datatable
'headersAttrsTr' => [],
'headersAttrsTh' => [],
],
'multiSelectType' => self::MULTI_SELECT_TYPE_SELECT2,
'multiSelectType' => self::MULTI_SELECT_TYPE_SELECT2,
'rowActions' => [
'name' => 'actions',
'orderable' => 'false',
Expand All @@ -111,7 +110,7 @@ class Datatable
],
];

protected Helper|DatatableHelper $Helper;
protected DatatableHelper $Helper;

/**
* @var array<string>
Expand Down Expand Up @@ -356,19 +355,18 @@ function validateDate(text) {
});
DATATABLE_CONFIGURATION;

protected $datatableJqueryUITemplate = <<<JQUERYUI_CONFIGURATION
if ($.fn.multiselect) { $(function(){ $('.form-select-multiple').multiselect(); }); }
JQUERYUI_CONFIGURATION;
protected string $datatableJqueryUITemplate = <<<JQUERYUI_CONFIGURATION
if ($.fn.multiselect) { $(function(){ $('.form-select-multiple').multiselect(); }); }
JQUERYUI_CONFIGURATION;


protected $datatableSelect2Template = <<<SELECT2_CONFIGURATION
if($.fn.select2) { $(function(){ $('.form-select-multiple').select2();}); }
SELECT2_CONFIGURATION;
protected string $datatableSelect2Template = <<<SELECT2_CONFIGURATION
if($.fn.select2) { $(function(){ $('.form-select-multiple').select2();}); }
SELECT2_CONFIGURATION;

/**
* @param \Cake\View\Helper $Helper
* @param \CakeDC\Datatables\View\Helper\DatatableHelper $Helper
*/
public function __construct(Helper $Helper)
public function __construct(DatatableHelper $Helper)
{
$this->Helper = $Helper;
$this->setConfig($Helper->getConfig());
Expand Down Expand Up @@ -470,13 +468,12 @@ public function getDatatableScript(): string

$this->processColumnRenderCallbacks();
$this->processColumnDefinitionsCallbacks();
$this->searchHeadersTypes = $this->processColumnTypeSearch();
$this->validateConfigurationOptions();

$this->columnSearchTemplate = Text::insert(
$this->columnSearchTemplate,
[
'searchTypes' => ($this->searchHeadersTypes ?? ''),
'searchTypes' => $this->processColumnTypeSearch(),
'delay' => $this->getConfig('delay') ?? '3000',
'tagId' => $tagId,
]
Expand Down Expand Up @@ -525,7 +522,9 @@ public function getDatatableScript(): string
'null',
'columnSearch' => $this->getConfig('columnSearch') ? $this->columnSearchTemplate : '',
'tableCss' => json_encode($this->getConfig('tableCss')),
'multiSelectCallback' => $this->getConfig('multiSelectType') === 'jquery-ui' ? $this->datatableJqueryUITemplate : $this->datatableSelect2Template,
'multiSelectCallback' => $this->getConfig('multiSelectType') === 'jquery-ui' ?
$this->datatableJqueryUITemplate :
$this->datatableSelect2Template,
];

if ($this->getConfig('createdRow')) {
Expand Down
8 changes: 6 additions & 2 deletions src/View/LinkFormatter/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ public function render(): string
unset($url['extra']);
}

$target = $this->getConfig('target');
assert(is_string($target));
$label = $this->getConfig('value');
assert(is_string($label));
$htmlLink = Text::insert(
$this->getConfig('template'),
[
'href' => $this->helper->Url->build($url) . $urlExtraValue,
'target' => $this->getConfig('target') ?: "' + {$this->getConfig('target')} + '",
'content' => $this->getConfig('label') ?: "' + {$this->getConfig('value')} + '",
'target' => $target ?: "' + {$target} + '",
'content' => $label ?: "' + {$this->getConfig('value')} + '",
]
);

Expand Down
4 changes: 2 additions & 2 deletions src/View/LinkFormatter/LinkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CakeDC\Datatables\View\LinkFormatter;

use Cake\View\Helper;
use CakeDC\Datatables\View\Helper\DatatableHelper;

/**
* LinkInterface
Expand All @@ -13,7 +13,7 @@ interface LinkInterface
/**
* Constructor
*/
public function __construct(Helper $helper, array $config = []);
public function __construct(DatatableHelper $helper, array $config = []);

/**
* Initialize
Expand Down
5 changes: 2 additions & 3 deletions src/View/LinkFormatter/LinkTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

use Cake\Core\InstanceConfigTrait;
use Cake\Utility\Text;
use Cake\View\Helper;
use CakeDC\Datatables\View\Helper\DatatableHelper;
use Exception;

trait LinkTrait
{
use InstanceConfigTrait;

protected Helper|DatatableHelper $helper;
protected DatatableHelper $helper;

protected string $conditionalLinkScript = <<<CONDITIONAL_LINK_SCRIPT
function (value) {
Expand All @@ -29,7 +28,7 @@ function (value) {
/**
* @throws \Exception
*/
public function __construct(Helper $helper, array $config = [])
public function __construct(DatatableHelper $helper, array $config = [])
{
$this->helper = $helper;
$this->setConfig($config);
Expand Down
5 changes: 4 additions & 1 deletion src/View/LinkFormatter/PostLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ public function render(): string
unset($url['extra']);
}

$target = $this->getConfig('target');
assert(is_string($target));

$htmlLink = Text::insert(
$this->getConfig('template'),
[
'href' => $this->helper->Url->build($url) . $urlExtraValue,
'target' => $this->getConfig('target') ?: "' + {$this->getConfig('target')} + '",
'target' => $target ?: "' + $target + '",
'content' => $this->getConfig('label') ?: "' + {$this->getConfig('value')} + '",
'onclick' => $this->onclickAction(),
]
Expand Down
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@
return;
}
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';

use Cake\Controller\Controller;

class_alias(Controller::class, 'App\Controller\AppController');

0 comments on commit 338ebd2

Please sign in to comment.