Passed
Push — master ( 766755...bcd94f )
by Anthony
04:03
created

InstallRibs   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A getErreur() 0 3 1
A getErreur2002() 0 5 1
A getErreur0() 0 5 1
A getErreur1049() 0 3 1
A getErreur1044() 0 5 1
A getErreur1045() 0 5 1
A setCreerBdd() 0 3 1
1
<?php
2
	namespace installation\controller;
3
	use core\App;
4
	use core\HTML\flashmessage\FlashMessage;
5
6
	class InstallRibs {
7
		private $db_type;
8
		private $db_name;
9
		private $db_user;
10
		private $db_pass;
11
		private $db_host;
12
13
		private $dbc;
14
15
		private $erreur;
16
		
17
		
18
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
19
		public function __construct($db_type, $db_host, $db_name, $db_user, $db_pass) {
20
			$this->db_type = $db_type;
21
			$this->db_name = $db_name;
22
			$this->db_user = $db_user;
23
			$this->db_pass = $db_pass;
24
			$this->db_host = $db_host;
25
26
			try {
27
				$this->dbc = new \PDO($this->db_type.':host='.$this->db_host.';dbname='.$this->db_name, $this->db_user, $this->db_pass);
28
			}
29
			catch (\PDOException $e) {
30
				//on tente de créer la bdd
31
				$erreur = "getErreur".$e->getCode();
32
				$this->$erreur();
33
			}
34
		}
35
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
36
		
37
		
38
		
39
		//-------------------------- GETTER ----------------------------------------------------------------------------//
40
		public function getErreur() {
41
			return $this->erreur;
42
		}
43
44
		/**
45
		 * server adress not ok
46
		 */
47
		private function getErreur2002() {
48
			FlashMessage::setFlash("Le serveur : ".$this->db_host." est introuvable");
49
50
			$this->erreur = true;
51
		}
52
53
		/**
54
		 * seerver type not correct
55
		 */
56
		private function getErreur0() {
57
			FlashMessage::setFlash("Le type : ".$this->db_type." n'est pas un type de base de données cprrect");
58
59
			$this->erreur = true;
60
		}
61
62
		/**
63
		 * couldn't find database
64
		 */
65
		private function getErreur1049() {
66
67
		}
68
69
		/**
70
		 * user uncorrect
71
		 */
72
		private function getErreur1044() {
73
			FlashMessage::setFlash("Le nom d'utilisateur : ".$this->db_user." est incorrect");
74
75
			$this->erreur = true;
76
		}
77
78
		/**
79
		 * password uncorrect
80
		 */
81
		private function getErreur1045() {
82
			FlashMessage::setFlash("Le  mot de passe : ".$this->db_pass." est incorrect");
83
84
			$this->erreur = true;
85
		}
86
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
87
		
88
		
89
		
90
		//-------------------------- SETTER ----------------------------------------------------------------------------//
91
		private function setCreerBdd() {
92
			$this->dbc->query("CREATE DATABASE ".$this->db_name);
93
		}
94
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
95
	}