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

Parser::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
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
}