Skip to content

Commit

Permalink
added phpstan-strict checking
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Oct 12, 2024
1 parent f5ccbdb commit 1800068
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions src/QueryBuilderForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class QueryBuilderForm extends Widget
public $rulesParam = 'rules';

/**
* @var array<mixed>|QueryBuilder QueryBuilder column configuration.
* @var array<mixed>|QueryBuilder $builder QueryBuilder column configuration.
* For example,
*
* ```php
Expand All @@ -91,7 +91,7 @@ class QueryBuilderForm extends Widget
/**
* @var string JSON rules representation into array format
*/
public $rules;
public string $rules = '';

/**
* @inheritdoc
Expand All @@ -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');
}

Expand Down Expand Up @@ -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});");
}
Expand Down
5 changes: 1 addition & 4 deletions src/RuleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -33,7 +33,4 @@ public static function addPrefixToRules(array $rules, string $prefix) : array

}




}
10 changes: 5 additions & 5 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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) );
}

/**
Expand All @@ -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 '';
}

Expand Down

0 comments on commit 1800068

Please sign in to comment.