Completed
Push — master ( e5ef44...29e0f1 )
by Auke
18s
created

loader.cmd.php ➔ ldSetCredentials()   C

Complexity

Conditions 11
Paths 29

Size

Total Lines 2
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132
Metric Value
cc 11
eloc 42
nc 29
nop 2
dl 0
loc 2
rs 5.2653
ccs 0
cts 1
cp 0
crap 132

How to fix   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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 48 and the first side effect is on line 38.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
    /******************************************************************
3
     loader.cmd.php                                        Muze Ariadne
4
     ------------------------------------------------------------------
5
     Author: Muze ([email protected])
6
     Date: 11 december 2002
7
8
     Copyright 2002 Muze
9
10
     This file is part of Ariadne.
11
12
     Ariadne is free software; you can redistribute it and/or modify
13
     it under the terms of the GNU General Public License as published
14
     by the Free Software Foundation; either version 2 of the License,
15
     or (at your option) any later version.
16
17
     Ariadne is distributed in the hope that it will be useful,
18
     but WITHOUT ANY WARRANTY; without even the implied warranty of
19
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
     GNU General Public License for more details.
21
22
     You should have received a copy of the GNU General Public License
23
     along with Ariadne; if not, write to the Free Software
24
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25
     02111-1307  USA
26
27
    -------------------------------------------------------------------
28
29
     Description:
30
31
	Contains all loader functions for the commandline interface
32
	to Ariadne.
33
34
    ******************************************************************/
35
36
	// compatibility with loaders in the bin directory which where not yet updated
37
	if( ! defined('AriadneBasePath') ){
38
		global $ariadne;
39
		$ARLoader = 'cmd';
40
		trigger_error('bootstrap.php not included, please update your loader',E_USER_DEPRECATED);
41
		require_once($ariadne."/bootstrap.php");
42
	}
43
44
	$DB["method"]["loader"] = false;
45
	$DB["method"]["file"] = true;
46
	$DB["file"] = "php://stderr";
47
48
	function error($text) {
49
		debug("Error: $text");
50
	}
51
52
	function ldRegisterFile($field = "file", &$error) {
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
53
	global $ARnls, $store, $ldCmd_files;
54
		debug("ldRegisterFile([$field], [error])");
55
56
		require_once($store->get_config("code")."modules/mod_mimemagic.php");
57
58
		$result = Array();
59
		$file_data = $ldCmd_files[$field];
60
		if ($file_data) {
61
				$file_temp = tempnam($store->get_config("files")."temp", "upload");
62
				$fp = fopen($file_temp, "wb+");
63 View Code Duplication
				if (!$fp) {
64
					$error = "could not write file '$field'";
65
				} else {
66
					debug("	file_data (".$file_data.")");
67
					fwrite($fp, $file_data, strlen($file_data));
68
					fclose($fp);
69
70
					$file_type = get_mime_type($file_temp);
71
72
					$result[$field] = $field;
73
					$result[$field."_temp"] = basename($file_temp);
74
					$result[$field."_size"] = filesize($file_temp);
75
					$result[$field."_type"] = $file_type;
76
					debug(" http_post_vars (".serialize($result).")");
77
				}
78
		}
79
		debug("ldRegisterFile[end] ($result)");
80
		return $result;
81
	}
82
83
	function ldAccessDenied($path, $message) {
0 ignored issues
show
Unused Code introduced by
The parameter $path 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...
84
	global $ARCurrent;
85
		if (!$ARCurrent->arLoginSilent) {
86
			echo "\n($path) $message\n";
87
		}
88
	}
89
90
	function ldSetRoot($session='', $nls='') {
0 ignored issues
show
Unused Code introduced by
The parameter $session 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...
Unused Code introduced by
The parameter $nls 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...
91
		// dummy function
92
	}
93
94
	function ldSetNls($nls) {
0 ignored issues
show
Unused Code introduced by
The parameter $nls 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...
95
		// dummy function
96
	}
97
98
	function ldSetSession($session='') {
0 ignored issues
show
Unused Code introduced by
The parameter $session 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...
99
		// dummy function
100
	}
