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.

SortByColumn::format()   B
last analyzed

Complexity

Conditions 11
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 11.6653

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 25
ccs 14
cts 17
cp 0.8235
rs 7.3166
cc 11
nc 1
nop 1
crap 11.6653

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace BristolSU\ControlDB\Export\Formatter\Shared;
4
5
use BristolSU\ControlDB\Export\FormattedItem;
6
use BristolSU\ControlDB\Export\Formatter\Formatter;
7
8
class SortByColumn extends Formatter
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SortByColumn
Loading history...
9
{
10
11 3
    public function format($items)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function format()
Loading history...
12
    {
13 3
        $column = $this->config('column', 'id');
14
        
15
        usort($items, function($a, $b) use ($column) {
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...
16 3
            $aVal = $a->getItem($column);
17 3
            $bVal = $b->getItem($column);
18 3
            if(is_null($aVal) && is_null($bVal)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
19
                return 0;
20
            }
21 3
            if(is_null($aVal) && !is_null($bVal)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
22
                return 1;
23
            }
24 3
            if(!is_null($aVal) && is_null($bVal)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
25 1
                return -1;
26
            }
27 3
            if(is_string($aVal) || is_string($bVal)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
28 1
                return $this->compareStrings($aVal, $bVal);
29
            }
30 2
            if(is_int($aVal) || is_int($bVal)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
31 2
                return $this->compareInts($aVal, $bVal);
32
            }
33
            return 0;
34 3
        });
0 ignored issues
show
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...
35 3
        return $items;
36
    }
37
    
38 1
    private function compareStrings(string $a, string $b): int 
0 ignored issues
show
Coding Style introduced by
Private method name "SortByColumn::compareStrings" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function compareStrings()
Loading history...
39
    {
40 1
        return strcmp($a, $b);
41
    }
42
43 2
    public function compareInts(int $a, int $b): int
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function compareInts()
Loading history...
44
    {
45 2
        if ($a == $b) {
46
            return 0;
47
        }
48 2
        return ($a < $b) ? -1 : 1;
49
    }
50
 
51
    public function formatItem(FormattedItem $formattedItem): FormattedItem
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function formatItem()
Loading history...
52
    {
53
        return $formattedItem;
54
    }
55
56
    public function handles(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function handles()
Loading history...
57
    {
58
        return static::ALL;
59
    }
60
}