GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 18e39d...348781 )
by Toby
36:48 queued 23:00
created

Handler::prepareItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace BristolSU\ControlDB\Export\Handler;
4
5
use BristolSU\ControlDB\Export\FormattedItem;
6
use BristolSU\ControlDB\Export\Formatter\Formatter;
7
use Illuminate\Support\Collection;
8
9
abstract class Handler
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Handler
Loading history...
10
{
11
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
12
     * @var array
13
     */
14
    private $config;
0 ignored issues
show
Coding Style introduced by
Private member variable "config" must be prefixed with an underscore
Loading history...
15
16 13
    public function __construct(array $config)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
17
    {
18 13
        $this->config = $config;
19 13
    }
20
21
    /**
22
     * Prepare items by transforming them to formattable items
23
     * 
24
     * @param $items
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
25
     * @return FormattedItem[]
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
26
     */
27 6
    protected function prepareItems($items)
28
    {
29 6
        $formattedItems = [];
30 6
        foreach($items as $item) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
31 6
            $formattedItems[] = FormattedItem::create($item);
32
        }
33 6
        return $formattedItems;
34
    }
35
    
36 6
    public function export($items = [])
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function export()
Loading history...
37
    {
38 6
        if($items instanceof Collection) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
39 1
            $items = $items->all();
40
        }
41 6
        $formattedItems = $this->prepareItems($items);
42 6
        foreach($this->getFormatters() as $formatter) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
43 5
            $formattedItems = $formatter->format($formattedItems);
44
        }
45 5
        $this->save($formattedItems);
46 5
    }
47
48
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
49
     * @return Formatter[]
50
     */
51 6
    protected function getFormatters()
52
    {
53
        return array_map(function($className) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
54 6
            if(class_exists($className)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
55 5
                return new $className($this->config('formatters')[$className]);
56
            }
57 1
            throw new \Exception(sprintf('Formatter %s does not exist', $className));
58 6
        }, array_keys($this->config('formatters', [])));
0 ignored issues
show
Bug introduced by
It seems like $this->config('formatters', array()) can also be of type null; however, parameter $input of array_keys() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

58
        }, array_keys(/** @scrutinizer ignore-type */ $this->config('formatters', [])));
Loading history...
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
59
    }
60
    
61
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
62
     * @param FormattedItem[] $items
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
63
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
64
     */
65
    abstract protected function save(array $items);
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @param string $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
69
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
70
     * 
71
     * @return mixed|null
72
     */
73 11
    protected function config(string $key, $default = null)
74
    {
75 11
        if(array_key_exists($key, $this->config)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
76 11
            return $this->config[$key];
77
        }
78 3
        return $default;
79
    }
80
}