diff --git a/Base/Model.php b/Base/Model.php index 978f97d..13ac9f5 100644 --- a/Base/Model.php +++ b/Base/Model.php @@ -262,16 +262,16 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T } /** - * @param $param + * @param int|array|string|null $param * @param null $db * @return Model|null * @throws NotFindClassException * @throws ReflectionException * @throws Exception */ - public static function findOne($param, $db = NULL): static|null + public static function findOne(int|array|string|null $param, $db = NULL): static|null { - if (is_bool($param) || is_null($param)) { + if (is_null($param)) { return NULL; } if (is_numeric($param)) { @@ -389,15 +389,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T */ protected static function deleteByCondition($condition = NULL, array $attributes = [], bool $if_condition_is_null = FALSE): bool { - if (empty($condition)) { - if (!$if_condition_is_null) { - return FALSE; - } - return (bool)static::query()->delete(); - } - $model = static::query()->ifNotWhere($if_condition_is_null)->where($condition); - if (!empty($attributes)) { - $model->bindParams($attributes); + $model = static::query(); + if (!empty($condition)) { + $model->where($condition)->bindParams($attributes); } return (bool)$model->delete(); } diff --git a/ModelInterface.php b/ModelInterface.php index 22edc92..1e47a3e 100644 --- a/ModelInterface.php +++ b/ModelInterface.php @@ -18,11 +18,11 @@ interface ModelInterface { /** - * @param $param + * @param int|array|string|null $param * @param null $db * @return ModelInterface */ - public static function findOne($param, $db = NULL): mixed; + public static function findOne(int|array|string|null $param, $db = NULL): mixed; /** diff --git a/Traits/QueryTrait.php b/Traits/QueryTrait.php index 390969e..c2542bb 100644 --- a/Traits/QueryTrait.php +++ b/Traits/QueryTrait.php @@ -780,11 +780,11 @@ trait QueryTrait } /** - * @param array $params + * @param array|null $params * * @return $this */ - public function bindParams(array $params = []): static + public function bindParams(?array $params = []): static { if (empty($params)) { return $this;