Completed
Push — master ( e5ef44...29e0f1 )
by Auke
18s
created

system_checks.php ➔ check_accept_path_info()   D

Complexity

Conditions 9
Paths 7

Size

Total Lines 43
Code Lines 28

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 9
eloc 28
nc 7
nop 0
dl 0
loc 43
rs 4.909
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 4 and the first side effect is on line 2.

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
	$ariadne = '';
3
4
	function check_php_version() {
5
		if (version_compare(PHP_VERSION, '5.4.7', '>=')) {
6
			return true;
7
		}
8
		return false;
9
	}
10
11
	function check_database_support() {
12
		if (check_mysql() || check_postgresql()) {
13
			return true;
14
		}
15
		return false;
16
	}
17
18
	function check_mysql() {
19
		if(function_exists('mysqli_connect')) {
20
			return true;
21
		}
22
		return false;
23
	}
24
25
	function check_postgresql() {
26
		if (function_exists('pg_connect')) {
27
			return true;
28
		}
29
		return false;
30
	}
31
32
	function check_apache() {
0 ignored issues
show
Coding Style introduced by
check_apache uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
33
		if (preg_match("/^apache/i", $_SERVER['SERVER_SOFTWARE'])) {
34
			return true;
35
		}
36
		return false;
37
	}
38
39
	function check_webserver() {
40
		if (
41
			check_apache()
42
			// FIXME: Add more compatible webservers.
0 ignored issues
show
Coding Style introduced by
Comment refers to a FIXME task "Add more compatible webservers"
Loading history...
43
		) {
44
			return true;
45
		}
46
		return false;
47
	}
48
49
	function check_accept_path_info() {
0 ignored issues
show
Coding Style introduced by
check_accept_path_info uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
50
		if ( function_exists('apache_lookup_uri')) {
51
			$extrapath = "/test_path_info/";
52
			$object = apache_lookup_uri($_SERVER['REQUEST_URI'] . $extrapath);
53
			if ($object->path_info == $extrapath) {
54
				return true;
55
			}
56
			return false;
57
		} else {
58
			$ariadne = '';
59
			@include("../ariadne.inc");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
60
			if ( $ariadne != '' ) {
61
				require_once($ariadne . '/ar.php');
62
63
				// checking if path_info could be available
64
				$testuri = new ar_url('http://' .  $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
65
				$testuri->query = '';
0 ignored issues
show
Documentation introduced by
The property $query is declared private in ar_url. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
66
				$testuri->path = str_replace('/index.php', '/', $testuri->path)."serverinfo.php";
0 ignored issues
show
Documentation introduced by
The property path does not exist on object<ar_url>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property path does not exist on object<ar_url>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
67
				$testuri = (string)$testuri;
68
				$result1 = json_decode(ar_http::get($testuri),true);
69
				$result2 = json_decode(ar_http::get($testuri.'/my/path/info'),true);
70
71
				if ( is_array($result1) && is_array($result2) ) {
72
					// self request works
73
					// pathinfo could work
74
					if( $result2['server']['PATH_INFO'] == '/my/path/info' ) {
75
						return true;
76
					} else {
77
						return false;
78
					}
79
				} elseif ( is_array($result1) && is_null($result2) ) {
80
					// self request works
81
					// request with pathinfo fails
82
					return false;
83
				} else {
84
					// self request fails
85
					// should return 'check via browser'
86
					return false;
87
				}
88
			}
89
		}
90
		return false;
91
	}
92
93
	function check_zend_compat() {
94
		if (!ini_get("zend.ze1_compatibility_mode")) {
95
			return true;
96
		}
97
		return false;
98
	}
99
100
	function check_ariadne_inc_read() {
101
		if (is_readable("../ariadne.inc")) {
102
			return true;
103
		}
104
		return false;
105
	}
106
107
	function check_ariadne_path() {
108
		@include("../ariadne.inc");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
109
		if (is_readable($ariadne . "/templates/pobject/")) {
0 ignored issues
show
Bug introduced by
The variable $ariadne does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
110
			return true;
111
		}
112
		return false;
113
	}
114
115
116
	function check_files_write() {
117
		@include("../ariadne.inc");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
118
		if (is_writable($ariadne . "/../files/")) {
0 ignored issues
show
Bug introduced by
The variable $ariadne does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
119
			return true;
120
		}
121
		return false;
122
	}
123
124
	function check_ariadne_phtml_write() {
125
		@include("../ariadne.inc");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
126
		if (file_exists($ariadne . "/configs/ariadne.phtml")) {
127
			if (is_writable($ariadne . "/configs/ariadne.phtml")) {
0 ignored issues
show
Bug introduced by
The variable $ariadne does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
128
				return true;
129
			}
130
		} else {
131
			if (is_writable($ariadne . "/configs/")) {
132
				return true;
133
			}
134
		}
135
		return false;
136
	}
137
138
	function check_im_convert() {
139
		$bin = find_in_path('convert');
140
		if (is_executable($bin)) {
141
			global $found_bins;
142
			$found_bins['bin_convert'] = $bin;
143
			return true;
144
		}
145
		return false;
146
	}
147
148
	function check_im_mogrify() {
149
		$bin = find_in_path('mogrify');
150
		if (is_executable($bin)) {
151
			global $found_bins;
152
			$found_bins['bin_mogrify'] = $bin;
153
			return true;
154
		}
155
		return false;
156
	}
157
158
	function check_im_composite() {
159
		$bin = find_in_path('composite');
160
		if (is_executable($bin)) {
161
			global $found_bins;
162
			$found_bins['bin_composite'] = $bin;
163
			return true;
164
		}
165
		return false;
166
	}
167
168
	function check_im_identify() {
169
		$bin = find_in_path('identify');
170
		if (is_executable($bin)) {
171
			global $found_bins;
172
			$found_bins['bin_identify'] = $bin;
173
			return true;
174
		}
175
		return false;
176
	}
177
178
	function check_image_magick() {
179
		if (
180
			check_im_convert() &&
181
			check_im_mogrify() &&
182
			check_im_composite() &&
183
			check_im_identify()
184
		) {
185
			return true;
186
		}
187
		return false;
188
	}
189
190
	function check_svn() {
191
		if (
192
			check_svn_class() &&
193
			check_svn_binary()
194
		) {
195
			return true;
196
		}
197
		return false;
198
	}
199
200
	function check_svn_class() {
201
		@include_once("VersionControl/SVN.php");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
202
		if (class_exists("VersionControl_SVN")) {
203
			return true;
204
		}
205
		return false;
206
	}
207
208 View Code Duplication
	function check_svn_binary() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
		$bin = find_in_path('svn');
210
		if (is_executable($bin)) {
211
			global $found_bins;
212
			$found_bins['bin_svn'] = $bin;
213
			return true;
214
		}
215
		return false;
216
	}
