Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| QuestionStatsResource | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resources\Api\V2; |
| 4 | |
| 5 | use App\Models\Question; |
| 6 | use Illuminate\Http\Resources\Json\ResourceCollection as JsonResourceCollection; |
| 7 | use Illuminate\Support\Collection; |
| 8 | |
| 9 | class QuestionStatsResource extends JsonResourceCollection |
| 10 | { |
| 11 | /** @var \App\Models\Question */ |
| 12 | protected $question = null; |
| 13 | |
| 14 | /** |
| 15 | * Create a new resource instance. |
| 16 | * |
| 17 | * @param \Illuminate\Support\Collection $questionStats |
| 18 | * @param \App\Models\Question $question |
| 19 | * @return void |
| 20 | */ |
| 21 | public function __construct(Collection $questionStats = null, Question $question) |
| 22 | { |
| 23 | $this->question = $question; |
| 24 | parent::__construct($questionStats); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Transform the resource into an array. |
| 29 | * |
| 30 | * @param mixed $request |
| 31 | * @return array |
| 32 | */ |
| 33 | // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass, Squiz.Commenting.FunctionComment.Missing |
| 34 | public function toArray($request) |
| 35 | { |
| 36 | return [ |
| 37 | 'answers' => (new AnswersResource($this->question->answers))->toArray($request), |
| 38 | 'stats' => $this->collection->toArray() |
| 39 | ]; |
| 40 | } |
| 41 | } |