Completed
Push — master ( df80f0...840f28 )
by Rafal
11s
created

Points   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 17 3
A checkCollection() 0 5 3
1
<?php
2
3
4
namespace App\GameBetting\Business\GamePoints;
5
6
7
use App\GameBetting\Business\GamePoints\Score\ScoreInterface;
8
use App\GameBetting\Persistence\DataProvider\Result;
9
10
class Points implements PointsInterface
11
{
12
    /**
13
     * @var ScoreInterface
14
     */
15
    private $collections;
16
17
    /**
18
     * @param ScoreInterface[] $collections
19
     */
20
    public function __construct(...$collections)
21
    {
22
        $this->collections = $collections;
0 ignored issues
show
Documentation Bug introduced by
It seems like $collections of type array<integer,App\GameBe...s\Score\ScoreInterface> is incompatible with the declared type App\GameBetting\Business...ts\Score\ScoreInterface of property $collections.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
    }
24
25
    /**
26
     * @param Result $result
27
     * @return int
28
     */
29
    public function get(Result $result): int
30
    {
31
        $this->checkCollection();
32
33
        usort($this->collections, function ($a, $b) {
0 ignored issues
show
Bug introduced by
$this->collections of type App\GameBetting\Business...ts\Score\ScoreInterface is incompatible with the type array expected by parameter $array of usort(). ( Ignorable by Annotation )

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

33
        usort(/** @scrutinizer ignore-type */ $this->collections, function ($a, $b) {
Loading history...
34
            return $a->getScore() <=> $b->getScore();
35
        });
36
        $this->collections = array_reverse($this->collections);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_reverse($this->collections) of type array is incompatible with the declared type App\GameBetting\Business...ts\Score\ScoreInterface of property $collections.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
38
        foreach ($this->collections as $collection) {
39
            if ($collection->check($result) === true) {
40
                $score = $collection->getScore();
41
                break;
42
            }
43
        }
44
45
        return $score;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $score does not seem to be defined for all execution paths leading up to this point.
Loading history...
46
    }
47
48
49
    private function checkCollection()
50
    {
51
        foreach ($this->collections as $collection) {
52
            if (!$collection instanceof ScoreInterface) {
53
                throw new \RuntimeException('Collection: ' . get_class($collection) . 'is not instanceof ' . ScoreInterface::class);
54
            }
55
        }
56
    }
57
58
59
}