Passed
Push — master ( 4d14cc...cd8bbe )
by Rafal
02:57
created

Parser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getGoals() 0 7 2
A get() 0 15 2
1
<?php declare(strict_types=1);
2
3
4
namespace App\GameApi\Business\WorldCupSfgIo\Client;
5
6
7
use App\GameApi\Persistence\DataProvider\GameResult;
8
9
class Parser implements ParserInterface
10
{
11
    /**
12
     * @param array $matchInfos
13
     * @return GameResult[]
14
     */
15
    public function get(array $matchInfos): array
16
    {
17
        $resultGames = [];
18
        foreach ($matchInfos as $matchInfo) {
19
            $homeTeam = $matchInfo['home_team'];
20
            $awayTeam = $matchInfo['away_team'];
21
22
            $resultGames[] = new GameResult(
23
                $homeTeam['country'],
24
                $awayTeam['country'],
25
                $this->getGoals($homeTeam),
26
                $this->getGoals($awayTeam)
27
            );
28
        }
29
        return $resultGames;
30
    }
31
32
    /**
33
     * @param array $team
34
     * @return int
35
     */
36
    private function getGoals(array $team): int
37
    {
38
        $goals = (int)$team['goals'];
39
        if (isset($team['penalties'])) {
40
            $goals += (int)$team['penalties'];
41
        }
42
        return $goals;
43
    }
44
}