Total Complexity | 4 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class RandomModelAttributeQuery extends Query |
||
9 | { |
||
10 | /** |
||
11 | * @var Model|string |
||
12 | */ |
||
13 | private $modelClass; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $attribute; |
||
19 | |||
20 | /** |
||
21 | * @var int |
||
22 | */ |
||
23 | private $take; |
||
24 | |||
25 | /** |
||
26 | * RandomModelAttributeQuery constructor. |
||
27 | * |
||
28 | * @param string $modelClass |
||
29 | * @param string $attribute |
||
30 | * @param int $take |
||
31 | */ |
||
32 | public function __construct(string $modelClass, string $attribute, int $take = 1) |
||
33 | { |
||
34 | $this->modelClass = $modelClass; |
||
35 | $this->attribute = $attribute; |
||
36 | $this->take = $take; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Retrieve a Query builder. |
||
41 | * |
||
42 | * @return Builder |
||
43 | */ |
||
44 | protected function builder(): Builder |
||
45 | { |
||
46 | return $this->modelClass::query(); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Retrieve a random model attribute from all of the model records. |
||
51 | * |
||
52 | * @return mixed |
||
53 | */ |
||
54 | public function execute() |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 |