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

Article::getArticle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 21
Code Lines 15

Duplication

Lines 9
Ratio 42.86 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 21
rs 9.0534
cc 4
eloc 15
nc 3
nop 0
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
	}