Skip to content

Commit fe0a6d8

Browse files
committed
Update finder methods and find() calls.
1 parent 75935c9 commit fe0a6d8

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

src/Identifier/Resolver/OrmResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function find(array $conditions, $type = self::TYPE_AND): ArrayAccess|arr
6363
if (is_string($options)) {
6464
$query->find($options);
6565
} else {
66-
$query->find($finder, $options);
66+
$query->find($finder, ...$options);
6767
}
6868
}
6969

tests/TestCase/Identifier/Resolver/OrmResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testFindConfig()
4040
'userModel' => 'AuthUsers',
4141
'finder' => [
4242
'all',
43-
'auth' => ['return_created' => true],
43+
'auth' => ['returnCreated' => true],
4444
],
4545
]);
4646

tests/test_app/TestApp/Model/Table/AuthUsersTable.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class AuthUsersTable extends Table
2626
* Custom finder
2727
*
2828
* @param \Cake\ORM\Query\SelectQuery $query The query to find with
29-
* @param array $options The options to find with
30-
* @return \Cake\ORM\Query The query builder
29+
* @param bool $returnCreated Whether to return 'created' field.
30+
* @return \Cake\ORM\Query\SelectQuery The query builder
3131
*/
32-
public function findAuth(SelectQuery $query, array $options)
32+
public function findAuth(SelectQuery $query, bool $returnCreated = false): SelectQuery
3333
{
3434
$query->select(['id', 'username', 'password']);
35-
if (!empty($options['return_created'])) {
35+
if ($returnCreated) {
3636
$query->select(['created']);
3737
}
3838

@@ -43,19 +43,13 @@ public function findAuth(SelectQuery $query, array $options)
4343
* Custom finder
4444
*
4545
* @param \Cake\ORM\Query\SelectQuery $query The query to find with
46-
* @param array $options The options to find with
47-
* @return \Cake\ORM\Query The query builder
46+
* @param string $username String username
47+
* @return \Cake\ORM\Query\SelectQuery The query builder
4848
*/
49-
public function findUsername(SelectQuery $query, array $options)
49+
public function findUsername(SelectQuery $query, string $username): SelectQuery
5050
{
51-
if (empty($options['username'])) {
52-
throw new Exception('Username not defined');
53-
}
54-
55-
$query = $this->find()
56-
->where(['username' => $options['username']])
51+
return $this->find()
52+
->where(['username' => $username])
5753
->select(['id', 'username', 'password']);
58-
59-
return $query;
6054
}
6155
}

0 commit comments

Comments
 (0)