GameRepository::allWith()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Gameap\Repositories;
4
5
use Gameap\Models\Game;
6
use Gameap\Models\GameMod;
7
use Gameap\Services\GlobalApi;
8
9
class GameRepository extends Repository
10
{
11
    public function __construct(Game $game)
12
    {
13
        $this->model = $game;
14
    }
15
16
    /**
17
     * @param int $perPage
18
     * @return mixed
19
     */
20
    public function getAll($perPage = 20)
21
    {
22
        return Game::orderBy('name')->paginate($perPage);
23
    }
24
25
    /**
26
     * @param string|array $with
27
     * @param int $perPage
28
     * @return mixed
29
     */
30
    public function allWith($with, $perPage = 50)
31
    {
32
        return Game::orderBy('name')->with($with)->paginate($perPage);
33
    }
34
35
    /**
36
     * Upgrade Games and Game Mods using GameAP API
37
     */
38
    public function upgradeFromRepo()
39
    {
40
        $apiGames = GlobalApi::games();
41
42
        foreach ($apiGames as $gameData) {
43
            $game = Game::find($gameData['code']) ?? new Game();
44
45
            $game->fill($gameData);
0 ignored issues
show
Bug introduced by
The method fill() does not exist on null. ( Ignorable by Annotation )

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

45
            $game->/** @scrutinizer ignore-call */ 
46
                   fill($gameData);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
47
            if (!$game->save()) {
48
                return false;
49
            }
50
51
            if (!empty($gameData['mods'])) {
52
                foreach ($gameData['mods'] as $gameModData) {
53
                    $gameMod = GameMod::firstOrCreate([
54
                        'name'      => $gameModData['name'],
55
                        'game_code' => $gameData['code'],
56
                    ]);
57
58
                    $gameMod->fill($gameModData);
59
                    $gameMod->save();
60
                }
61
            }
62
        }
63
64
        return true;
65
    }
66
}
67