Issues (413)

Repositories/Eloquent/UserRepositoryEloquent.php (1 issue)

1
<?php
2
3
namespace Yeelight\Repositories\Eloquent;
4
5
use Illuminate\Support\Collection;
6
use Yeelight\Models\Foundation\User;
7
use Yeelight\Presenters\UserPresenter;
8
use Yeelight\Repositories\Criteria\RequestCriteria;
9
use Yeelight\Repositories\Interfaces\UserRepository;
10
use Yeelight\Validators\UserValidator;
11
12
/**
13
 * Class UserRepositoryEloquent
14
 *
15
 * @category Yeelight
16
 *
17
 * @package Yeelight\Repositories\Eloquent
18
 *
19
 * @author Sheldon Lee <[email protected]>
20
 *
21
 * @license https://opensource.org/licenses/MIT MIT
22
 *
23
 * @link https://www.yeelight.com
24
 */
25
class UserRepositoryEloquent extends BaseRepository implements UserRepository
26
{
27
    /**
28
     * $fieldSearchable
29
     *
30
     * @var array
31
     */
32
    protected $fieldSearchable = [
33
        'user_id',
34
        'name'     => 'like',
35
        'username' => 'like',
36
        'email'    => 'like',
37
        'gender',
38
        'country',
39
        'timezone' => 'like',
40
        'locale',
41
        'phone_number' => 'like',
42
    ];
43
44
    /**
45
     * $isSearchableForceAndWhere
46
     *
47
     * @var bool
48
     */
49
    protected $isSearchableForceAndWhere = true;
50
51
    /**
52
     * Specify Model class name.
53
     *
54
     * @return string
55
     */
56
    public function model()
57
    {
58
        return User::class;
59
    }
60
61
    /**
62
     * Specify Validator class name.
63
     *
64
     * @return mixed
65
     */
66
    public function validator()
67
    {
68
        return UserValidator::class;
69
    }
70
71
    /**
72
     * Specify Presenter class name.
73
     *
74
     * @return mixed
75
     */
76
    public function presenter()
77
    {
78
        return UserPresenter::class;
79
    }
80
81
    /**
82
     * ByUserIds
83
     *
84
     * @param array|Collection $userIds Collection
85
     *
86
     * @return $this
87
     */
88
    public function byUserIds($userIds)
89
    {
90
        $this->model = $this->model->whereIn('user_id', $userIds);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->model->whereIn('user_id', $userIds) can also be of type Illuminate\Database\Query\Builder or Illuminate\Database\Eloquent\Builder. However, the property $model is declared as type Illuminate\Database\Eloquent\Model. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
91
92
        return $this;
93
    }
94
95
    /**
96
     * Boot up the repository, pushing criteria.
97
     */
98
    public function boot()
99
    {
100
        $this->pushCriteria(app(RequestCriteria::class));
101
    }
102
}
103