Passed
Pull Request — master (#29)
by
unknown
01:56
created

Course::studentsWhoPrefer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9
1
<?php
2
3
namespace Example\Models;
4
5
use CoffeeCode\DataLayer\DataLayer;
6
7
class Course extends DataLayer
8
{
9
    /**
10
     * Course constructor.
11
     */
12
    public function __construct()
13
    {
14
        parent::__construct("courses", ["name"], "id", false);
15
    }
16
17
    /**
18
     * @return array|null
19
     */
20
    public function studentsWhoPrefer(): ?array
21
    {
22
        $students = new Student();
23
        return $this
24
            ->select("*, courses.name as course_name")
25
            ->join(
26
                $students, 
27
                'courses.id', '=', 'students.preferred_course')
28
            ->where(
29
                'courses.id = :id', 
30
                "id={$this->id}")
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Example\Models\Course. Since you implemented __get, consider adding a @property annotation.
Loading history...
31
            ->limit(5)
32
            ->fetch(true);
33
    }
34
35
    /**
36
     * @return array|null
37
     */
38
    public function studentsThatFinished(): ?array
39
    {
40
        $students = new Student();
41
        $studentCourse = new StudentCourse();
42
43
        return $this
44
            ->select()
45
            ->join(
46
                $studentCourse,
47
                "courses.id", "=", "student_course.idcourse"
48
            )
49
            ->join(
50
                $students,
51
                "students.id", "=", "student_course.idstudent"
52
            )
53
            ->where(
54
                "courses.id = :id",
55
                "id={$this->id}"
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Example\Models\Course. Since you implemented __get, consider adding a @property annotation.
Loading history...
56
            )
57
            ->fetch(true);
58
    }
59
}