Completed
Push — master ( a8f20d...0172d7 )
by Seth
01:51
created

AbstractCourseSearchDomain   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A localizeUrl() 0 12 3
1
<?php
2
3
namespace smtech\StMarksSearch\Canvas\Courses;
4
5
use Exception;
6
use smtech\CanvasPest\CanvasPest;
7
use smtech\StMarksSearch\Canvas\AbstractCanvasSearchDomain;
8
9
/**
10
 * Parent object for Canvas course searches
11
 *
12
 * @author Seth Battis <[email protected]>
13
 */
14
abstract class AbstractCourseSearchDomain extends AbstractCanvasSearchDomain
15
{
16
    /**
17
     * Localize the general Canvas URL to a particular course (if necessary)
18
     *
19
     * Will "localize" the `url` parameter after initialization -- i.e. if the
20
     * URL of the search domain is `https://canvas.instructure.com` and the ID
21
     * is 43, the URL will be localized to
22
     * `https://canvas.instructure.com/courses/43`
23
     *
24
     * @return void
25
     */
26
    protected function localizeUrl()
27
    {
28
        if (!preg_match('%.*/courses/\d+$%', $this->getUrl())) {
29
            $id = $this->getId();
30
            if (!is_numeric($id)) {
31
                $course = $this->getApi()->get("/courses/$id");
32
                assert(isset($course['id']), new Exception("Unknown course `id` parameter: $id"));
33
                $id = $course['id'];
34
            }
35
            $this->setUrl($this->getUrl() . "/courses/{$id}");
36
        }
37
    }
38
}
39