Completed
Push — master ( 747b3c...8271d0 )
by Anthony
03:05
created

Article   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 28.13 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 1
dl 18
loc 64
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B getLastArticle() 9 22 4
A getArticle() 9 21 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
			if ((is_array($query)) && (count($query) > 0)) {
28
				$articles = [];
29
				
30 View Code Duplication
				foreach ($query as $obj) {
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...
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
					];
38
				}
39
				
40
				App::setValues(["blog" => $articles]);
41
			}
42
		}
43
		
44
		public function getArticle() {
45
			$dbc = App::getDb();
46
			$param = Blog::$parametre_router;
47
			
48
			$query = $dbc->select()->from("_blog_article")
49
				->where("ID_article", "=", $param, "OR")
50
				->where("url", "=", $param)
51
				->get();
52
			
53
			if ((is_array($query)) && (count($query) == 1)) {
54 View Code Duplication
				foreach ($query as $obj) {
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
					App::setValues(["blog" => [
56
						"id_article" => $obj->ID_article,
57
						"title" => $obj->title,
58
						"url" => $obj->url,
59
						"article" => $obj->article,
60
						"publication_date" => $obj->publication_date
61
					]]);
62
				}
63
			}
64
		}
65
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
66
		
67
		
68
		//-------------------------- SETTER ----------------------------------------------------------------------------//
69
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
70
	}