Completed
Push — master ( d694f8...872600 )
by cam
04:32 queued 10s
created

format_html.php ➔ format_boucle_html()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 64
nop 10
dl 0
loc 14
rs 8.8333
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2019                                                *
7
 *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
8
 *                                                                         *
9
 *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
10
 *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11
\***************************************************************************/
12
13
if (!defined('_ECRIRE_INC_VERSION')) {
14
	return;
15
}
16
17
function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) {
0 ignored issues
show
Unused Code introduced by
The parameter $prof is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
	$preaff = $preaff ? "<BB$nom>$preaff" : "";
19
	$avant = $avant ? "<B$nom>$avant" : "";
20
	$apres = $apres ? "$apres</B$nom>" : "";
21
	$altern = $altern ? "$altern<//B$nom>" : "";
22
	$postaff = $postaff ? "$postaff</BB$nom>" : "";
23
	if (!$corps) {
24
		$corps = " />";
25
	} else {
26
		$corps = ">$corps</BOUCLE$nom>";
27
	}
28
29
	return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff";
30
}
31
32
function format_inclure_html($file, $args, $prof) {
0 ignored issues
show
Unused Code introduced by
The parameter $prof is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
	if (strpos($file, '#') === false) {
34
		$t = $file ? ("(" . $file . ")") : "";
35
	} else {
36
		$t = "{fond=" . $file . '}';
37
	}
38
	$args = !$args ? '' : ("{" . join(", ", $args) . "}");
39
40
	return ("<INCLURE" . $t . $args . ">");
41
}
42
43
function format_polyglotte_html($args, $prof) {
0 ignored issues
show
Unused Code introduced by
The parameter $prof is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
	$contenu = array();
45
	foreach ($args as $l => $t) {
46
		$contenu[] = ($l ? "[$l]" : '') . $t;
47
	}
48
49
	return ("<multi>" . join(" ", $contenu) . "</multi>");
50
}
51
52
function format_idiome_html($nom, $module, $args, $filtres, $prof) {
0 ignored issues
show
Unused Code introduced by
The parameter $prof is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
	foreach ($args as $k => $v) {
54
		$args[$k] = "$k=$v";
55
	}
56
	$args = (!$args ? '' : ('{' . join(',', $args) . '}'));
57
58
	return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>");
59
}
60
61
function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) {
0 ignored issues
show
Unused Code introduced by
The parameter $prof is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
	$nom = "#"
63
		. ($boucle ? ($boucle . ":") : "")
64
		. $nom
65
		. $etoile
66
		. $args
67
		. $filtres;
68
69
	// Determiner si c'est un champ etendu, 
70
71
	$s = ($avant or $apres or $filtres
72
		or (strpos($args, '(#') !== false));
73
74
	return ($s ? "[$avant($nom)$apres]" : $nom);
75
}
76
77
function format_critere_html($critere) {
78
	foreach ($critere as $k => $crit) {
79
		$crit_s = '';
80
		foreach ($crit as $operande) {
81
			list($type, $valeur) = $operande;
82
			if ($type == 'champ' and $valeur[0] == '[') {
83
				$valeur = substr($valeur, 1, -1);
84
				if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) {
85
					$valeur = substr($valeur, 1, -1);
86
				}
87
			}
88
			$crit_s .= $valeur;
89
		}
90
		$critere[$k] = $crit_s;
91
	}
92
93
	return (!$critere ? "" : ("{" . join(",", $critere) . "}"));
94
}
95
96
function format_liste_html($fonc, $args, $prof) {
0 ignored issues
show
Unused Code introduced by
The parameter $prof is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
	return ((($fonc !== '') ? "|$fonc" : $fonc)
98
		. (!$args ? "" : ("{" . join(",", $args) . "}")));
99
}
100
101
// Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes
102
function format_suite_html($args) {
103
	for ($i = 0; $i < count($args) - 1; $i++) {
104
		list($texte, $type) = $args[$i];
105
		list($texte2, $type2) = $args[$i + 1];
106
		if (!$texte or !$texte2) {
107
			continue;
108
		}
109
		$c1 = substr($texte, -1);
110
		if ($type2 !== 'texte') {
111
			// si un texte se termine par ( et est suivi d'un champ
112
			// ou assimiles, forcer la notation pleine
113
			if ($c1 == '(' and substr($texte2, 0, 1) == '#') {
114
				$args[$i + 1][0] = '[(' . $texte2 . ')]';
115
			}
116
		} else {
117
			if ($type == 'texte') {
118
				continue;
119
			}
120
			// si un champ ou assimiles est suivi d'un texte
121
			// et si celui-ci commence par un caractere de champ
122
			// forcer la notation pleine
123
			if (($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|')
124
				or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2))
125
			) {
126
				$args[$i][0] = '[(' . $texte . ')]';
127
			}
128
		}
129
	}
130
131
	return join("", array_map('array_shift', $args));
132
}
133
134
function format_texte_html($texte) {
135
	return $texte;
136
}
137