diff --git a/composer.json b/composer.json index 7b5456d..cea1d8c 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ }, "require-dev": { "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0 || ^11.0", - "phpstan/phpstan": "^1" + "phpstan/phpstan": "^1", + "phpstan/phpstan-strict-rules": "^1.6" }, "autoload": { diff --git a/phpstan.neon b/phpstan.neon index 2c1409d..4ed7226 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,8 +1,11 @@ includes: - phpstan-baseline.neon + - vendor/phpstan/phpstan-strict-rules/rules.neon parameters: level: 8 paths: - src bootstrapFiles: - stan_autoload.php + treatPhpDocTypesAsCertain: false + reportMaybesInPropertyPhpDocTypes: false diff --git a/src/QueryBuilderForm.php b/src/QueryBuilderForm.php index e8da1d2..18a6c7a 100644 --- a/src/QueryBuilderForm.php +++ b/src/QueryBuilderForm.php @@ -70,7 +70,7 @@ class QueryBuilderForm extends Widget public $rulesParam = 'rules'; /** - * @var array|QueryBuilder QueryBuilder column configuration. + * @var array|QueryBuilder $builder QueryBuilder column configuration. * For example, * * ```php @@ -91,7 +91,7 @@ class QueryBuilderForm extends Widget /** * @var string JSON rules representation into array format */ - public $rules; + public string $rules = ''; /** * @inheritdoc @@ -106,7 +106,7 @@ public function init() : void $this->builder = $builder; } - if (!$this->builder instanceof QueryBuilder) { + if (!($this->builder instanceof QueryBuilder)) { throw new InvalidConfigException('The "builder" property must be instance of "QueryBuilder'); } @@ -134,7 +134,7 @@ public function run() $builderId = $this->builder->getId(); $view = $this->getView(); - if ($this->rules) { + if (strlen($this->rules) > 0) { $rules = Json::encode($this->rules); $view->registerJs("$('#{$builderId}').queryBuilder('setRules', {$rules});"); } diff --git a/src/RuleHelper.php b/src/RuleHelper.php index ecf5844..4c1d409 100644 --- a/src/RuleHelper.php +++ b/src/RuleHelper.php @@ -13,7 +13,7 @@ class RuleHelper */ public static function addPrefixToRules(array $rules, string $prefix) : array { - if (!isset($rules['rules']) || !$rules['rules']) { + if (!array_key_exists('rules', $rules) || !is_array($rules['rules']) || count($rules['rules']) === 0 ) { return $rules; } @@ -33,7 +33,4 @@ public static function addPrefixToRules(array $rules, string $prefix) : array } - - - } \ No newline at end of file diff --git a/src/Translator.php b/src/Translator.php index 2db1181..2e3802a 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -54,7 +54,7 @@ class Translator public function __construct(private readonly array $data, ?string $paramPrefix = null) { $this->init(); - if($paramPrefix){ + if(!is_null($paramPrefix)){ $this->paramPrefix = $paramPrefix; } $this->_where = $this->buildWhere($this->data); @@ -75,11 +75,11 @@ protected function encodeRule(string $field, string $type, array $params): strin $keys = array_keys($params); if (is_string($pattern)) { - $replacement = !empty($keys) ? $keys[0] : null; + $replacement = count($keys)>0 ? $keys[0] : null; } else { $op = ArrayHelper::getValue($pattern, 'op'); $list = ArrayHelper::getValue($pattern, 'list'); - if ($list){ + if (!is_null($list)){ $sep = ArrayHelper::getValue($pattern, 'sep'); $replacement = implode($sep, $keys); } else { @@ -91,7 +91,7 @@ protected function encodeRule(string $field, string $type, array $params): strin } $this->_params = array_merge($this->_params, $params); - return $field . " " . ($replacement ? str_replace("?", $replacement, $pattern) : $pattern); + return $field . " " . (is_null($replacement) ? $pattern : str_replace("?", $replacement, $pattern) ); } /** @@ -100,7 +100,7 @@ protected function encodeRule(string $field, string $type, array $params): strin */ protected function buildWhere(array $data) : string { - if (!isset($data['rules']) || !$data['rules']) { + if (!array_key_exists('rules', $data) || !is_array($data['rules']) || count($data['rules']) === 0 ) { return ''; }