Completed
Push — master ( f5682e...f9e71a )
by
unknown
20s
created

system_checks.php ➔ check_domdocument_class()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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.6.2', '>=')) {
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");
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");
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");
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");
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");
202
		if (class_exists("VersionControl_SVN")) {
203
			return true;
204
		}
205
		return false;
206
	}
207
208
	function check_domdocument_class() {
209
		if (class_exists("DOMDocument")) {
210
			return true;
211
		}
212
		return false;
213
	}
214
215 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...
216
		$bin = find_in_path('svn');
217
		if (is_executable($bin)) {
218
			global $found_bins;
219
			$found_bins['bin_svn'] = $bin;
220
			return true;
221
		}
222
		return false;
223
	}
224
225
	function check_svn_write() {
226
		@include("../ariadne.inc");
227
		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...
228
			return true;
229
		}
230
		return false;
231
	}
232
233 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...
234
		$bin = find_in_path('tidy');
235
		if (is_executable($bin)) {
236
			global $found_bins;
237
			$found_bins['bin_tidy'] = $bin;
238
			return true;
239
		}
240
		return false;
241
	}
242
243 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...
244
		$bin = find_in_path('grep');
245
		if (is_executable($bin)) {
246
			global $found_bins;
247
			$found_bins['bin_grep'] = $bin;
248
			return true;
249
		}
250
		return false;
251
	}
252
253
	function check_connect_db($conf) {
254 View Code Duplication
		if ($conf && $conf->dbms) {
255
			switch ( $conf->dbms ) {
256
				case 'mysql':
257
				case 'mysql_workspaces':
258
					return check_connect_db_mysql($conf);
259
				break;
260
				case 'postgresql':
261
					return check_connect_db_postgresql($conf);
262
				break;
263
			}
264
			// 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...
265
		}
266
		return false;
267
	}
268
269
	function check_select_db($conf) {
270 View Code Duplication
		if ($conf && $conf->dbms) {
271
			switch ( $conf->dbms ) {
272
				case 'mysql':
273
				case 'mysql_workspaces':
274
					return check_select_db_mysql($conf);
275
				break;
276
				case 'postgresql':
277
					return check_select_db_postgresql($conf);
278
				break;
279
			}
280
		}
281
		return false;
282
	}
283
284
	function check_db_grants($conf) {
285 View Code Duplication
		if ($conf && $conf->dbms) {
286
			switch ( $conf->dbms ) {
287
				case 'mysql':
288
				case 'mysql_workspaces':
289
					return check_db_grants_mysql($conf);
290
				break;
291
				case 'postgresql':
292
					return check_db_grants_postgresql($conf);
293
				break;
294
			}
295
		}
296
		return false;
297
	}
298
299
	function check_db_grants_mysql($conf) {
300
		$dbh = getConnection($conf);
301
		if (!$dbh->connect_errno) {
302
			$query = "SHOW GRANTS FOR CURRENT_USER();";
303
304
			$result = $dbh->query($query);
305
			if (!$dbh->errno ) {
306
				while ($row = $result->fetch_row()){
307
					if (preg_match("/^GRANT ALL/", $row[0])) {
308
						return true;
309
					}
310
					if (
311
						preg_match("/^GRANT.*?SELECT.*?ON/", $row[0]) &&
312
						preg_match("/^GRANT.*?INSERT.*?ON/", $row[0]) &&
313
						preg_match("/^GRANT.*?UPDATE.*?ON/", $row[0]) &&
314
						preg_match("/^GRANT.*?CREATE.*?ON/", $row[0]) &&
315
						preg_match("/^GRANT.*?DELETE.*?ON/", $row[0])
316
					) {
317
						return true;
318
					}
319
				}
320
			}
321
		}
322
		return false;
323
	}
324
325
	function check_db_grants_postgresql($conf) {
326
		if ( check_select_db_postgresql($conf) ) {
327
			$query = "SELECT has_database_privilege ( '".$conf->database."', 'CREATE' );";
328
			$result = pg_query( $query );
329
			while ( $row = pg_fetch_row( $result ) ) {
330
				if ( $row[0]=='t' ) {
331
					return true;
332
				}
333
			}
334
		}
335
		return false;
336
	}
337
338
	function getConnection($conf){
339
		static $dbh;
340
		if(!isset($dbh)) {
341
			$dbh = new mysqli($conf->host, $conf->user, $conf->password, $conf->database);
342
		}
343
		return $dbh;
344
	}
345
346
	function check_connect_db_mysql($conf) {
347
		$dbh = getConnection($conf);
348
		if ($dbh->connect_errno) {
349
			return false;
350
		}
351
		return true;
352
	}
353
354
	function check_connect_db_postgresql($conf) {
355
		$port = null;
356
		$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...
357
		if ( strpos($conf->host,':') !== false) {
358
			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...
359
		}
360
361
		if( $conf->host == ''){
362
			$hoststr = '';
363
		} else {
364
			$hoststr = 'host='.$conf->host;
365
		}
366
367
		if ($port) {
368
			$hoststr = $hoststr .= ' port='.$port;
369
		}
370
371
		if( $conf->password != '' ){
372
			$password = ' password='.$conf->password;
373
		}
374
375
		$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...
376
		$conf->connection = pg_connect($connstring);
377
		return (bool) $conf->connection;
378
	}
379
380
	function check_select_db_mysql($conf) {
381
		return check_connect_db_mysql($conf); //connect also checks database
382
	}
383
384
	function check_select_db_postgresql($conf) {
385
		return check_connect_db_postgresql($conf); //connect also checks database
386
	}
