Completed
Push — master ( 908239...605605 )
by Anthony
02:03
created

Article   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 101
Duplicated Lines 31.68 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
c 1
b 0
f 0
lcom 0
cbo 1
dl 32
loc 101
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B getLastArticle() 16 23 4
B getArticle() 0 22 4
B getCategoryArticle() 16 31 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 modules\blog\app\controller;
3
	
4
	
5
	use core\App;
6
	
7
	class Article {
8
		
9
		
10
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
11
		public function __construct() {
12
			
13
		}
14
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
15
		
16
		
17
		//-------------------------- GETTER ----------------------------------------------------------------------------//
18
		/**
19
		 * this function get last articles
20
		 */
21
		public function getLastArticle() {
22
			$dbc = App::getDb();
23
			$nb_article = Blog::getArticleIndex();
24
			
25
			$query = $dbc->select()->from("_blog_article")->limit(0, $nb_article)->get();
26
			
27 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...
28
				$articles = [];
29
				
30
				foreach ($query as $obj) {
31
					$articles[] = [
32
						"id_article" => $obj->ID_article,
33
						"title" => $obj->title,
34
						"url" => $obj->url,
35
						"article" => $obj->article,
36
						"publication_date" => $obj->publication_date,
37
						"categories" => Blog::getCategory()->getCategoryArticle($obj->url)
38
					];
39
				}
40
				
41
				Blog::setValues(["articles" => $articles]);
42
			}
43
		}
44
		
45
		/**
46
		 * function that get one article
47
		 */
48
		public function getArticle() {
49
			$dbc = App::getDb();
50
			$param = Blog::$router_parameter;
51
			
52
			$query = $dbc->select()->from("_blog_article")
53
				->where("ID_article", "=", $param, "OR")
54
				->where("url", "=", $param)
55
				->get();
56
			
57
			if ((is_array($query)) && (count($query) == 1)) {
58
				foreach ($query as $obj) {
59
					Blog::setValues(["article" => [
60
						"id_article" => $obj->ID_article,
61
						"title" => $obj->title,
62
						"url" => $obj->url,
63
						"article" => $obj->article,
64
						"publication_date" => $obj->publication_date,
65
						"categories" => Blog::getCategory()->getCategoryArticle()
66
					]]);
67
				}
68
			}
69
		}
70
		
71
		public function getCategoryArticle() {
72
			$dbc = App::getDb();
73
			$category = Blog::$router_parameter;
74
			
75
			$query = $dbc->select()
76
				->from("_blog_article")
77
				->from("_blog_category")
78
				->from("_blog_article_category")
79
				->where("_blog_category.ID_category", "=", $category, "OR")
80
				->where("_blog_category.category", "=", $category, "AND")
81
				->where("_blog_article_category.ID_article", "=", "_blog_article.ID_article", "AND", true)
82
				->where("_blog_article_category.ID_category", "=", "_blog_category.ID_category", "", true)
83
				->get();
84
			
85 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...
86
				$articles = [];
87
				
88
				foreach ($query as $obj) {
89
					$articles[] = [
90
						"id_article" => $obj->ID_article,
91
						"title" => $obj->title,
92
						"url" => $obj->url,
93
						"article" => $obj->article,
94
						"publication_date" => $obj->publication_date,
95
						"categories" => Blog::getCategory()->getCategoryArticle($obj->url)
96
					];
97
				}
98
				
99
				Blog::setValues(["articles" => $articles]);
100
			}
101
		}
102
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
103
		
104
		
105
		//-------------------------- SETTER ----------------------------------------------------------------------------//
106
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
107
	}