Toolbox   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getGenerator() 0 12 1
A unborkPreviewUrl() 0 20 3
1
<?php
2
3
namespace smtech\SeeAllSubmissions;
4
5
use smtech\LTI\Configuration\Option;
6
use Battis\HierarchicalSimpleCache;
7
8
/**
9
 * See All Submissions toolbox
10
 *
11
 * Adds some common, useful methods to the St. Mark's-styled
12
 * ReflexiveCanvasLTI Toolbox
13
 *
14
 * @author  Seth Battis <[email protected]>
15
 */
16
class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox
17
{
18
19
    /**
20
     * Configure course and account navigation placements
21
     *
22
     * @return Generator
23
     */
24
    public function getGenerator()
25
    {
26
        parent::getGenerator();
27
28
        $this->generator->setOptionProperty(
29
            Option::COURSE_NAVIGATION(),
30
            'visibility',
31
            'members'
32
        );
33
34
        return $this->generator;
35
    }
36
37
    /**
38
     * This is a quasi temporary "unborking" while a few support tickets are
39
     * working through the queue. See the fix-me notations below.
40
     *
41
     * @param string $previewUrl
42
     * @return string
43
     */
44
    public function unborkPreviewUrl($previewUrl)
0 ignored issues
show
Coding Style introduced by
unborkPreviewUrl uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
45
    {
46
        if (!preg_match('%^https?://.*%', $previewUrl)) {
47
            /*
48
             * FIXME: per [case 01584858 ](https://cases.canvaslms.com/CommunityConsole?id=500A000000UPwauIAD)
49
             * attachments are not well-documented and the Crocodoc attachments
50
             * include an incomplete preview URL that works… but not in an IFRAME
51
             */
52
            return $_SESSION[CANVAS_INSTANCE_URL] . $previewUrl;
53
        } elseif (preg_match('%^(.*version=)(\d+)(.*)$%', $previewUrl, $match)) {
54
            /*
55
             * FIXME: per [case 01584819](https://cases.canvaslms.com/CommunityConsole?id=500A000000UPwSlIAL)
56
             * preview URLs are generated "off by one" and are really zero-indexed.
57
             */
58
            return $match[1] . ($match[2] - 1) . $match[3];
59
        } else {
60
            /* whatevs, it is what it is… */
61
            return $previewUrl;
62
        }
63
    }
64
}
65