Completed
Push — master ( 47b10e...1cc257 )
by Jacob
03:29
created

URLDecode::getURI()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

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

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
class URLDecode
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
	private static $array = array();
7
8
	static function init()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
init 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...
9
	{
10
		$host = $_SERVER['HTTP_HOST'];
11
		$uri = $_SERVER['REQUEST_URI'];
12
		self::form_url_array($host, $uri);
13
	}
14
15
	static private function form_url_array($host, $uri)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
16
	{
17
		$uri = substr($uri, 1);
18
		if(strpos($uri, '?'))
19
			$uri = substr($uri, 0, strpos($uri, '?'));
20
		$uri_array = explode('/', $uri);
21
		
22
		if(!Loader::isLive())
23
			$host = substr($host, strpos($host, '.') + 1);
24
		
25
		self::$array['host'] = $host;
26
		
27
    if (
28
      $host == 'www.waterfallsofthekeweenaw.com' ||
29
      $host == 'waterfallsofthekeweenaw.com'
30
    ) {
31
			self::$array['site'] = 'waterfalls';
32
		} else {
33
			self::$array['site'] = substr($host, 0, strpos($host, '.'));
34
		}
35
		
36
		self::$array['base'] = 'http://' . (!Loader::isLive() ? 'dev.' : '') . $host . '/';
37
		self::$array['uri'] = '/' . implode('/', $uri_array);
38
		
39
		if(end($uri_array) == '')
40
			$uri_array = array_slice($uri_array, 0, count($uri_array) - 1);
41
		self::$array['pieces'] = (array) $uri_array;
42
	}
43
44
	static function getSite()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
	{
46
		return self::$array['site'];
47
	}
48
49
	static function getHost()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
	{
51
		return self::$array['host'];
52
	}
53
54
	static function getBase()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
	{
56
		return self::$array['base'];
57
	}
58
59
	static function getURI()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
60
	{
61
		return self::$array['uri'];
62
	}
63
64
	static function getExtension()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
65
	{
66
		$file = self::getPiece(-1);
67
		if(substr($file, -1) == '/')
68
			return false;
69
		return substr($file, strrpos($file, '.') + 1);;
70
	}
71
72
	static function getPiece($piece = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
73
	{
74
		if(!$piece)
75
			return self::$array['pieces'];
76
		
77
		if($piece == -1)
78
			return end(self::$array['pieces']);
79
		
80
		$piece = $piece - 1;
81
		if(array_key_exists($piece, self::$array['pieces']))
82
			return self::$array['pieces'][$piece];
83
		return;
84
	}
85
86
}
87
88
URLDecode::init();
89
90
?>
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...
91