Completed
Push — master ( 1bb428...fe8713 )
by Tobias
8s
created

functions_utils.php ➔ _print()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 1
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Print a message
5
 */
6
function _print( $string = NULL ) {
0 ignored issues
show
Coding Style introduced by
_print 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...
7
	if ( 'cli' == php_sapi_name() ) { // PHP is running in terminal
8
		$line_end = PHP_EOL;
9
	} else {
10
		$line_end = '<br/>';
11
	}
12
13
	if ( ! empty( $string ) ) {
14
		$file   = basename( $_SERVER["PHP_SELF"] );
15
		$output = date( 'd-m-Y_H:i:s ' ) . "[$file] $string $line_end";
16
	} else {
17
		$output = $line_end;
18
	}
19
20
	print ( $output );
21
}
22