From 5b94a455ddcde8deb33959730c6818abfca31087 Mon Sep 17 00:00:00 2001 From: Max Loeb Date: Mon, 18 Sep 2023 18:51:07 -0700 Subject: [PATCH 1/2] simplify --- lib/Relation.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Relation.php b/lib/Relation.php index 90f35dae..1928e3dd 100644 --- a/lib/Relation.php +++ b/lib/Relation.php @@ -170,7 +170,7 @@ public function __call(string $method, mixed $args): Model|null $options['conditions'][] = WhereClause::from_underscored_string($this->table()->conn, $attributes, $args, $this->alias_attribute); $options['limit'] = 1; - $ret = $this->to_a_withOptions($options); + $ret = $this->_to_a($options); if (0 === count($ret)) { if ($create) { @@ -719,7 +719,7 @@ public function find(): Model|array $options['conditions'] ??= []; $options['conditions'][] = $this->pk_conditions($args); - $list = $this->to_a_withOptions($options); + $list = $this->_to_a($options); if (is_array($args) && count($list) != count($args)) { throw new RecordNotFound('found ' . count($list) . ', but was looking for ' . count($args)); } @@ -741,7 +741,7 @@ public function find(): Model|array public function take(int $limit = null): Model|array|null { $options = array_merge($this->options, ['limit' => $limit ?? 1]); - $models = $this->to_a_withOptions($options); + $models = $this->_to_a($options); return isset($limit) ? $models : $models[0] ?? null; } @@ -827,7 +827,7 @@ private function firstOrLast(int $limit = null, bool $isAscending): array } } - return $this->to_a_withOptions($options); + return $this->_to_a($options); } /** @@ -837,17 +837,17 @@ private function firstOrLast(int $limit = null, bool $isAscending): array */ public function to_a(): array { - return $this->to_a_withOptions($this->options); + return $this->_to_a($this->options); } /** - * Converts relation objects to array with a given options. - * * @param RelationOptions $options + * @throws ActiveRecordException + * @throws Exception\RelationshipException * * @return array All the rows that matches query. If no rows match, returns [] */ - private function to_a_withOptions(array $options): array + protected function _to_a(array $options): array { if ($this->isNone) { return []; From b3144e9fa37e198c305d3f28da1c43fc08931790 Mon Sep 17 00:00:00 2001 From: Max Loeb Date: Mon, 18 Sep 2023 19:00:34 -0700 Subject: [PATCH 2/2] lint --- lib/Relation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Relation.php b/lib/Relation.php index 1928e3dd..d58dc34e 100644 --- a/lib/Relation.php +++ b/lib/Relation.php @@ -842,6 +842,7 @@ public function to_a(): array /** * @param RelationOptions $options + * * @throws ActiveRecordException * @throws Exception\RelationshipException *