Issues (45)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Xhgui/Twig/Extension.php (15 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class Xhgui_Twig_Extension extends Twig_Extension
4
{
5
    protected $_app;
6
7
    public function __construct($app)
8
    {
9
        $this->_app = $app;
10
    }
11
12
    public function getName()
13
    {
14
        return 'xhgui';
15
    }
16
17
    public function getFunctions()
18
    {
19
        return array(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array('url' => ne...e' => array('html')))); (array<string,Twig_Function_Method>) is incompatible with the return type declared by the interface Twig\Extension\ExtensionInterface::getFunctions of type Twig\TwigFunction[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
20
            'url' => new Twig_Function_Method($this, 'url'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Function_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
21
            'static' => new Twig_Function_Method($this, 'staticUrl'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Function_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
            'percent' => new Twig_Function_Method($this, 'makePercent', array(
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Function_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
23
                'is_safe' => array('html')
24
            )),
25
        );
26
    }
27
28
    public function getFilters()
29
    {
30
        return array(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array('simple_url...od($this, 'truncate')); (array<string,Twig_Filter...ion|Twig_Filter_Method>) is incompatible with the return type declared by the interface Twig\Extension\ExtensionInterface::getFilters of type Twig\TwigFilter[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
31
            'simple_url' => new Twig_Filter_Function('Xhgui_Util::simpleUrl'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Filter_Function has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
32
            'as_bytes' => new Twig_Filter_Method($this, 'formatBytes', array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Filter_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
33
            'as_time' => new Twig_Filter_Method($this, 'formatTime', array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Filter_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
34
            'as_diff' => new Twig_Filter_Method($this, 'formatDiff', array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Filter_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
35
            'as_percent' => new Twig_Filter_Method($this, 'formatPercent', array('is_safe' => array('html'))),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Filter_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
36
            'truncate' => new Twig_Filter_Method($this, 'truncate'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Filter_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
37
        );
38
    }
39
40
    protected function _getBase()
41
    {
42
        $base = dirname($_SERVER['PHP_SELF']);
43
        if ($base == '/') {
44
            return '';
45
        }
46
        return $base;
47
    }
48
49
    public function truncate($input, $length = 50)
50
    {
51
        if (strlen($input) < $length) {
52
            return $input;
53
        }
54
        return substr($input, 0, $length) . "\xe2\x80\xa6";
55
    }
56
57
    /**
58
     * Get a URL for xhgui.
59
     *
60
     * @param string $path The file/path you want a link to
0 ignored issues
show
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
61
     * @param array $queryarg Additional querystring arguments.
0 ignored issues
show
There is no parameter named $queryarg. Did you maybe mean $queryargs?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
62
     * @return string url.
63
     */
64
    public function url($name, $queryargs = array())
65
    {
66
        $query = '';
67
        if (!empty($queryargs)) {
68
            $query = '?' . http_build_query($queryargs);
69
        }
70
        return $this->_app->urlFor($name)  . $query;
71
    }
72
73
    /**
74
     * Get the URL for static content relative to webroot
75
     *
76
     * @param string $path The file/path you want a link to
0 ignored issues
show
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
77
     * @return string url.
78
     */
79
    public function staticUrl($url)
80
    {
81
        $rootUri = $this->_app->request()->getRootUri();
82
83
        // Get URL part prepending index.php
84
        $indexPos = strpos($rootUri, 'index.php');
85
        if ($indexPos > 0) {
86
            return substr($rootUri, 0, $indexPos) . $url;
87
        }
88
        return $rootUri . '/' . $url;
89
    }
90
91
    public function formatBytes($value)
92
    {
93
        return number_format((float)$value) . '&nbsp;<span class="units">bytes</span>';
94
    }
95
96
    public function formatTime($value)
97
    {
98
        return number_format((float)$value) . '&nbsp;<span class="units">µs</span>';
99
    }
100
101
    public function formatDiff($value)
102
    {
103
        $class = 'diff-same';
0 ignored issues
show
$class is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
104
        $class = $value > 0 ? 'diff-up' : 'diff-down';
105
        if ($value == 0) {
106
            $class = 'diff-same';
107
        }
108
        return sprintf(
109
            '<span class="%s">%s</span>',
110
            $class,
111
            number_format((float)$value)
112
        );
113
    }
114
115
    public function makePercent($value, $total)
116
    {
117
        $value = (false === empty($total)) ? $value / $total : 0;
118
        return $this->formatPercent($value);
119
    }
120
121
    public function formatPercent($value)
122
    {
123
        return number_format((float)$value * 100, 0) . ' <span class="units">%</span>';
124
    }
125
}
126