Completed
Push — Api_opt ( 47a261...24829b )
by
unknown
69:01 queued 36:29
created

start.php ➔ global_url_handler()   C

Complexity

Conditions 11
Paths 8

Size

Total Lines 30
Code Lines 16

Duplication

Lines 8
Ratio 26.67 %

Importance

Changes 0
Metric Value
cc 11
eloc 16
nc 8
nop 4
dl 8
loc 30
rs 5.2653
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
4
elgg_register_event_handler('init', 'system', 'gc_lang_url_handler_init');
5
elgg_register_plugin_hook_handler('route', 'all', 'global_url_handler', 10);
6
7
function gc_lang_url_handler_init($param1, $param2, $param3) {
8
	// empty ...
9
}
10
11
/**
12
 * Handles incoming HTTP Request from the GSA, this acts as the security layer for the GSA only
13
 * @param $hook
14
 * @param $type
15
 * @param $returnvalue
16
 * @param $params
17
 * @return False to stop processing the response, True will let elgg handle the response
18
 */
19
function global_url_handler($hook, $type, $returnvalue, $params) {
0 ignored issues
show
Coding Style introduced by
global_url_handler uses the super-global variable $_GET 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...
Coding Style introduced by
global_url_handler uses the super-global variable $_COOKIE 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...
Coding Style introduced by
global_url_handler 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...
20
21
	// checks to make sure that the url does not affect the ajax calls
22
	if (strpos($_SERVER['PHP_SELF'], 'ajax') !== false) return;
23
	
24
	if (strpos($_SERVER['PHP_SELF'], '/view') !== false || strpos($_SERVER['PHP_SELF'], '/profile') !== false) {
25
26
		if ($_GET["language"] == 'fr') { 
27 View Code Duplication
			if ($_COOKIE['connex_lang'] != 'fr') {
28
				setcookie('connex_lang', 'fr', 0, '/');
29
				Header('Location: '.$_SERVER['PHP_SELF']);
30
			}
31
		} elseif ($_GET["language"] == 'en') {
32 View Code Duplication
			if ($_COOKIE['connex_lang'] != 'en') {
33
				setcookie('connex_lang', 'en', 0, '/');
34
				Header('Location: '.$_SERVER['PHP_SELF']);
35
			}
36
		} else {
37
			if ($_GET["language"] == '' || $_GET["language"] != 'en' || $_GET["language"] != 'fr'  )  {
38
				
39
				forward("?language=" . get_current_language());
40
			}
41
		}
42
43
	} else {
44
45
		return;
46
	}
47
	
48
}
49
50
51