Completed
Push — master ( 0ddad3...b5072f )
by Anthony
02:20
created

Category   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 32.47 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 1
dl 25
loc 77
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 19 4
B getCategoryArticle() 12 30 5
A getNamemCategorieUrl() 0 10 2

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 modules\blog\app\controller;
3
	
4
	
5
	use core\App;
6
	
7
	class Category {
8
		
9
		
10
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
11
		public function __construct() {
12
			$dbc = App::getDb();
13
			
14
			$query = $dbc->select()->from("_blog_category")->get();
15
			
16 View Code Duplication
			if ((is_array($query)) && (count($query) > 0)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
17
				$categories = [];
18
				
19
				foreach ($query as $obj) {
20
					$categories[] = [
21
						"id_category" => $obj->ID_category,
22
						"category" => $obj->category,
23
						"url_category" => $obj->url_category
24
					];
25
				}
26
				
27
				Blog::setValues(["categories_list" => $categories]);
28
			}
29
		}
30
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
31
		
32
		
33
		//-------------------------- GETTER ----------------------------------------------------------------------------//
34
		/**
35
		 * get all categories of an article
36
		 */
37
		public function getCategoryArticle($id_article = null) {
38
			$dbc = App::getDb();
39
			
40
			if ($id_article === null) {
41
				$id_article = Blog::$router_parameter;
42
			}
43
			
44
			$query = $dbc->select()
45
				->from("_blog_article")
46
				->from("_blog_category")
47
				->from("_blog_article_category")
48
				->where("_blog_article.ID_article", "=", $id_article, "OR")
49
				->where("_blog_article.url", "=", $id_article, "AND")
50
				->where("_blog_article_category.ID_article", "=", "_blog_article.ID_article", "AND", true)
51
				->where("_blog_article_category.ID_category", "=", "_blog_category.ID_category", "", true)
52
				->get();
53
			
54 View Code Duplication
			if ((is_array($query)) && (count($query) > 0)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
55
				$categories = [];
56
				foreach ($query as $obj) {
57
					$categories[] = [
58
						"id_category" => $obj->ID_category,
59
						"category" => $obj->category,
60
						"url_category" => $obj->url_category
61
					];
62
				}
63
				
64
				return $categories;
65
			}
66
		}
67
		
68
		public function getNamemCategorieUrl() {
69
			$dbc = App::getDb();
70
			$url_category = Blog::$router_parameter;
71
			
72
			$query = $dbc->select("category")->from("_blog_category")->where("url_category", "=", $url_category)->get();
73
			
74
			foreach ($query as $obj) {
75
				return $obj->category;
76
			}
77
		}
78
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
79
		
80
		
81
		//-------------------------- SETTER ----------------------------------------------------------------------------//
82
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
83
	}