217
218
	function check_svn_write() {
219
		@include("../ariadne.inc");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
220
		if (is_writeable($ariadne . "/configs/svn/")) {
0 ignored issues
show
Bug introduced by
The variable $ariadne does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
221
			return true;
222
		}
223
		return false;
224
	}
225
226 View Code Duplication
	function check_html_tidy() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
227
		$bin = find_in_path('tidy');
228
		if (is_executable($bin)) {
229
			global $found_bins;
230
			$found_bins['bin_tidy'] = $bin;
231
			return true;
232
		}
233
		return false;
234
	}
235
236 View Code Duplication
	function check_grep() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
		$bin = find_in_path('grep');
238
		if (is_executable($bin)) {
239
			global $found_bins;
240
			$found_bins['bin_grep'] = $bin;
241
			return true;
242
		}
243
		return false;
244
	}
245
246
	function check_connect_db($conf) {
247 View Code Duplication
		if ($conf && $conf->dbms) {
248
			switch ( $conf->dbms ) {
249
				case 'mysql':
250
				case 'mysql_workspaces':
251
					return check_connect_db_mysql($conf);
252
				break;
253
				case 'postgresql':
254
					return check_connect_db_postgresql($conf);
255
				break;
256
			}
257
			// FIXME: Add postgresql checks too
0 ignored issues
show
Coding Style introduced by
Comment refers to a FIXME task "Add postgresql checks too"
Loading history...
258
		}
259
		return false;
260
	}
261
262
	function check_select_db($conf) {
263 View Code Duplication
		if ($conf && $conf->dbms) {
264
			switch ( $conf->dbms ) {
265
				case 'mysql':
266
				case 'mysql_workspaces':
267
					return check_select_db_mysql($conf);
268
				break;
269
				case 'postgresql':
270
					return check_select_db_postgresql($conf);
271
				break;
272
			}
273
		}
274
		return false;
275
	}
276
277
	function check_db_grants($conf) {
278 View Code Duplication
		if ($conf && $conf->dbms) {
279
			switch ( $conf->dbms ) {
280
				case 'mysql':
281
				case 'mysql_workspaces':
282
					return check_db_grants_mysql($conf);
283
				break;
284
				case 'postgresql':
285
					return check_db_grants_postgresql($conf);
286
				break;
287
			}
288
		}
289
		return false;
290
	}
