This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
20 | 'url' => new Twig_Function_Method($this, 'url'), |
||
0 ignored issues
–
show
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. ![]() |
|||
21 | 'static' => new Twig_Function_Method($this, 'staticUrl'), |
||
0 ignored issues
–
show
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. ![]() |
|||
22 | 'percent' => new Twig_Function_Method($this, 'makePercent', array( |
||
0 ignored issues
–
show
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. ![]() |
|||
23 | 'is_safe' => array('html') |
||
24 | )), |
||
25 | ); |
||
26 | } |
||
27 | |||
28 | public function getFilters() |
||
29 | { |
||
30 | return array( |
||
0 ignored issues
–
show
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 ![]() |
|||
31 | 'simple_url' => new Twig_Filter_Function('Xhgui_Util::simpleUrl'), |
||
0 ignored issues
–
show
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. ![]() |
|||
32 | 'as_bytes' => new Twig_Filter_Method($this, 'formatBytes', array('is_safe' => array('html'))), |
||
0 ignored issues
–
show
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. ![]() |
|||
33 | 'as_time' => new Twig_Filter_Method($this, 'formatTime', array('is_safe' => array('html'))), |
||
0 ignored issues
–
show
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. ![]() |
|||
34 | 'as_diff' => new Twig_Filter_Method($this, 'formatDiff', array('is_safe' => array('html'))), |
||
0 ignored issues
–
show
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. ![]() |
|||
35 | 'as_percent' => new Twig_Filter_Method($this, 'formatPercent', array('is_safe' => array('html'))), |
||
0 ignored issues
–
show
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. ![]() |
|||
36 | 'truncate' => new Twig_Filter_Method($this, 'truncate'), |
||
0 ignored issues
–
show
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. ![]() |
|||
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 /**
* @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. ![]() |
|||
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 /**
* @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. ![]() |
|||
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 /**
* @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. ![]() |
|||
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) . ' <span class="units">bytes</span>'; |
||
94 | } |
||
95 | |||
96 | public function formatTime($value) |
||
97 | { |
||
98 | return number_format((float)$value) . ' <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 ![]() |
|||
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 |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.