These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | require_once 'common.inc.php'; |
||
4 | |||
5 | use smtech\CanvasHack\Toolbox; |
||
6 | use smtech\ReflexiveCanvasLTI\LTI\ToolProvider; |
||
7 | use smtech\ReflexiveCanvasLTI\Exception\ConfigurationException; |
||
8 | |||
9 | define('ACTION_CONFIG', 'config'); |
||
10 | define('ACTION_INSTALL', 'install'); |
||
11 | define('ACTION_CONSUMERS', 'consumers'); |
||
12 | define('ACTION_UNSPECIFIED', false); |
||
13 | |||
14 | /* store any requested actions for future handling */ |
||
15 | $action = (empty($_REQUEST['action']) ? |
||
16 | ACTION_UNSPECIFIED : |
||
17 | strtolower($_REQUEST['action']) |
||
18 | ); |
||
19 | |||
20 | /* action requests only come from outside the LTI! */ |
||
21 | if ($action) { |
||
22 | unset($_SESSION[ToolProvider::class]); |
||
23 | } |
||
24 | |||
25 | /* authenticate LTI launch request, if present */ |
||
26 | if ($toolbox->lti_isLaunching()) { |
||
27 | $toolbox->resetSession(); |
||
28 | $toolbox->lti_authenticate(); |
||
29 | exit; |
||
30 | } |
||
31 | |||
32 | /* if authenticated LTI launch, head off to app.php */ |
||
33 | if (!empty($_SESSION[ToolProvider::class]['canvas'])) { |
||
34 | header("Location: control-panel.php"); |
||
35 | exit; |
||
36 | |||
37 | /* if not authenticated, default to showing credentials */ |
||
38 | } else { |
||
39 | $action = (empty($action) ? |
||
40 | ACTION_CONFIG : |
||
41 | $action |
||
42 | ); |
||
43 | } |
||
44 | |||
45 | /* process any actions */ |
||
46 | switch ($action) { |
||
47 | /* reset cached install data from config file */ |
||
48 | case ACTION_INSTALL: |
||
49 | $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true); |
||
50 | $toolbox =& $_SESSION['toolbox']; |
||
51 | |||
52 | /* test to see if we can connect to the API */ |
||
53 | try { |
||
54 | $toolbox->getAPI(); |
||
55 | } catch (ConfigurationException $e) { |
||
56 | /* if there isn't an API token in config.xml, are there OAuth credentials? */ |
||
57 | if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) { |
||
58 | $toolbox->interactiveGetAccessToken(); |
||
0 ignored issues
–
show
|
|||
59 | exit; |
||
60 | } else { /* no (understandable) API credentials available -- doh! */ |
||
61 | throw $e; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | /* finish by opening consumers control panel */ |
||
66 | header('Location: consumers.php'); |
||
67 | exit; |
||
68 | |||
69 | /* show LTI configuration XML file */ |
||
70 | case ACTION_CONFIG: |
||
71 | header('Content-type: application/xml'); |
||
72 | echo $toolbox->saveConfigurationXML(); |
||
73 | exit; |
||
74 | } |
||
75 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: