Completed
Push — spip-3.0 ( 5d8b58 )
by cam
53:01 queued 42:30
created

etape_3b.php ➔ install_etape_3b_dist()   F

Complexity

Conditions 20
Paths 9320

Size

Total Lines 118
Code Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 78
c 0
b 0
f 0
nc 9320
nop 0
dl 0
loc 118
rs 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2016                                                *
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')) return;
14
15
include_spip('inc/headers');
16
17
function install_etape_3b_dist()
18
{
19
	$login = _request('login');
20
	$email = _request('email');
21
	$nom = _request('nom');
22
	$pass = _request('pass');
23
	$pass_verif = _request('pass_verif');
24
25
	$server_db = defined('_INSTALL_SERVER_DB') ?
26
		_INSTALL_SERVER_DB
27
		: _request('server_db');
28
29
	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI', 6);
30
	if (!defined('_LOGIN_TROP_COURT')) define('_LOGIN_TROP_COURT', 4);
31
32
		if($login) {
33
			$echec = ($pass!=$pass_verif) ?
34
				_T('info_passes_identiques')
35
				: ((strlen($pass)<_PASS_LONGUEUR_MINI) ?
36
					_T('info_passe_trop_court_car_pluriel', array('nb'=>_PASS_LONGUEUR_MINI))
37
					: ((strlen($login)<_LOGIN_TROP_COURT) ?
38
						_T('info_login_trop_court')
39
						: ''));
40
		include_spip('inc/filtres');
41
		if (!$echec AND $email AND !email_valide($email))
42
			$echec = _T('form_email_non_valide');
43
		if ($echec) {
44
			echo minipres(
45
			'AUTO',
46
			info_progression_etape(3,'etape_','install/', true).
47
			"<div class='error'><h3>$echec</h3>\n".
48
			"<p>"._T('avis_connexion_echec_2')."</p>".
49
			"</div>"
50
			);
51
			exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function install_etape_3b_dist() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
52
		}
53
	}
54
55
	if (@file_exists(_FILE_CHMOD_TMP))
56
		include(_FILE_CHMOD_TMP);
57
	else
58
		redirige_url_ecrire('install');
59
60
	if (!@file_exists(_FILE_CONNECT_TMP))
61
		redirige_url_ecrire('install');
62
63
	# maintenant on connait le vrai charset du site s'il est deja configure
64
	# sinon par defaut lire_meta reglera _DEFAULT_CHARSET
65
	# (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET)
66
67
	lire_metas();
68
	if ($login) {
69
		include_spip('inc/charsets');
70
71
		$nom = (importer_charset($nom, _DEFAULT_CHARSET));
72
		$login = (importer_charset($login, _DEFAULT_CHARSET));
73
		$email = (importer_charset($email, _DEFAULT_CHARSET));
74
		# pour le passwd, bizarrement il faut le convertir comme s'il avait
75
		# ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js
76
		$pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1');
77
		include_spip('auth/sha256.inc');
78
		include_spip('inc/acces');
79
		$htpass = generer_htpass($pass);
80
		$alea_actuel = creer_uniqid();
81
		$alea_futur = creer_uniqid();
82
		$shapass = _nano_sha256($alea_actuel.$pass);
83
		// prelablement, creer le champ webmestre si il n'existe pas (install neuve
84
		// sur une vieille base
85
		$t = sql_showtable("spip_auteurs", true);
86
		if (!isset($t['field']['webmestre']))
87
			@sql_alter("TABLE spip_auteurs ADD webmestre varchar(3)  DEFAULT 'non' NOT NULL");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
88
89
		$id_auteur = sql_getfetsel("id_auteur", "spip_auteurs", "login=" . sql_quote($login));
90
		if ($id_auteur !== NULL) {
91
			sql_updateq('spip_auteurs', array("nom"=> $nom, 'email'=> $email, 'login'=>$login, 'pass'=>$shapass, 'alea_actuel'=>$alea_actuel, 'alea_futur'=> $alea_futur, 'htpass'=>$htpass, 'statut'=>'0minirezo'), "id_auteur=$id_auteur");
92
		}
93
		else {
94
			$id_auteur = sql_insertq('spip_auteurs', array(
95
				'nom' => $nom,
96
				'email' => $email,
97
				'login' => $login,
98
				'pass' => $shapass,
99
				'htpass' => $htpass,
100
				'alea_actuel' => $alea_actuel,
101
				'alea_futur' => $alea_futur,
102
				'statut' =>'0minirezo'));
103
		}
104
		// le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne
105
		@sql_updateq('spip_auteurs', array('webmestre' => 'oui'), "id_auteur=$id_auteur");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
106
107
		// inserer email comme email webmaster principal
108
		// (sauf s'il est vide: cas de la re-installation)
109
		if ($email)
0 ignored issues
show
Bug Best Practice introduced by
The expression $email of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
110
			ecrire_meta('email_webmaster', $email);
111
112
		// Connecter directement celui qui vient de (re)donner son login
113
		// mais sans cookie d'admin ni connexion longue
114
		include_spip('inc/auth');
115
		if (!$auteur = auth_identifier_login($login, $pass)
116
		OR !auth_loger($auteur, true))
0 ignored issues
show
Bug introduced by
It seems like $auteur defined by auth_identifier_login($login, $pass) on line 115 can also be of type string; however, auth_loger() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Unused Code introduced by
The call to auth_loger() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
117
			spip_log("login automatique impossible $auth_spip $session" . count($row));
0 ignored issues
show
Bug introduced by
The variable $auth_spip does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $session does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $row does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
118
	}
119
120
	// installer les metas
121
	$config = charger_fonction('config', 'inc');
122
	$config();
123
124
	// activer les plugins
125
	// leur installation ne peut pas se faire sur le meme hit, il faudra donc
126
	// poursuivre au hit suivant
127
	include_spip('inc/plugin');
128
	actualise_plugins_actifs();
129
130
131
	include_spip('inc/distant');
132
	redirige_par_entete(parametre_url(self(),'etape','4','&'));
133
	
134
}
135
136
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
137