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.

Json::render()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 16
c 2
b 0
f 0
nc 16
nop 1
dl 0
loc 28
rs 9.4222
1
<?php
2
3
namespace Halfpastfour\PHPChartJS\Renderer;
4
5
use Laminas\Json\Json as JsonHelper;
6
7
/**
8
 * Class Json
9
 *
10
 * @package Halfpastfour\PHPChartJS\Renderer
11
 */
12
class Json extends Renderer
13
{
14
    /**
15
     * Render the necessary JSON for the chart to function in the frontend.
16
     *
17
     * @param int|false $flags
18
     *
19
     * @return string
20
     */
21
    public function render($flags = null)
22
    {
23
        $config = [
24
            'type' => constant(get_class($this->chart) . "::TYPE"),
25
            'data' => [],
26
        ];
27
28
        $labels = $this->chart->labels()->jsonSerialize();
29
        if ($labels) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $labels of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
30
            $config['data']['labels'] = $labels;
31
        }
32
33
        $dataSets = $this->chart->dataSets()->jsonSerialize();
34
        if ($dataSets) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $dataSets of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
35
            $config['data']['datasets'] = $dataSets;
36
        }
37
38
        $options = $this->chart->options()->jsonSerialize();
39
        if (! empty($options)) {
40
            $config['options'] = $options;
41
        }
42
43
        $output = JsonHelper::encode($config, false, ['enableJsonExprFinder' => true]);
44
        if ($flags & Renderer::RENDER_PRETTY) {
45
            $output = JsonHelper::prettyPrint($output);
46
        }
47
48
        return $output;
49
    }
50
}
51