mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Cleanup code, improve typings
This commit is contained in:
21
common/models/AccountQuery.php
Normal file
21
common/models/AccountQuery.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
/**
|
||||
* @see Account
|
||||
*/
|
||||
class AccountQuery extends ActiveQuery {
|
||||
|
||||
public function andWhereLogin(string $login): self {
|
||||
return $this->andWhere([$this->getLoginAttribute($login) => $login]);
|
||||
}
|
||||
|
||||
private function getLoginAttribute(string $login): string {
|
||||
return strpos($login, '@') ? 'email' : 'username';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user