291
292
	function check_db_grants_mysql($conf) {
293
		$dbh = getConnection($conf);
294
		if (!$dbh->connect_errno) {
295
			$query = "SHOW GRANTS FOR CURRENT_USER();";
296
297
			$result = $dbh->query($query);
298
			if (!$dbh->errno ) {
299
				while ($row = $result->fetch_row()){
300
					if (preg_match("/^GRANT ALL/", $row[0])) {
301
						return true;
302
					}
303
					if (
304
						preg_match("/^GRANT.*?SELECT.*?ON/", $row[0]) &&
305
						preg_match("/^GRANT.*?INSERT.*?ON/", $row[0]) &&
306
						preg_match("/^GRANT.*?UPDATE.*?ON/", $row[0]) &&
307
						preg_match("/^GRANT.*?CREATE.*?ON/", $row[0]) &&
308
						preg_match("/^GRANT.*?DELETE.*?ON/", $row[0])
309
					) {
310
						return true;
311
					}
312
				}
313
			}
314
		}
315
		return false;
316
	}
317
318
	function check_db_grants_postgresql($conf) {
319
		if ( check_select_db_postgresql($conf) ) {
320
			$query = "SELECT has_database_privilege ( '".$conf->database."', 'CREATE' );";
321
			$result = pg_query( $query );
322
			while ( $row = pg_fetch_row( $result ) ) {
323
				if ( $row[0]=='t' ) {
324
					return true;
325
				}
326
			}
327
		}
328
		return false;
329
	}
330
331
	function getConnection($conf){
332
		static $dbh;
333
		if(!isset($dbh)) {
334
			$dbh = new mysqli($conf->host, $conf->user, $conf->password, $conf->database);
335
		}
336
		return $dbh;
337
	}
338
339
	function check_connect_db_mysql($conf) {
340
		$dbh = getConnection($conf);
341
		if ($dbh->connect_errno) {
342
			return false;
343
		}
344
		return true;
345
	}
346
347
	function check_connect_db_postgresql($conf) {
348
		$port = null;
349
		$host = $conf->host;
0 ignored issues
show
Unused Code introduced by
$host 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...
350
		if ( strpos($conf->host,':') !== false) {
351
			list($host,$port) = explode($conf->host, ':',2);
0 ignored issues
show
Unused Code introduced by
The assignment to $host is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
352
		}
353
354
		if( $conf->host == ''){
355
			$hoststr = '';
356
		} else {
357
			$hoststr = 'host='.$conf->host;
358
		}
359
360
		if ($port) {
361
			$hoststr = $hoststr .= ' port='.$port;
362
		}
363
364
		if( $conf->password != '' ){
365
			$password = ' password='.$conf->password;
366
		}
367
368
		$connstring = $hoststr.' dbname='.$conf->database.' user='.$conf->user . ' ' .$password;
0 ignored issues
show
Bug introduced by
The variable $password does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
369
		$conf->connection = pg_connect($connstring);
370
		return (bool) $conf->connection;
371
	}
372
373
	function check_select_db_mysql($conf) {
374
		return check_connect_db_mysql($conf); //connect also checks database
375
	}
376
377
	function check_select_db_postgresql($conf) {
378
		return check_connect_db_postgresql($conf); //connect also checks database
379
	}
380
381
382
	function check_db_is_empty($conf) {
383
		switch( $conf->dbms ) {
384
			case 'mysql':
385
			case 'mysql_workspaces':
386
				return check_db_is_empty_mysql($conf);
387
			break;
388
			case 'postgresql':
389
				return check_db_is_empty_postgresql($conf);
390
			break;
391
		}
392
		return false;
393
	}
394
395
	function check_db_is_empty_mysql($conf) {
396
		$dbh = getConnection($conf);
397
		if (!$dbh->connect_errno) {
398
			$query = "SHOW TABLES;";
399
			$result = $dbh->query($query);
400
			if (!$dbh->errno && $result->num_rows == 0) {
401
				return true;
402
			}
403
		}
404
		return false;
405
	}
406
407
	function check_db_is_empty_postgresql($conf) {
408
		if (check_connect_db_postgresql($conf)) {
409
			$query = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';";
410
			$result = pg_query($conf->connection, $query);
411
			if (pg_num_rows($result) == 0) {
412
				return true;
413
			}
414
		}
415
		return false;
416
	}
