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

UsesCsv::generateCsv()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 2
nop 2
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 Illuminate\Support\Str;
7
8
trait UsesCsv
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait UsesCsv
Loading history...
9
{
10
11
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
12
     * @param array|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...
13
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
14
     */
15 7
    public function getHeaders($items)
16
    {
17 7
        $headers = [];
18 7
        foreach($items as $item) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
19 7
            foreach($item->getColumnNames() as $column) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
20 7
                if(!in_array($column, $headers)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
21 7
                    $headers[] = $column;
22
                }
23
            }
24
        }
25 7
        return $headers;
26
    }
27
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @param array|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...
30
     * @param null $headers
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $headers 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 18 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
31
     * @param $defaultIfNull
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...
32
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
33
     */
34 7
    public function getRows($items, $headers = null, $defaultIfNull = null)
35
    {
36 7
        $headers = $headers ?? $this->getHeaders($items);
37
        
38 7
        $rows = [];
39 7
        foreach($items as $item) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
40 7
            $row = [];
41 7
            foreach($headers as $header) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
42 7
                $row[] = $item->getItem($header, $defaultIfNull);
43
            }
44 7
            $rows[] = $row;
45
        }
46
        
47 7
        return $rows;
48
    }
49
50 4
    public function generateCsv($items, $defaultIfNull = null)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function generateCsv()
Loading history...
51
    {
52 4
        $csv = tmpfile();
53
54 4
        $headers = $this->getHeaders($items);
55
        
56 4
        fputcsv($csv, $this->getHeaders($items));
0 ignored issues
show
Bug introduced by
It seems like $csv can also be of type false; however, parameter $handle of fputcsv() does only seem to accept resource, 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

56
        fputcsv(/** @scrutinizer ignore-type */ $csv, $this->getHeaders($items));
Loading history...
57
58 4
        foreach($this->getRows($items, $headers, $defaultIfNull) as $row) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
59 4
            fputcsv($csv, $row);
60
        }
61
        
62 4
        return $csv;
63
    }
64
    
65
}