A001LeaguesSeeder::run()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 42
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 42
rs 8.5806
cc 4
eloc 22
nc 4
nop 0
1
<?php
2
3
4
use App\Lib\DsManager\Helpers\LeagueFixtureGenerator;
5
use App\Lib\DsManager\Models\Orm\League;
6
use App\Lib\DsManager\Models\Orm\LeagueRound;
7
use App\Lib\DsManager\Models\Orm\Match;
8
use App\Lib\DsManager\Models\Orm\Team;
9
10
class A001LeaguesSeeder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    function run()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
13
    {
14
        $leagues = [
15
            'friendly' => 16,
16
            'europa league' => 8
17
        ];
18
        $teams = Team::all()->toArray();
19
        foreach ($leagues as $league => $teamsNum) {
20
21
            $teamCopy = $teams;
22
            $league = League::create(
23
                [
24
                    'name' => $league,
25
                    'teams' => $teamsNum
26
                ]
27
            );
28
29
            //Create Rounds
30
            shuffle($teamCopy);
31
            $teamCopy = array_splice($teamCopy, 0, $teamsNum);
32
            $rounds = LeagueFixtureGenerator::generate($teamCopy);
33
            foreach ($rounds as $i => $round) {
34
35
                $leagueRound = LeagueRound::create(
36
                    [
37
                        'league_id' => $league->id,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lib\DsManager\Models\Orm\League>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
38
                        'day' => $i + 1
39
                    ]
40
                );
41
42
                foreach ($round as $match) {
43
                    $newMatch = Match::create(
0 ignored issues
show
Unused Code introduced by
$newMatch is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
                        [
45
                            'home_team_id' => $match['home_team_id'],
46
                            'away_team_id' => $match['away_team_id'],
47
                            'league_round_id' => $leagueRound->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lib\DsManager\Models\Orm\LeagueRound>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
48
                        ]
49
                    );
50
                }
51
            }
52
        }
53
    }
54
}