417
418
	function check_file( $file ) {
0 ignored issues
show
Best Practice introduced by
The function check_file() has been defined more than once; this definition is ignored, only the first definition in www/install/check.php (L64-81) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
419
		if (file_exists($file) && is_readable($file)) {
420
			return true;
421
		}
422
		return false;
423
	}
424
425
	function check_base_ax() {
426
		if (check_file("packages/base.ax")) {
427
			return true;
428
		}
429
		return false;
430
	}
431
432
	function check_demo_ax() {
433
		if (check_file("packages/demo.ax")) {
434
			return true;
435
		}
436
		return false;
437
	}
438
439
	function check_libs_ax() {
440
		if (check_file("packages/libs.ax")) {
441
			return true;
442
		}
443
		return false;
444
	}
445
446
	function check_docs_ax() {
447
		if (check_file("packages/docs.ax")) {
448
			return true;
449
		}
450
		return false;
451
	}
452
453
	function check_admin_password($admin_passwords) {
454
		if ($admin_passwords[0] && $admin_passwords[1] && $admin_passwords[0] == $admin_passwords[1]) {
455
			return true;
456
		}
457
		return false;
458
	}
459
460
	function check_tar_class() {
461
		@include_once("Archive/Tar.php");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
462
		if (class_exists("Archive_Tar")) {
463
			return true;
464
		}
465
		return false;
466
	}
467
468
	function check_exif() {
469
		if (function_exists('exif_read_data')) {
470
			return true;
471
		}
472
		return false;
473
	}
474
475
	function check_mb_functions() {
476
		if (function_exists('mb_substr')) {
477
			return true;
478
		}
479
		return false;
480
	}
481
482
	function check_mcrypt() {
483
		if (extension_loaded('mcrypt')) {
484
			return true;
485
		}
486
		return false;
487
	}
488
489
	function getServerVar( $name ) {
0 ignored issues
show
Coding Style introduced by
getServerVar uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
490
		return isset( $_SERVER[$name] ) ? $_SERVER[$name] : null;
491
	}
492
493
	function find_in_path($needle,array $extrapath=array()) {
494
		$paths = explode(PATH_SEPARATOR,getServerVar('PATH'));
495
		$paths = array_merge($paths,$extrapath);
496
497
		$exts = explode(PATH_SEPARATOR, getServerVar('PATHEXT'));
498
499
		foreach($paths as $path){
500
			$file = $path . DIRECTORY_SEPARATOR . $needle;
501
			if(file_exists($file)) {
502
				return $file;
503
			}
504
505
			// W32 needs this
506
			foreach ($exts as $ext) {
507
				if(file_exists($file.$ext)) {
508
					return $file.$ext;
509
				}
510
			}
511
		}
512
	}
513
514
	$found_bins = array(); // will be filled by the check functions
515
516
	$required_checks = array(
517
		"check_php_version" => check_php_version(),		// php => 5.4.0
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
518
		"check_database_support" => check_database_support(),	// MySQL or Postgres
519
		"check_webserver" => check_webserver(),			// Apache, IIS, NGINX?
520
		"check_accept_path_info" => check_accept_path_info(),	// Apache config: AcceptPathInfo
521
		"check_zend_compat" => check_zend_compat(),		// zend.ze1_compatibility_mode = Off
522
		"check_ariadne_inc_read" => check_ariadne_inc_read(),	// Check if configuration file (ariadne.inc) can be read bij www-data
523
		"check_ariadne_path" => check_ariadne_path(),		// Check if path in ariadne.inc looks like an Ariadne tree
524
		"check_files_write" => check_files_write(),		// Check if files dir can be written by www-data
525
		"check_base_ax"	=> check_base_ax(),
526
		"check_tar_class" => check_tar_class(),			// Check if Archive/Tar class is available to import packages with.
527
		"check_mb_functions" => check_mb_functions(),			// Check if Archive/Tar class is available to import packages with.
528
	);
529
530
	$recommended_checks = array(
531
		"check_ariadne_phtml_write" => check_ariadne_phtml_write(),	// Check if configuration file (ariadne.phtml) can be written bij www-data
532
		"check_exif" => check_exif(),
533
		"check_image_magick" => check_image_magick(),
534
		"check_svn" => check_svn(),
535
		"check_svn_write" => check_svn_write(),
536
		"check_html_tidy" => check_html_tidy(),
537
		"check_grep" => check_grep(),
538
		"check_demo_ax" => check_demo_ax(),
539
		"check_mcrypt" => check_mcrypt(),
540
//		"check_libs_ax" => check_libs_ax(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
541
//		"check_docs_ax" => check_docs_ax()
542
	);
543
544
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...