Completed
Push — master ( 393727...543190 )
by Vincenzo
03:00
created

MatchSimulator::simulate()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 45
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 45
rs 8.5806
cc 4
eloc 24
nc 3
nop 1
1
<?php
2
3
4
namespace App\Lib\DsManager\Helpers;
5
6
7
use App\Lib\DsManager\Models\Match;
8
use App\Lib\DsManager\Models\Orm\MatchResult;
9
10
/**
11
 * Class MatchSimulator
12
 * @package App\Lib\DsManager\Helpers
13
 */
14
class MatchSimulator
15
{
16
17
    /**
18
     * @param $matchId
19
     * @return mixed
20
     */
21
    public static function simulate($matchId)
22
    {
23
        $result = MatchResult::complete()
24
            ->where(
25
                [
26
                    'id' => $matchId
27
                ]
28
            )->first();
29
30
        if (!empty($result) && !$result->simulated) {
31
            //simulate match
32
            $match = Match::fromArray(
33
                \App\Lib\DsManager\Models\Orm\Match::complete()
0 ignored issues
show
Bug introduced by
The method complete() does not exist on App\Lib\DsManager\Models\Orm\Match. Did you maybe mean scopeComplete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
                    ->where(
35
                        [
36
                            'id' => $matchId
37
                        ]
38
                    )->first()->toArray()
39
            );
40
41
            $matchResult = $match->simulate()->toArray();
42
43
            $result = MatchResult::where(
44
                [
45
                    'id' => $matchId
46
                ]
47
            )->update(
48
                MatchResult::resolveAttributes(
49
                    $matchResult,
50
                    $matchId
51
                )
52
            );
53
            if ($result === 1) {
54
                $result = MatchResult::complete()
55
                    ->where(
56
                        [
57
                            'id' => $matchId
58
                        ]
59
                    )->first();
60
            }
61
62
        }
63
64
        return $result;
65
    }
66
}