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 ( 2c6b6b...9556d0 )
by William
02:47
created

Negotiator::match()   D

Complexity

Conditions 17
Paths 5

Size

Total Lines 48
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 17.0949

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 27
cts 29
cp 0.931
rs 4.9412
c 0
b 0
f 0
cc 17
eloc 27
nc 5
nop 3
crap 17.0949

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