Issues (459)

src/util/Helper.php (2 issues)

1
<?php
2
3
/**
4
 * JPGraph v4.0.3
5
 */
6
7
namespace Amenadiel\JpGraph\Util;
8
9 1
require_once __DIR__ . '/../config.inc.php';
10
11
/**
12
 * @class Helper
13
 * // Misc Helper functions
14
 */
15
class Helper
16
{
17
    //
18
    // Setup PHP error handler
19
    //
20
    public static function phpErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
0 ignored issues
show
The parameter $vars is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

20
    public static function phpErrorHandler($errno, $errmsg, $filename, $linenum, /** @scrutinizer ignore-unused */ $vars)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
        // Respect current error level
23
        if ($errno & error_reporting()) {
24
            JpGraphError::RaiseL(25003, basename($filename), $linenum, $errmsg);
25
        }
26
    }
27
28
    //
29
    // Utility function to generate an image name based on the filename we
30
    // are running from and assuming we use auto detection of graphic format
31
    // (top level), i.e it is safe to call this function
32
    // from a script that uses JpGraph
33
    //
34
    public static function GenImgName()
35
    {
36
        // Determine what format we should use when we save the images
37
        $supported = imagetypes();
38
        if ($supported & IMG_PNG) {
39
            $img_format = 'png';
40
        } elseif ($supported & IMG_GIF) {
41
            $img_format = 'gif';
42
        } elseif ($supported & IMG_JPG) {
43
            $img_format = 'jpeg';
44
        } elseif ($supported & IMG_WBMP) {
45
            $img_format = 'wbmp';
46
        } elseif ($supported & IMG_XPM) {
47
            $img_format = 'xpm';
48
        }
49
50
        if (!isset($_SERVER['PHP_SELF'])) {
51
            JpGraphError::RaiseL(25005);
52
            //(" Can't access PHP_SELF, PHP global variable. You can't run PHP from command line if you want to use the 'auto' naming of cache or image files.");
53
        }
54
        $fname = basename($_SERVER['PHP_SELF']);
55
        if (!empty($_SERVER['QUERY_STRING'])) {
56
            $q = @$_SERVER['QUERY_STRING'];
57
            $fname .= '_' . preg_replace('/\\W/', '_', $q) . '.' . $img_format;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $img_format does not seem to be defined for all execution paths leading up to this point.
Loading history...
58
        } else {
59
            $fname = substr($fname, 0, strlen($fname) - 4) . '.' . $img_format;
60
        }
61
62
        return $fname;
63
    }
64
65
    // Useful mathematical function
66 6
    public static function sign($a)
67
    {
68 6
        return $a >= 0 ? 1 : -1;
69
    }
70
71
    public static function trace()
72
    {
73
        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
74
75
        $btarray0 = ([
76
            'class2'    => $backtrace[1]['class'],
77
            'type2'     => $backtrace[1]['type'],
78
            'function2' => $backtrace[1]['function'],
79
            'spacer4'   => ' ',
80
            'line2'     => $backtrace[0]['line'],
81
        ]);
82
83
        $tag = implode('', $btarray0);
84
85
        \PC::debug(func_get_args(), $tag);
86
    }
87
}
88