Passed
Push — main ( 0f2e29...68faa1 )
by Leandro
01:32
created

Core   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 2
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCoursesByField() 0 9 2
A getCourses() 0 10 2
1
<?php
2
3
namespace Puerari\Moodle;
4
5
/**
6
 * @trait Account
7
 * @package Puerari\Cwp
8
 * @author Leandro Puerari <[email protected]>
9
 */
10
trait Core
11
{
12
    /**
13
     * @param string $field
14
     * @param string $value
15
     * @return array|string
16
     * @throws MraException
17
     */
18
    public function getCoursesByField(/*string*/ $field, /*string*/ $value)/*: array|string*/
19
    {
20
        $validFields = ['', 'id', 'ids', 'shortname', 'idnumber', 'category'];
21
        if (!in_array($field, $validFields)) {
22
            throw new MraException("Invalid field value: '$field'.\n Valid values: " . implode(', ', $validFields));
23
        }
24
        $this->data = compact('field', 'value');
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
        $this->data['wsfunction'] = 'core_course_get_courses_by_field';
26
        return $this->execGetCurl();
0 ignored issues
show
Bug introduced by
It seems like execGetCurl() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        return $this->/** @scrutinizer ignore-call */ execGetCurl();
Loading history...
27
    }
28
29
    /**
30
     * @param array $ids
31
     * @return array|string
32
     * @throws MraException
33
     */
34
    public function getCourses(array $ids)
35
    {
36
        $this->data = [];
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
        $this->data['wsfunction'] = 'core_course_get_courses';
38
        $cont = 0;
39
        foreach ($ids as $vlr) {
40
            $this->data['options']['ids'][$cont] = intval($vlr);
41
            ++$cont;
42
        }
43
        return $this->execGetCurl();
44
    }
45
}
46