Conditions | 16 |
Paths | 182 |
Total Lines | 110 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
30 | public function detectUri() |
||
31 | { |
||
32 | $returnObj = new \stdClass; |
||
33 | |||
34 | $returnObj->fileArbo = ''; |
||
35 | $returnObj->nameCtr = ''; |
||
36 | $returnObj->nameMethode = ''; |
||
37 | |||
38 | $uriParse = parse_url($_SERVER['REQUEST_URI']); |
||
39 | $request = rawurldecode($uriParse['path']); |
||
40 | |||
41 | if($request[0] === '/') |
||
42 | { |
||
43 | $request = substr($request, 1); |
||
44 | } |
||
45 | |||
46 | $exRequest = explode('/', $request); |
||
47 | $link = $exRequest[0]; |
||
48 | |||
49 | /* |
||
50 | var_dump($request); |
||
51 | var_dump($exRequest); |
||
52 | var_dump($link); |
||
53 | exit; |
||
54 | */ |
||
55 | |||
56 | //S'il s'agit de la page index ou racine, on envoi vers la page par défault |
||
57 | if($link == 'index.php' || $link == '') |
||
58 | { |
||
59 | $returnObj->fileArbo = $this->controller->getOptions()->defaultMethode.'.php'; |
||
60 | $returnObj->nameCtr = $this->controller->getOptions()->defaultMethode; |
||
61 | |||
62 | return $returnObj; |
||
63 | } |
||
64 | |||
65 | $file_find = false; //Indique si le fichier a été trouvé |
||
66 | $dir_find = false; //Indique si le dossier a été trouvé |
||
67 | |||
68 | $dirArbo = ''; |
||
69 | $methode = ''; |
||
70 | |||
71 | foreach($exRequest as $query) |
||
72 | { |
||
73 | //Le fichier à été trouvé |
||
74 | if($file_find) |
||
75 | { |
||
76 | $this->getArgs[] = $query; |
||
77 | continue; |
||
78 | } |
||
79 | |||
80 | //Tant qu'on a pas trouvé le fichier |
||
81 | |||
82 | if(!empty($dirArbo) && empty($methode)) |
||
83 | { |
||
84 | $methode = $query; |
||
85 | } |
||
86 | |||
87 | //On rajoute un / à la fin du lien si on a commencé à mettre des choses dessus |
||
88 | if($returnObj->fileArbo != '') |
||
89 | { |
||
90 | $returnObj->fileArbo .= '/'; |
||
91 | } |
||
92 | |||
93 | $returnObj->fileArbo .= $query; //Et on y rajoute la valeur lu |
||
94 | //Si le fichier existe dans le dossier controller. On passe la $file_find à true |
||
95 | if(file_exists(path_controllers.'/'.$returnObj->fileArbo.'.php')) |
||
96 | { |
||
97 | $returnObj->nameCtr = $returnObj->fileArbo; |
||
98 | $file_find = true; |
||
99 | } |
||
100 | |||
101 | //Si un dossier existe pourtant le nom, on passe $dir_find à true |
||
102 | if(file_exists(path_controllers.'/'.$returnObj->fileArbo)) |
||
103 | { |
||
104 | $dir_find = true; |
||
105 | $dirArbo = $returnObj->fileArbo; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | if($file_find == true) |
||
110 | { |
||
111 | $returnObj->fileArbo .= '.php'; |
||
112 | |||
113 | return $returnObj; |
||
114 | } |
||
115 | |||
116 | //Si rien a été trouvé, on rajoute "/index" à la fin du lien |
||
117 | if($dir_find == true) |
||
118 | { |
||
119 | $returnObj->nameCtr = $this->fileArbo; |
||
120 | $returnObj->nameMethode = $methode; |
||
121 | |||
122 | if(!(method_exists('\controller\\'.$dirArbo, $methode) && $this->controller->getOptions()->useClass)) |
||
123 | { |
||
124 | $returnObj->fileArbo = $dirArbo.'/index.php'; |
||
125 | $returnObj->nameCtr = $dirArbo.'\index'; |
||
126 | } |
||
127 | |||
128 | return $returnObj; |
||
129 | } |
||
130 | |||
131 | $returnObj->nameMethode = $this->controller->getOptions()->defaultMethode; |
||
132 | |||
133 | if(isset($exRequest[0])) |
||
134 | { |
||
135 | $returnObj->nameMethode = $exRequest[0]; |
||
136 | } |
||
137 | |||
138 | return $returnObj; |
||
139 | } |
||
140 | |||
160 |