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

MatchSimulator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 53
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B simulate() 0 45 4
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
}