From 4bcd4a8a448f8f15f781c5c3cd976665dbdd89bc Mon Sep 17 00:00:00 2001 From: whwyy Date: Mon, 18 Dec 2023 17:59:42 +0800 Subject: [PATCH] eee --- Base/Model.php | 53 ++++++++++++++++++++++++-------------------------- Model.php | 51 ++++++++++++++++++++++++------------------------ 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/Base/Model.php b/Base/Model.php index a901a0b..94e96bc 100644 --- a/Base/Model.php +++ b/Base/Model.php @@ -231,11 +231,10 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** * @param int|string|array $param - * @param null $db * @return Model|null * @throws */ - public static function findOne(int|string|array $param, $db = NULL): ?static + public static function findOne(int|string|array $param): ?static { $model = static::instance(); @@ -258,11 +257,10 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** * @param int $param - * @param null $db * @return Model|null * @throws */ - public static function primary(int $param, $db = NULL): ?static + public static function primary(int $param): ?static { $model = static::instance(); $query = new ActiveQuery($model); @@ -523,10 +521,10 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** - * @param $value + * @param array $value * @return $this */ - public function populates($value): static + public function populates(array $value): static { $this->_attributes = $value; $this->_oldAttributes = $value; @@ -555,11 +553,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** - * @param $rule + * @param array $rule * @return Validator * @throws */ - private function resolve($rule): Validator + private function resolve(array $rule): Validator { $validate = new Validator(); foreach ($rule as $val) { @@ -596,11 +594,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** - * @param $attribute + * @param string $attribute * @return bool * @throws */ - public function has($attribute): bool + public function has(string $attribute): bool { return true; } @@ -626,11 +624,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** - * @param $oldAttributes - * @param $changeAttributes + * @param array $oldAttributes + * @param array $changeAttributes * @return bool */ - public function afterSave($oldAttributes, $changeAttributes): bool + public function afterSave(array $oldAttributes, array $changeAttributes): bool { return TRUE; } @@ -656,12 +654,13 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ return $this; } + /** - * @param $name - * @param $value - * @throws + * @param string $name + * @param mixed $value + * @return void */ - public function __set($name, $value): void + public function __set(string $name, mixed $value): void { if ($this->hasRelateMethod($name, 'set')) { $this->{'set' . ucfirst($name)}($value); @@ -676,11 +675,10 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** - * @param $name + * @param string $name * @return mixed - * @throws */ - public function __get($name): mixed + public function __get(string $name): mixed { $value = $this->_attributes[$name] ?? null; if (!$this->hasRelateMethod($name)) { @@ -692,12 +690,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** - * @param $name - * @param null $value + * @param string $name + * @param mixed|null $value * @return mixed - * @throws */ - protected function withPropertyOverride($name, $value = null): mixed + protected function withPropertyOverride(string $name, mixed $value = null): mixed { $method = 'get' . ucfirst($name) . 'Attribute'; if (method_exists($this, $method)) { @@ -720,10 +717,10 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ /** - * @param $name - * @return mixed|null + * @param string $name + * @return mixed */ - protected function withRelate($name): mixed + protected function withRelate(string $name): mixed { $response = $this->{'get' . ucfirst($name)}(); if ($response instanceof \Database\Traits\Relation) { @@ -737,7 +734,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ * @param $name * @return bool */ - public function __isset($name): bool + public function __isset(string $name): bool { return isset($this->_attributes[$name]); } diff --git a/Model.php b/Model.php index 45fcbe3..feb8dfb 100644 --- a/Model.php +++ b/Model.php @@ -168,12 +168,11 @@ class Model extends Base\Model /** - * @param $columns - * @param $action + * @param array $columns + * @param string $action * @return array|bool|int|string|null - * @throws */ - private function mathematics($columns, $action): int|bool|array|string|null + private function mathematics(array $columns, string $action): int|bool|array|string|null { $condition = [$this->getPrimary() => $this->getPrimaryValue()]; $activeQuery = static::query()->where($condition); @@ -249,10 +248,10 @@ class Model extends Base\Model /** - * @param $data + * @param array $data * @return array */ - private function withs($data): array + private function withs(array $data): array { $with = $this->getWith(); foreach ($with as $value) { @@ -268,12 +267,12 @@ class Model extends Base\Model /** * @param ModelInterface|string $modelName - * @param $foreignKey - * @param $localKey + * @param string $foreignKey + * @param string $localKey * @return string - * @throws + * @throws Exception */ - private function _hasBase(ModelInterface|string $modelName, $foreignKey, $localKey): string + private function _hasBase(ModelInterface|string $modelName, string $foreignKey, string $localKey): string { if (($value = $this->{$localKey}) === null) { throw new Exception("Need join table primary key."); @@ -291,12 +290,12 @@ class Model extends Base\Model /** * @param ModelInterface|string $modelName - * @param $foreignKey - * @param $localKey + * @param string $foreignKey + * @param string $localKey * @return HasOne|ActiveQuery - * @throws + * @throws Exception */ - public function hasOne(ModelInterface|string $modelName, $foreignKey, $localKey): HasOne|ActiveQuery + public function hasOne(ModelInterface|string $modelName, string $foreignKey, string $localKey): HasOne|ActiveQuery { return new HasOne($this->_hasBase($modelName, $foreignKey, $localKey)); } @@ -304,12 +303,12 @@ class Model extends Base\Model /** * @param ModelInterface|string $modelName - * @param $foreignKey - * @param $localKey + * @param string $foreignKey + * @param string $localKey * @return ActiveQuery|HasCount - * @throws + * @throws Exception */ - public function hasCount(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasCount + public function hasCount(ModelInterface|string $modelName, string $foreignKey, string $localKey): ActiveQuery|HasCount { return new HasCount($this->_hasBase($modelName, $foreignKey, $localKey)); } @@ -317,24 +316,24 @@ class Model extends Base\Model /** * @param ModelInterface|string $modelName - * @param $foreignKey - * @param $localKey + * @param string $foreignKey + * @param string $localKey * @return ActiveQuery|HasMany - * @throws + * @throws Exception */ - public function hasMany(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasMany + public function hasMany(ModelInterface|string $modelName, string $foreignKey, string $localKey): ActiveQuery|HasMany { return new HasMany($this->_hasBase($modelName, $foreignKey, $localKey)); } /** * @param ModelInterface|string $modelName - * @param $foreignKey - * @param $localKey + * @param string $foreignKey + * @param string $localKey * @return ActiveQuery|HasMany - * @throws + * @throws Exception */ - public function hasIn(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasMany + public function hasIn(ModelInterface|string $modelName, string $foreignKey, string $localKey): ActiveQuery|HasMany { if (($value = $this->{$localKey}) === null) { throw new Exception("Need join table primary key.");