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 ( 9556d0...69e188 )
by William
02:37
created

Negotiator::match()   C

Complexity

Conditions 23
Paths 6

Size

Total Lines 55
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 32
CRAP Score 23.0147

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 32
cts 33
cp 0.9697
rs 6.5378
c 0
b 0
f 0
cc 23
eloc 30
nc 6
nop 3
crap 23.0147

How to fix   Long Method    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
3
namespace Negotiation;
4
5
class Negotiator extends AbstractNegotiator
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10 42
    protected function acceptFactory($accept)
11
    {
12 42
        return new Accept($accept);
13
    }
14
15
    /**
16
     * {@inheritdoc}
17
     */
18 38
    protected function match(AcceptHeader $accept, AcceptHeader $priority, $index)
19
    {
20 38
        if (!$accept instanceof Accept || !$priority instanceof Accept) {
21
            return null;
22
        }
23
24 38
        $acceptBase = $accept->getBasePart();
25 38
        $priorityBase = $priority->getBasePart();
26
27 38
        $acceptSub = $accept->getSubPart();
28 38
        $prioritySub = $priority->getSubPart();
29
30 38
        $intersection = array_intersect_assoc($accept->getParameters(), $priority->getParameters());
31
32 38
        $baseEqual = !strcasecmp($acceptBase, $priorityBase);
33 38
        $subEqual  = !strcasecmp($acceptSub, $prioritySub);
34
35 38
        if (($acceptBase === '*' || $baseEqual)
36 38
            && ($acceptSub === '*' || $subEqual)
37 38
            && count($intersection) === count($accept->getParameters())
38 38
        ) {
39 31
            $score = 100 * $baseEqual + 10 * $subEqual + count($intersection);
40
41 31
            return new Match($accept->getQuality() * $priority->getQuality(), $score, $index);
42
        }
43
44 37
        if (!strstr($acceptSub, '+') || !strstr($prioritySub, '+')) {
45 37
            return null;
46
        }
47
48
        // Handle "+" segment wildcards
49 7
        list($acceptSub, $acceptPlus) = $this->splitSubPart($acceptSub);
50 7
        list($prioritySub, $priorityPlus) = $this->splitSubPart($prioritySub);
51
52
        // If no wildcards in either the subtype or + segment, do nothing.
53 7
        if (!($acceptBase === '*' || $baseEqual)
54 7
            || !($acceptSub === '*' || $prioritySub === '*' || $acceptPlus === '*' || $priorityPlus === '*')
55 7
        ) {
56 3
            return null;
57
        }
58
59 4
        $subEqual  = !strcasecmp($acceptSub, $prioritySub);
60 4
        $plusEqual = !strcasecmp($acceptPlus, $priorityPlus);
61
62 4
        if (($acceptSub === '*' || $prioritySub === '*' || $subEqual)
63 4
            && ($acceptPlus === '*' || $priorityPlus === '*' || $plusEqual)
64 4
            && count($intersection) === count($accept->getParameters())
65 4
        ) {
66 4
            $score = 100 * $baseEqual + 10 * $subEqual + $plusEqual + count($intersection);
67
68 4
            return new Match($accept->getQuality() * $priority->getQuality(), $score, $index);
69
        }
70
71 1
        return null;
72
    }
73
74
    /**
75
     * Split a subpart into the subpart and "plus" part.
76
     *
77
     * For media-types of the form "application/vnd.example+json", matching
78
     * should allow wildcards for either the portion before the "+" or
79
     * after. This method splits the subpart to allow such matching.
80
     */
81 7
    protected function splitSubPart($subPart)
82
    {
83 7
        if (!strstr($subPart, '+')) {
84
            return [$subPart, ''];
85
        }
86
87 7
        return explode('+', $subPart, 2);
88
    }
89
}
90