-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSMBBoard.php
51 lines (45 loc) · 1.38 KB
/
CSMBBoard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
use Spatie\ArrayToXml\ArrayToXml;
class CSMBBoard implements Board
{
public function doReportForStudent(Student $student)
{
$grades = $student->getGrades();
sort($grades);
// I guess that discarding the lowest grade should be done here
// and that the lowest grade should not appear in the final report.
// If it were only a condition to calculate the final result
// then the whole condition would not make sense.
if(count($grades) > 2)
{
unset($grades[0]);
}
$result = $this->calculateFinalResult($grades);
$this->displayReport($student,$grades,$result);
}
private function calculateFinalResult(array $grades)
{
$highest_grade = array_pop($grades);
if($highest_grade > 8)
{
return 'Pass';
}
else
{
return 'Fail';
}
}
private function displayReport(Student $student, array $grades, $result)
{
$report = array(
'id' => $student->getId(),
'name' => $student->getName(),
'grades' => $grades,
'average' => (array_sum($grades) / count($grades)),
'result' => $result
);
$report_xml = ArrayToXml::convert($report);
header('Content-Type: text/xml');
echo $report_xml;
}
}