Skip to content

Commit 5c59aae

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

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
namespace TestApp\Model\Table;
1515

16-
use Cake\Core\Exception\Exception;
1716
use Cake\ORM\Query\SelectQuery;
1817
use Cake\ORM\Table;
1918

@@ -26,13 +25,13 @@ class AuthUsersTable extends Table
2625
* Custom finder
2726
*
2827
* @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
28+
* @param bool $returnCreated Whether to return 'created' field.
29+
* @return \Cake\ORM\Query\SelectQuery The query builder
3130
*/
32-
public function findAuth(SelectQuery $query, array $options)
31+
public function findAuth(SelectQuery $query, bool $returnCreated = false): SelectQuery
3332
{
3433
$query->select(['id', 'username', 'password']);
35-
if (!empty($options['return_created'])) {
34+
if ($returnCreated) {
3635
$query->select(['created']);
3736
}
3837

@@ -43,19 +42,13 @@ public function findAuth(SelectQuery $query, array $options)
4342
* Custom finder
4443
*
4544
* @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
45+
* @param string $username String username
46+
* @return \Cake\ORM\Query\SelectQuery The query builder
4847
*/
49-
public function findUsername(SelectQuery $query, array $options)
48+
public function findUsername(SelectQuery $query, string $username): SelectQuery
5049
{
51-
if (empty($options['username'])) {
52-
throw new Exception('Username not defined');
53-
}
54-
55-
$query = $this->find()
56-
->where(['username' => $options['username']])
50+
return $this->find()
51+
->where(['username' => $username])
5752
->select(['id', 'username', 'password']);
58-
59-
return $query;
6053
}
6154
}

0 commit comments

Comments
 (0)