Issues (896)

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.

apigen/hook-docs.php (10 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 211.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Generate documentation for hooks in Sensei
4
 * Copied from  https://github.com/woothemes/woocommerce
5
 */
6
class Sensei_HookFinder {
7
	private static $current_file           = '';
8
	private static $files_to_scan          = array();
9
	private static $pattern_custom_actions = '/do_action(.*?);/i';
0 ignored issues
show
The property $pattern_custom_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
	private static $pattern_custom_filters = '/apply_filters(.*?);/i';
0 ignored issues
show
The property $pattern_custom_filters is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
11
	private static $found_files            = array();
12
	private static $custom_hooks_found     = '';
13
    private static $sensei_directory =  '';
14
    private static $docs_output_directory =  '';
15
    private static $put_file =  '';
16
17
    public static function initialize(){
18
19
        self::$sensei_directory = dirname( dirname(__FILE__) );
20
        self::$docs_output_directory = self::$sensei_directory . '/docs.woothemes.com/images/sensei-apidocs/';
21
        self::$put_file =  self::$docs_output_directory.'/hook-docs.html';
22
23
    }
24
25
	private static function get_files( $pattern, $flags = 0, $path = '' ) {
26
27
	    if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {
28
29
	        if ($dir == '\\' || $dir == '/') { $dir = ''; } // End IF Statement
30
31
	        return self::get_files(basename( $pattern ), $flags, $dir . '/' );
32
33
	    } // End IF Statement
34
35
	    $paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT );
36
	    $files = glob( $path . $pattern, $flags );
37
38
	    if ( is_array( $paths ) ) {
39
		    foreach ( $paths as $p ) {
40
			    $found_files = array();
41
		   		$retrieved_files = (array) self::get_files( $pattern, $flags, $p . '/' );
42
		   		foreach ( $retrieved_files as $file ) {
43
			   		if ( ! in_array( $file, self::$found_files ) )
44
			   			$found_files[] = $file;
45
		   		}
46
47
		   		self::$found_files = array_merge( self::$found_files, $found_files );
48
49
		   		if ( is_array( $files ) && is_array( $found_files ) ) {
50
		   			$files = array_merge( $files, $found_files );
51
		   		}
52
53
		    } // End FOREACH Loop
54
	    }
55
	    return $files;
56
    }
57
58
	private static function get_hook_link( $hook, $details = array() ) {
0 ignored issues
show
The parameter $details is not used and could be removed.

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

Loading history...
59
		//if ( ! empty( $details['class'] ) ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
		//	$link = 'http://docs.woothemes.com/sensei-apidocs/source-class-' . $details['class'] . '.html#' . $details['line'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
		//} elseif ( ! empty( $details['function'] ) ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
		//	$link = 'http://docs.woothemes.com/sensei-apidocs/source-function-' . $details['function'] . '.html#' . $details['line'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
		//} else {
64
			$link = 'https://github.com/woothemes/sensei/search?utf8=%E2%9C%93&q=' . $hook;
65
		//}
66
67
		return '<a href="' . $link . '">' . $hook . '</a>';
68
	}
69
70
	public static function process_hooks() {
71
72
        self::initialize();
73
74
		// If we have one, get the PHP files from it.
75
		$template_files 	= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/templates/' );
76
		$template_files[]	= self::$sensei_directory . '/includes/template-functions.php';
77
78
		$shortcode_files 	= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/shortcodes/' );
79
		$widget_files	 	= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/widgets/' );
80
		$admin_files 		= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/admin/' );
81
		$class_files 		= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/' );
82
		$other_files		= array(
83
            self::$sensei_directory.'/woothemes-sensei.php'
84
		);
85
86
		self::$files_to_scan = array(
87
			'Template Hooks'  => $template_files,
88
			'Shortcode Hooks' => $shortcode_files,
89
			'Widget Hooks'    => $widget_files,
90
			'Class Hooks'     => $class_files,
91
			'Admin Hooks'     => $admin_files,
92
			'Other Hooks'     => $other_files,
93
		);
94
95
		$scanned = array();
96
97
		ob_start();
98
99
		echo '<div id="content">';
100
		echo '<h1>Action and Filter Hook Reference</h1>';
101
		echo '<div class="description"><p>The following is a full list of actions and filters found in Sensei.</p></div>';
102
103
		foreach ( self::$files_to_scan as $heading => $files ) {
104
			self::$custom_hooks_found = array();
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type string of property $custom_hooks_found.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
105
106
			foreach ( $files as $f ) {
107
				self::$current_file = basename( $f );
108
109
                if ( in_array( self::$current_file, $scanned ) ) {
110
                    continue;
111
                }
112
113
                $scanned[] = self::$current_file;
114
115
				$tokens             = token_get_all( file_get_contents( $f ) );
116
				$token_type         = false;
117
				$current_class      = '';
118
				$current_function   = '';
119
120
				foreach ( $tokens as $index => $token ) {
121
					if ( is_array( $token ) ) {
122
						if ( $token[0] == T_CLASS ) {
123
							$token_type = 'class';
124
						} elseif ( $token[0] == T_FUNCTION ) {
125
							$token_type = 'function';
126
						} elseif ( $token[1] === 'do_action' ) {
127
							$token_type = 'action';
128
						} elseif ( $token[1] === 'apply_filters' ) {
129
							$token_type = 'filter';
130
						} elseif ( $token_type && ! empty( trim( $token[1] ) ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $token_type of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
131
							switch ( $token_type ) {
132
								case 'class' :
133
									$current_class = $token[1];
134
								break;
135
								case 'function' :
136
									$current_function = $token[1];
137
								break;
138
								case 'filter' :
139
								case 'action' :
140
									$hook = trim( $token[1], "'" );
141
									if ( isset( self::$custom_hooks_found[ $hook ] ) ) {
142
										self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file;
143
									} else {
144
    									self::$custom_hooks_found[ $hook ] = array(
145
											'line'     => $token[2],
146
											'class'    => $current_class,
147
											'function' => $current_function,
148
											'file'     => array( self::$current_file ),
149
											'type'     => $token_type
150
										);
151
									}
152
								break;
153
							}
154
							$token_type = false;
155
						}
156
					}
157
				}
158
			}
159
160
			foreach ( self::$custom_hooks_found as $hook => $details ) {
161
				if ( ! strstr( $hook, 'sensei' ) ) {
162
					unset( self::$custom_hooks_found[ $hook ] );
163
				}
164
			}
165
166
			ksort( self::$custom_hooks_found );
167
168
			if ( ! empty( self::$custom_hooks_found ) ) {
169
				echo '<h2>' . $heading . '</h2>';
170
171
				echo '<table class="summary"><thead><tr><th>Hook</th><th>Type</th><th>File(s)</th></tr></thead><tbody>';
172
173
				foreach ( self::$custom_hooks_found as $hook => $details ) {
174
					echo '<tr>
175
						<td>' . self::get_hook_link( $hook, $details ) . '</td>
176
						<td>' . $details['type'] . '</td>
177
						<td>' . implode( ', ', array_unique( $details['file'] ) ) . '</td>
178
					</tr>' . "\n";
179
				}
180
181
				echo '</tbody></table>';
182
			}
183
		}
184
185
		echo '</div><div id="footer">';
186
187
188
189
        // change to the ouput directory before operating on the files
190
        chdir(  self::$docs_output_directory );
191
192
        $html   = file_get_contents( 'index.html' );
193
		$header = current( explode( '<div id="content">', $html ) );
194
		$header = str_replace( '<li class="active">', '<li>', $header );
195
		$header = str_replace( '<li class="hooks">', '<li class="active">', $header );
196
		$footer = end( explode( '<div id="footer">', $html ) );
197
198
        //  delete old hook-docs file
199
        if( file_exists( self::$put_file  )  ){
200
201
            unlink( self::$put_file );
202
203
        }
204
205
		file_put_contents(  self::$put_file , $header . ob_get_clean() . $footer );
206
207
		echo "Hook docs generated :)\n";
208
	}
209
}
210
211
Sensei_HookFinder::process_hooks();