Conditions | 10 |
Paths | 7 |
Total Lines | 74 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
42 | public function processHello(array $args) |
||
43 | { |
||
44 | debug($args); |
||
45 | $helloMsg = array_shift($args); |
||
46 | $sessionInfo = array_shift($args); |
||
47 | |||
48 | if (!is_array($helloMsg)) { |
||
49 | return ["ERROR"]; |
||
50 | } |
||
51 | |||
52 | if (!is_object($sessionInfo)) { |
||
53 | return ["ERROR"]; |
||
54 | } |
||
55 | |||
56 | $helloMsg = Message::createMessageFromArray($helloMsg); |
||
57 | |||
58 | if (!$helloMsg instanceof HelloMessage |
||
59 | || !$sessionInfo |
||
60 | || !isset($helloMsg->getDetails()->authid) |
||
61 | || !$this->getUserDb() instanceof WampCraUserDbInterface |
||
62 | ) { |
||
63 | return ["ERROR"]; |
||
64 | } |
||
65 | |||
66 | $authid = $helloMsg->getDetails()->authid; |
||
67 | $user = $this->getUserDb()->get($authid); |
||
68 | |||
69 | if (!$user) { |
||
70 | return ["FAILURE"]; |
||
71 | } |
||
72 | |||
73 | // create a challenge |
||
74 | $nonce = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)); |
||
75 | $authRole = "user"; |
||
76 | $authMethod = "wampcra"; |
||
77 | $authProvider = "userdb"; |
||
78 | $now = new \DateTime(); |
||
79 | $timeStamp = $now->format($now::ISO8601); |
||
80 | if (!isset($sessionInfo->sessionId)) { |
||
81 | return ["ERROR"]; |
||
82 | } |
||
83 | $sessionId = $sessionInfo->sessionId; |
||
84 | |||
85 | $challenge = [ |
||
86 | "authid" => $authid, |
||
87 | "authrole" => $authRole, |
||
88 | "authprovider" => $authProvider, |
||
89 | "authmethod" => $authMethod, |
||
90 | "nonce" => $nonce, |
||
91 | "timestamp" => $timeStamp, |
||
92 | "session" => $sessionId |
||
93 | ]; |
||
94 | |||
95 | $serializedChallenge = json_encode($challenge); |
||
96 | |||
97 | $challengeDetails = [ |
||
98 | "challenge" => $serializedChallenge, |
||
99 | "challenge_method" => $this->getMethodName() |
||
100 | ]; |
||
101 | |||
102 | if ($user['salt'] !== null) { |
||
103 | // we are using salty password |
||
104 | $saltInfo = [ |
||
105 | "salt" => $user['salt'], |
||
106 | "keylen" => 32, |
||
107 | "iterations" => 1000 |
||
108 | ]; |
||
109 | |||
110 | $challengeDetails = array_merge($challengeDetails, $saltInfo); |
||
111 | } |
||
112 | |||
113 | return ["CHALLENGE", (object)$challengeDetails]; |
||
114 | |||
115 | } |
||
116 | |||
161 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.