Completed
Pull Request — master (#113)
by Robbert
08:44
created

rcas::setUser()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 45
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20
Metric Value
dl 0
loc 45
ccs 0
cts 36
cp 0
rs 8.5806
cc 4
eloc 33
nc 2
nop 2
crap 20
1
<?php
2
	class rcas {
3
4
		function getUser($prefix) {
5
		global $AR;
6
			if (substr($AR->user->data->login, 0, strlen($prefix)) == $prefix) {
7
				return $AR->user;
8
			} else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
9
			}
10
		}
11
12
	 	function setUser($login, $userInfo = Array()) {
13
		global $AR, $store;
14
			pobject::pushContext(Array("scope" => "php"));
15
			$result = mod_auth_default::getUser($login, $this->config["ar:userDir"]);
16
			if ($result === LD_ERR_ACCESS) {
17
				$aLogin     = 'admin'; // FIXME: make this configurable
0 ignored issues
show
Coding Style introduced by
Comment refers to a FIXME task "make this configurable"
Loading history...
18
19
				$AR->user   = current($store->call("system.get.phtml", "", $store->find("/system/users/", "login.value='$aLogin' and object.implements='puser'")));
20
21
				$user_dir   = $this->config["ar:userDir"];
22
				$user_profile = $this->config["ar:userProfile"];
23
24
				$data = Array();
25
				$data["arNewFilename"] = "$user_dir$login/";
26
27
				$data["name"] = $login;
28
				$data["newpass1"] = '!',
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ','
Loading history...
29
				$data["newpass2"] = '!',
30
				$data["profile"] = $user_profile;
31
				$data["setowner"] = true;
32
				$data["email"] = $userInfo["email"];
33
34
				foreach ($userInfo as $key => $value) {
35
					$data["custom"]["none"][$key] = $value;
36
				}
37
38
				$userType = $this->config["ar:userType"] ? $this->config["ar:userType"] : "puser";
39
40
				$user = $store->newobject(
41
							"$user_dir$login/",
42
							"$user_dir",
43
							$userType,
44
							new object);
45
46
				$user->arIsNewObject = true;
47
				$user->call('system.save.data.phtml', $data);
48
				$AR->user = $user;
49
			}
50
			ldSetCredentials($login, $this->config["ar:userDir"]);
51
			// unbecome system user
52
			pobject::popContext();
53
			return $AR->user;
54
		}
55
56
	}
57
58
	class pinp_rcas {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
59
60
		function _init($module, $config = Array()) {
61
			global $ariadne;
62
			require_once($ariadne.'/modules/mod_rcas/'.basename($module).".php");
63
			$className = "rcas_$module";
64
			return new $className($config);
65
		}
66
67
	}
68