387
388
389
	function check_db_is_empty($conf) {
390
		switch( $conf->dbms ) {
391
			case 'mysql':
392
			case 'mysql_workspaces':
393
				return check_db_is_empty_mysql($conf);
394
			break;
395
			case 'postgresql':
396
				return check_db_is_empty_postgresql($conf);
397
			break;
398
		}
399
		return false;
400
	}
401
402
	function check_db_is_empty_mysql($conf) {
403
		$dbh = getConnection($conf);
404
		if (!$dbh->connect_errno) {
405
			$query = "SHOW TABLES;";
406
			$result = $dbh->query($query);
407
			if (!$dbh->errno && $result->num_rows == 0) {
408
				return true;
409
			}
410
		}
411
		return false;
412
	}
413
414
	function check_db_is_empty_postgresql($conf) {
415
		if (check_connect_db_postgresql($conf)) {
416
			$query = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';";
417
			$result = pg_query($conf->connection, $query);
418
			if (pg_num_rows($result) == 0) {
419
				return true;
420
			}
421
		}
422
		return false;
423
	}
424
425
	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...
426
		if (file_exists($file) && is_readable($file)) {
427
			return true;
428
		}
429
		return false;
430
	}
431
432
	function check_base_ax() {
433
		if (check_file("packages/base.ax")) {
434
			return true;
435
		}
436
		return false;
437
	}
438
439
	function check_demo_ax() {
440
		if (check_file("packages/demo.ax")) {
441
			return true;
442
		}
443
		return false;
444
	}
445
446
	function check_libs_ax() {
447
		if (check_file("packages/libs.ax")) {
448
			return true;
449
		}
450
		return false;
451
	}
452
453
	function check_docs_ax() {
454
		if (check_file("packages/docs.ax")) {
455
			return true;
456
		}
457
		return false;
458
	}
459
460
	function check_admin_password($admin_passwords) {
461
		if ($admin_passwords[0] && $admin_passwords[1] && $admin_passwords[0] == $admin_passwords[1]) {
462
			return true;
463
		}
464
		return false;
465
	}
466
467
	function check_tar_class() {
468
		@include_once("Archive/Tar.php");
469
		if (class_exists("Archive_Tar")) {
470
			return true;
471
		}
472
		return false;
473
	}
474
475
	function check_exif() {
476
		if (function_exists('exif_read_data')) {
477
			return true;
478
		}
479
		return false;
480
	}
481
482
	function check_mb_functions() {
483
		if (function_exists('mb_substr')) {
484
			return true;
485
		}
486
		return false;
487
	}
488
489
	function check_mcrypt() {
490
		if (extension_loaded('mcrypt')) {
491
			return true;
492
		}
493
		return false;
494
	}
495
496
	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...
497
		return isset( $_SERVER[$name] ) ? $_SERVER[$name] : null;
498
	}
499
500
	function find_in_path($needle,array $extrapath=array()) {
501
		$paths = explode(PATH_SEPARATOR,getServerVar('PATH'));
502
		$paths = array_merge($paths,$extrapath);
503
504
		$exts = explode(PATH_SEPARATOR, getServerVar('PATHEXT'));
505
506
		foreach($paths as $path){
507
			$file = $path . DIRECTORY_SEPARATOR . $needle;
508
			if(file_exists($file)) {
509
				return $file;
510
			}
511
512
			// W32 needs this
513
			foreach ($exts as $ext) {
514
				if(file_exists($file.$ext)) {
515
					return $file.$ext;
516
				}
517
			}
518
		}
519
	}
520
521
	$found_bins = array(); // will be filled by the check functions
522
523
	$required_checks = array(
524
		"check_php_version" => check_php_version(),		// php => 5.6.2
525
		"check_database_support" => check_database_support(),	// MySQL or Postgres
526
		"check_webserver" => check_webserver(),			// Apache, IIS, NGINX?
527
		"check_accept_path_info" => check_accept_path_info(),	// Apache config: AcceptPathInfo
528
		"check_zend_compat" => check_zend_compat(),		// zend.ze1_compatibility_mode = Off
529
		"check_ariadne_inc_read" => check_ariadne_inc_read(),	// Check if configuration file (ariadne.inc) can be read bij www-data
530
		"check_ariadne_path" => check_ariadne_path(),		// Check if path in ariadne.inc looks like an Ariadne tree
531
		"check_files_write" => check_files_write(),		// Check if files dir can be written by www-data
532
		"check_base_ax"	=> check_base_ax(),
533
		"check_tar_class" => check_tar_class(),			// Check if Archive/Tar class is available to import packages with.
534
		"check_mb_functions" => check_mb_functions(),			// Check if Archive/Tar class is available to import packages with.
535
		"check_domdocument_class" => check_domdocument_class(),
536
	);
537
538
	$recommended_checks = array(
539
		"check_ariadne_phtml_write" => check_ariadne_phtml_write(),	// Check if configuration file (ariadne.phtml) can be written bij www-data
540
		"check_exif" => check_exif(),
541
		"check_image_magick" => check_image_magick(),
542
		"check_svn" => check_svn(),
543
		"check_svn_write" => check_svn_write(),
544
		"check_html_tidy" => check_html_tidy(),
545
		"check_grep" => check_grep(),
546
		"check_demo_ax" => check_demo_ax(),
547
		"check_mcrypt" => check_mcrypt(),
548
//		"check_libs_ax" => check_libs_ax(),
549
//		"check_docs_ax" => check_docs_ax()
550
	);
551
552
?>
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...