Passed
Push — master ( c51a0a...99fb41 )
by Anthony
02:59
created

Navigation   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 66
Duplicated Lines 48.48 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 13
c 3
b 0
f 0
lcom 0
cbo 2
dl 32
loc 66
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 16 5
A getLienNavigationPage() 16 16 4
A getLienNavigationModule() 16 16 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
	namespace core;
3
	class Navigation {
4
		
5
		
6
		
7
		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
8
		public function __construct() {
9
			$dbc = App::getDb();
10
11
			$query = $dbc->select()->from("navigation")->orderBy("ordre")->get();
12
13
			if (is_array($query) && (count($query) > 0)) {
14
				foreach ($query as $obj) {
15
					if ($obj->ID_page === null) {
16
						$this->getLienNavigationModule($obj->ID_module);
17
					}
18
					else {
19
						$this->getLienNavigationPage($obj->ID_page);
20
					}
21
				}
22
			}
23
		}
24
		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
25
		
26
		
27
		
28
		//-------------------------- GETTER ----------------------------------------------------------------------------//
29 View Code Duplication
		private function getLienNavigationPage($id_page) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
			$dbc = App::getDb();
31
32
			$query = $dbc->select()
33
				->from("navigation")
34
				->from("page")
35
				->where("navigation.ID_page", "=", "page.ID_page", "AND")
36
				->where("page.ID_page", "=", $id_page)
37
				->get();
38
39
			if (is_array($query) && (count($query) > 0)) {
40
				foreach ($query as $obj) {
41
					echo($obj->titre." ++ ".$obj->url."<br>");
42
				}
43
			}
44
		}
45
46 View Code Duplication
		private function getLienNavigationModule($id_module) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
			$dbc = App::getDb();
48
49
			$query = $dbc->select()
50
				->from("navigation")
51
				->from("module")
52
				->where("navigation.ID_module", "=", "module.ID_module", "AND")
53
				->where("module.ID_module", "=", $id_module)
54
				->get();
55
56
			if (is_array($query) && (count($query) > 0)) {
57
				foreach ($query as $obj) {
58
					echo($obj->nom_module." ++ ".$obj->url."<br>");
59
				}
60
			}
61
		}
62
		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
63
		
64
		
65
		
66
		//-------------------------- SETTER ----------------------------------------------------------------------------//
67
		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
68
	}