Conditions | 5 |
Paths | 7 |
Total Lines | 53 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
Bugs | 0 | Features | 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 |
||
13 | public function onLaunch() { |
||
14 | global $metadata; // FIXME:0 grown-ups don't program like this issue:17 |
||
15 | global $sql; // FIXME:0 grown-ups don't program like this issue:17 |
||
16 | |||
17 | /* is this user in a role that can use this app? */ |
||
18 | if ($this->user->isAdmin()) { |
||
19 | |||
20 | /* set up any needed session variables */ |
||
21 | $_SESSION['consumer_key'] = $this->consumer->getKey(); |
||
22 | $_SESSION['resource_id'] = $this->resource_link->getId(); |
||
23 | $_SESSION['user_consumer_key'] = $this->user->getResourceLink()->getConsumer()->getKey(); |
||
24 | $_SESSION['user_id'] = $this->user->getId(); |
||
25 | $_SESSION['isStudent'] = $this->user->isLearner(); |
||
26 | $_SESSION['isContentItem'] = FALSE; |
||
27 | |||
28 | /* do we have an admin API access token? */ |
||
29 | $haveToken = true; |
||
30 | if (empty($metadata['CANVAS_API_TOKEN'])) { |
||
31 | |||
32 | /* ...if not, do we have a user API access token for this user? */ |
||
33 | $userToken = new UserAPIToken($_SESSION['user_consumer_key'], $_SESSION['user_id'], $sql); |
||
34 | if (empty($userToken->getToken())) { |
||
35 | |||
36 | /* ...if this user has no token, let's start by getting one */ |
||
37 | $haveToken = false; |
||
38 | $this->redirectURL = "{$metadata['APP_URL']}/lti/token_request.php?oauth=request"; |
||
39 | } else { |
||
40 | |||
41 | /* ...but if the user does have a token, rock on! */ |
||
42 | $_SESSION['isUserToken'] = true; |
||
43 | $_SESSION['apiToken'] = $userToken->getToken(); |
||
44 | //$_SESSION['apiUrl'] = $userToken->getAPIUrl(); |
||
45 | } |
||
46 | } else { |
||
47 | |||
48 | /* ...if we have an admin API token, rock on! */ |
||
49 | $_SESSION['isUserToken'] = false; |
||
50 | $_SESSION['apiToken'] = $metadata['CANVAS_API_TOKEN']; |
||
51 | //$_SESSION['apiUrl'] = $metadata['CANVAS_API_URL']; |
||
52 | } |
||
53 | $_SESSION['apiUrl'] = 'https://' . $this->user->getResourceLink()->settings['custom_canvas_api_domain'] . '/api/v1'; |
||
54 | |||
55 | /* pass control off to the app */ |
||
56 | if ($haveToken) { |
||
57 | $this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=launch"; |
||
58 | } |
||
59 | |||
60 | /* ...otherwise set an appropriate error message and fail */ |
||
61 | } else { |
||
62 | $this->reason = 'Invalid role'; |
||
63 | $this->isOK = false; |
||
64 | } |
||
65 | } |
||
66 | |||
116 | ?> |
||
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.