Passed
Push — master ( 4c85c7...39cc03 )
by Anthony
03:13
created

GestionErreurContenus::getTestUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
	namespace core\admin\contenus;
3
	
4
	
5
	use core\App;
6
	use core\HTML\flashmessage\FlashMessage;
7
	
8
	trait GestionErreurContenus {
9
		private $erreur;
10
		private $err_balise_title;
11
		private $err_url;
12
		private $err_meta_description;
13
		private $err_titre_page;
14
		
15
		//-------------------------- GETTER ----------------------------------------------------------------------------//
16
		/**
17
		 * @param string $nom_table
18
		 * @param string $nom_id_table
19
		 * @param string $champ
20
		 * @param $value
21
		 * @param integer $limit_char
22
		 * @param string $err_char
23
		 * @param string $err_egalite
24
		 * @param null $value_id_table
25
		 * @return string
26
		 * fonction qui permet de vérifier qu'il n'y ait pas d'erreur dans le champ spécifié ni de doublons
27
		 */
28
		private function getVerifChamp($nom_table, $nom_id_table, $champ, $value, $limit_char, $err_char, $err_egalite, $value_id_table = null) {
29
			$dbc = App::getDb();
30
			
31
			if (strlen(utf8_decode($value)) > $limit_char) {
32
				$this->erreur = true;
33
				return "<li>$err_char</li>";
34
			}
35
			else if ($dbc->rechercherEgalite($nom_table, $champ, $value, $nom_id_table, $value_id_table) == true) {
36
				$this->erreur = true;
37
				return "<li>$err_egalite</li>";
38
			}
39
		}
40
		
41
		/**
42
		 * @param $balise_title
43
		 * @param null $id_page
44
		 * @return string
45
		 */
46
		private function getTestBaliseTitle($balise_title, $id_page = null) {
47
			$err_balise_title_char = "Le titre pour le navigateur ne doit pas dépasser 70 caractères";
48
			$err_balise_title_egalite = "Ce titre est déjà présent en base de données, merci d'en choisir un autre pour optimiser le référencement de votre site";
49
			$this->err_balise_title = $this->getVerifChamp("page", "ID_page", "balise_title", $balise_title, 70, $err_balise_title_char, $err_balise_title_egalite, $id_page);
50
		}
51
		
52
		/**
53
		 * @param $url
54
		 * @param null $id_page
55
		 * @return string
56
		 */
57
		private function getTestUrl($url, $id_page = null) {
58
			$err_url_char = "L'url ne doit pas dépasser 92 caractères";
59
			$err_url_egalite = "Cette url est déjà présent en base de données, merci d'en choisir une autre pour ne pas avoir de conflit entre vos pages";
60
			$this->err_url = $this->getVerifChamp("page", "ID_page", "url", $url, 92, $err_url_char, $err_url_egalite, $id_page);
61
		}
62
		
63
		/**
64
		 * @param $meta_description
65
		 * @param null $id_page
66
		 * @return string
67
		 */
68
		private function getTestMetaDescription($meta_description, $id_page = null) {
69
			$err_meta_description_char = "La description de cette page ne doit pas dépasser 158 caractères";
70
			$err_meta_description_egalite = "Cette description est déjà présent en base de données, merci d'en choisir une autre pour optimiser le référencement de votre site";
71
			$this->err_meta_description = $this->getVerifChamp("page", "ID_page", "meta_description", $meta_description, 158, $err_meta_description_char, $err_meta_description_egalite, $id_page);
72
		}
73
		
74
		/**
75
		 * @param $titre_page
76
		 * @param null $id_page
77
		 * @return string
78
		 */
79
		private function getTestTitrePage($titre_page, $id_page = null) {
80
			$err_titre_page_char = "Le titre de cette page ne doit pas dépasser 50 caractères";
81
			$err_titre_page_egalite = "Cette titre de page est déjà présent en base de données, merci d'en choisir un autre pour ne pas avoir de conflit dans votre navigation";
82
			$this->err_titre_page = $this->getVerifChamp("page", "ID_page", "titre", $titre_page, 50, $err_titre_page_char, $err_titre_page_egalite, $id_page);
83
		}
84
		
85
		/**
86
		 * @param $balise_title
87
		 * @param $url
88
		 * @param $meta_description
89
		 * @param $titre_page
90
		 * @param null $id_page
91
		 */
92
		private function getTestParam($balise_title, $url, $meta_description, $titre_page, $id_page = null) {
93
			$this->getTestBaliseTitle($balise_title, $id_page);
94
			$this->getTestUrl($url, $id_page);
95
			$this->getTestMetaDescription($meta_description, $id_page);
96
			$this->getTestTitrePage($titre_page, $id_page);
97
		}
98
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
99
		
100
		
101
		//-------------------------- SETTER ----------------------------------------------------------------------------//
102
		/**
103
		 * @param string $url
0 ignored issues
show
Bug introduced by
There is no parameter named $url. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
104
		 * @param string $err_balise_title
0 ignored issues
show
Bug introduced by
There is no parameter named $err_balise_title. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
105
		 * @param string $err_url
0 ignored issues
show
Bug introduced by
There is no parameter named $err_url. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
106
		 * @param string $err_meta_description
0 ignored issues
show
Bug introduced by
There is no parameter named $err_meta_description. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
107
		 * @param string $err_titre_page
0 ignored issues
show
Bug introduced by
There is no parameter named $err_titre_page. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
108
		 */
109
		private function setErreurContenus() {
110
			$_SESSION['balise_title'] = $this->balise_title;
0 ignored issues
show
Bug introduced by
The property balise_title does not seem to exist. Did you mean err_balise_title?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
111
			$_SESSION['url'] = $this->url;
0 ignored issues
show
Bug introduced by
The property url does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
112
			$_SESSION['meta_description'] = $this->meta_description;
0 ignored issues
show
Bug introduced by
The property meta_description does not seem to exist. Did you mean err_meta_description?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
113
			$_SESSION['titre_page'] = $this->titre_page;
0 ignored issues
show
Bug introduced by
The property titre_page does not seem to exist. Did you mean err_titre_page?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
114
			$_SESSION['parent'] = $this->parent;
0 ignored issues
show
Bug introduced by
The property parent does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
115
			$_SESSION['err_modification_contenu'] = true;
116
			
117
			$message = "<ul>".$this->err_balise_title.$this->err_url.$this->err_meta_description.$this->err_titre_page."</ul>";
118
			FlashMessage::setFlash($message);
119
		}
120
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
121
	}