101
102
	function ldStartSession($sessionid='') {
0 ignored issues
show
Unused Code introduced by
The parameter $sessionid 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...
103
		// dummy function
104
	}
105
106
	function ldSetCache($file, $time, $image, $headers) {
0 ignored issues
show
Unused Code introduced by
The parameter $file 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...
Unused Code introduced by
The parameter $time 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...
Unused Code introduced by
The parameter $image 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...
Unused Code introduced by
The parameter $headers 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...
107
		// dummy function
108
	}
109
110
	function ldGetRequestedHost() {
111
		// dummy function
112 48
	}
113
114
	function ldGetUserCookie($cookiename="ARUserCookie") {
0 ignored issues
show
Unused Code introduced by
The parameter $cookiename 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...
115
		$cookie = false;
116
		return $cookie;
117
	}
118
119
	function ldSetUserCookie($cookie, $cookiename="ARUserCookie", $expire=null, $path="/", $domain="", $secure=0) {
0 ignored issues
show
Unused Code introduced by
The parameter $cookie 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...
Unused Code introduced by
The parameter $cookiename 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...
Unused Code introduced by
The parameter $expire 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...
Unused Code introduced by
The parameter $path 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...
Unused Code introduced by
The parameter $domain 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...
Unused Code introduced by
The parameter $secure 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...
120
		$result = false;
121
		return $result;
122
	}
123
124
	function ldGetCredentials() {
125
	}
126
127
	function ldSetCredentials($login, $password) {
0 ignored issues
show
Unused Code introduced by
The parameter $login 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...
Unused Code introduced by
The parameter $password 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...
128
	}
129
130
	function ldCheckCredentials($login, $password) {
0 ignored issues
show
Unused Code introduced by
The parameter $login 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...
Unused Code introduced by
The parameter $password 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...
131
	}
132
133
	function ldRedirect($uri) {
0 ignored issues
show
Unused Code introduced by
The parameter $uri 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...
134
	}
135
136
	function ldHeader($header) {
0 ignored issues
show
Unused Code introduced by
The parameter $header 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...
137 4
	}
138
139
	function ldSetClientCache($cache_on, $expires=0, $modified=0) {
0 ignored issues
show
Unused Code introduced by
The parameter $cache_on 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...
Unused Code introduced by
The parameter $expires 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...
Unused Code introduced by
The parameter $modified 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...
140 60
		return true;
141
	}
142
143
	function ldSetContent($mimetype, $size=0) {
0 ignored issues
show
Unused Code introduced by
The parameter $mimetype 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...
Unused Code introduced by
The parameter $size 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...
144 4
		return true;
145
	}
146
147
	function ldGetServerVar($server_var = "") {
0 ignored issues
show
Unused Code introduced by
The parameter $server_var 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...
148
		// dummy function
149 4
		return false;
150
	}
151
152
	function ldGetClientVar($client_var) {
0 ignored issues
show
Unused Code introduced by
The parameter $client_var 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...
153
		// dummy function
154
		return false;
155
	}
156
157
	function ldObjectNotFound($requestedpath, $requestedtemplate) {
158
		echo "NOT FOUND: [".$requestedpath."][".$requestedtemplate."]";
159
	}
160
161
	function ldParseOption($cmd) {
162
		$result = false;
163
		if (strpos($cmd, "--") === 0) {
164
			$result = array ('cmd' => $cmd);
165
			$option_switch=substr($cmd, 2);
166
167 View Code Duplication
			if (strpos($option_switch,'=') !== false) {
168
				$result['value'] = substr($option_switch, strpos($option_switch, "=")+1);
169
				$option_switch=substr($option_switch,0,strpos($option_switch, "="));
170
			}
171
172 View Code Duplication
			if (strpos($option_switch,"-")!==false) {
173
				$result['subswitch'] = substr($option_switch, strpos($option_switch,"-")+1);
174
				$option_switch=substr($option_switch, 0, strpos($option_switch,"-"));
175
			}
176
			$result['switch'] = $option_switch;
177
		}
178
		return $result;
179
	}
180
181
	function ldDisablePostProcessing() {
182
		// dummy function
183
		return false;
184
	}
185