Passed
Push — master ( a40ea7...ddbf02 )
by Anthony
03:04
created

RouterController   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 14
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 85
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestCoreController() 0 8 2
A getTestModuleController() 0 9 2
A getBaseLink() 0 4 1
A getTestControllerExist() 0 5 2
B __construct() 0 17 5
A getController() 0 3 1
A getErreur() 0 3 1
1
<?php
2
	namespace core;
3
	
4
	
5
	class RouterController {
6
		private $page;
7
		private $controller;
8
		private $part;
9
		private $erreur;
10
		
11
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
12
		public function __construct($page, $admin = null) {
13
			if (strpos($page, "controller") !== false) {
14
				$this->part = "app";
15
				if ($admin !== null) {
16
					$this->part = "admin";
17
				}
18
				
19
				$this->page = $page;
20
				
21
				if (($this->getTestCoreController() === false) && ($this->getTestModuleController()  === false)) {
22
					$this->controller = $this->part."/".$this->page.".php";
23
				}
24
				
25
				$this->getTestControllerExist();
26
				$this->erreur = false;
27
			}
28
		}
29
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
30
		
31
		
32
		//-------------------------- GETTER ----------------------------------------------------------------------------//
33
		public function getController(){
34
		    return $this->controller;
35
		}
36
		public function getErreur(){
37
		    return $this->erreur;
38
		}
39
		
40
		/**
41
		 * @return bool
42
		 * this function set if is a controller core the link to the controller
43
		 */
44
		private function getTestCoreController() {
45
			if (strpos($this->page, "controller/core") !== false) {
46
				$this->controller = $this->getBaseLink().".php";
47
				return true;
48
			}
49
			
50
			return false;
51
		}
52
		
53
		/**
54
		 * @return bool
55
		 * this function set if is a controller module the link to the controller
56
		 */
57
		private function getTestModuleController() {
58
			if (strpos($this->page, "controller/modules") !== false) {
59
				$explode = explode("/", $this->getBaseLink(), 3);
60
				$this->controller = $explode[0]."/".$explode[1]."/".$this->part."/controller/".$explode[2].".php";
61
				return true;
62
			}
63
			
64
			return false;
65
		}
66
		
67
		/**
68
		 * @return mixed
69
		 * this function return link and delete controller at the begining of the link
70
		 */
71
		private function getBaseLink() {
72
			$explode = explode("/", $this->page, 2);
73
			return end($explode);
74
		}
75
		
76
		/**
77
		 * redirect on 404 if controller doesn't exist
78
		 */
79
		private function getTestControllerExist() {
80
			if (!file_exists($this->controller)) {
81
				RedirectError::Redirect(404);
82
			}
83
		}
84
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
85
		
86
		
87
		//-------------------------- SETTER ----------------------------------------------------------------------------//
88
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
89
	}