Completed
Push — master ( 505b4c...62d9c0 )
by Seth
05:17 queued 03:12
created

Toolbox::getHistory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace smtech\GradingAnalytics;
4
5
use smtech\LTI\Configuration\Option;
6
use Battis\HierarchicalSimpleCache;
7
8
class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox
9
{
10
    const TOOL_CANVAS_EXTERNAL_TOOL_ID = 'TOOL_CANVAS_EXTERNAL_TOOL_ID';
11
12
    protected $history;
13
14
    protected $snapshots;
15
16
    public function getGenerator()
17
    {
18
        parent::getGenerator();
19
20
        $this->generator->setOptionProperty(
21
            Option::COURSE_NAVIGATION(),
22
            'visibility',
23
            'admins'
24
        );
25
        $this->generator->setOptionProperty(
26
            Option::ACCOUNT_NAVIGATION(),
27
            'visibility',
28
            'admins'
29
        );
30
31
        return $this->generator;
32
    }
33
34
    protected function loadConfiguration($configFilePath, $forceRecache = false)
35
    {
36
        parent::loadConfiguration($configFilePath, $forceRecache);
37
38
        if ($forceRecache) {
39
            $this->clearConfig(self::TOOL_CANVAS_EXTERNAL_TOOL_ID);
40
        }
41
    }
42
43
    private $GRAPH_DATA_COUNT = 0;
44
    public function graphWidth($dataCount = false)
45
    {
46
        if ($dataCount) {
47
            $this->GRAPH_DATA_COUNT = $dataCount;
0 ignored issues
show
Documentation Bug introduced by
The property $GRAPH_DATA_COUNT was declared of type integer, but $dataCount is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
48
        }
49
        return max(GRAPH_MIN_WIDTH, $this->GRAPH_DATA_COUNT * GRAPH_BAR_WIDTH);
50
    }
51
52
    public function graphHeight($dataCount = false)
53
    {
54
        if ($dataCount) {
55
            $this->GRAPH_DATA_COUNT = $dataCount;
0 ignored issues
show
Documentation Bug introduced by
The property $GRAPH_DATA_COUNT was declared of type integer, but $dataCount is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
56
        }
57
        return $this->graphWidth() * GRAPH_ASPECT_RATIO;
58
    }
59
60
    public function getHistory($courseId)
61
    {
62
        if (!is_a($this->history, History::class)) {
63
            $this->history = new History($this, $courseId);
64
        }
65
        return $this->history->getHistory();
66
    }
67
68
    public function getSnapshot($courseOrDepartmentId, Domain $domain, $isCourseId = true, $teacherFilter = false)
69
    {
70
        if (empty($this->snapshots[$domain])) {
71
            $this->snapshots[$domain] = new Snapshot($this, $domain, $courseOrDepartmentId, $isCourseId);
72
        }
73
        return $this->snapshots[$domain]->getSnapshot($teacherFilter);
74
    }
75
}
76