GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

JavaScript::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 27
rs 9.7666
1
<?php
2
3
namespace Halfpastfour\PHPChartJS\Renderer;
4
5
/**
6
 * Class JavaScript
7
 *
8
 * @package Halfpastfour\PHPChartJS\Renderer
9
 */
10
class JavaScript extends Renderer
11
{
12
    /**
13
     * Renders the necessary JavaScript for the chart to function in the frontend.
14
     *
15
     * @param int|null $flags
16
     *
17
     * @return string
18
     */
19
    public function render($flags = null)
20
    {
21
        $script = [];
22
23
        // First, setup the canvas context
24
        $script[] = "var ctx = document.getElementById( \"{$this->chart->getId()}\" ).getContext( \"2d\" );";
25
26
        // Now, setup the chart instance
27
        $jsonRenderer = new Json($this->chart);
28
        $json         = $jsonRenderer->render($flags);
29
        $script[]     = "var chart = new Chart( ctx, {$json} );";
30
        $scriptString = implode("\n", $script);
31
32
        // Return the script
33
        return <<<JS
34
window.onload=(function(oldLoad){return function(){
35
  if (oldLoad) {
36
    oldLoad();
37
  }
38
  
39
  {$scriptString};
40
  
41
  if (! window.hasOwnProperty('chartInstances')) {
42
    window.chartInstances = {};
43
  }
44
  
45
  window.chartInstances['{$this->chart->getId()}'] = chart;
46
}})(window.onload);
47
JS
48
            ;
49
    }
50
}
51