Passed
Push — master ( 24a4a4...d8896b )
by Julien
06:15
created

TreeGen::addParentToChildren()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Xoco70\LaravelTournaments\TreeGen;
4
5
use Illuminate\Support\Collection;
6
use Xoco70\LaravelTournaments\Contracts\TreeGenerable;
7
use Xoco70\LaravelTournaments\Exceptions\TreeGenerationException;
8
use Xoco70\LaravelTournaments\Models\Championship;
9
use Xoco70\LaravelTournaments\Models\Fight;
10
use Xoco70\LaravelTournaments\Models\FightersGroup;
11
12
abstract class TreeGen implements TreeGenerable
13
{
14
    protected $groupBy;
15
    protected $tree;
16
    public $championship;
17
    public $settings;
18
    protected $numFighters;
19
20
    abstract protected function generateAllTrees();
21
22
    abstract protected function generateFights();
23
24
    abstract protected function addFighterToGroup(FightersGroup $group, $fighter, $fighterToUpdate);
25
26
    abstract protected function getByeGroup($fighters);
27
28
    abstract protected function getNumRounds($fightersCount);
29
30
    abstract protected function chunk(Collection $fightersByEntity);
31
32
    abstract protected function syncGroup(FightersGroup $group, $fighters);
33
34
    abstract protected function generateGroupsForRound(Collection $fightersByArea, $round);
35
36
    /**
37
     * @param Championship $championship
38
     * @param $groupBy
39
     */
40
    public function __construct(Championship $championship, $groupBy)
41
    {
42
        $this->championship = $championship;
43
        $this->groupBy = $groupBy;
44
        $this->settings = $championship->getSettings();
45
        $this->tree = new Collection();
46
    }
47
48
    /**
49
     * Generate tree groups for a championship.
50
     *
51
     * @throws TreeGenerationException
52
     */
53
    public function run()
54
    {
55
        $this->championship->fightersGroups()->delete();
56
        $this->generateAllTrees();
57
        $this->generateAllFights();
58
    }
59
60
61
62
    /**
63
     * Get Competitor's list ordered by entities
64
     * Countries for Internation Tournament, State for a National Tournament, etc.
65
     *
66
     * @param $fighters
67
     *
68
     * @return Collection
69
     */
70
    private function getFightersByEntity($fighters): Collection
71
    {
72
        // Right now, we are treating users and teams as equals.
73
        // It doesn't matter right now, because we only need name attribute which is common to both models
74
75
        // $this->groupBy contains federation_id, association_id, club_id, etc.
76
        if (($this->groupBy) != null) {
77
            return $fighters->groupBy($this->groupBy); // Collection of Collection
78
        }
79
80
        return $fighters->chunk(1); // Collection of Collection
81
    }
82
83
    /**
84
     * Get the size the first round will have.
85
     *
86
     * @param $fighterCount
87
     * @param $groupSize
88
     *
89
     * @return int
90
     */
91
    protected function getTreeSize($fighterCount, $groupSize)
92
    {
93
        $squareMultiplied = collect([1, 2, 4, 8, 16, 32, 64])
94
            ->map(function ($item) use ($groupSize) {
95
                return $item * $groupSize;
96
            }); // [4, 8, 16, 32, 64,...]
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
98
        foreach ($squareMultiplied as $limit) {
99
            if ($fighterCount <= $limit) {
100
                $treeSize = $limit;
101
                $numAreas = $this->settings->fightingAreas;
102
                $fighterCountPerArea = $treeSize / $numAreas;
103
                if ($fighterCountPerArea < $groupSize) {
104
                    $treeSize = $treeSize * $numAreas;
105
                }
106
107
                return $treeSize;
108
            }
109
        }
110
111
        return 64 * $groupSize;
112
    }
113
114
115
116
    /**
117
     * @param $order
118
     * @param $round
119
     * @param $parent
120
     *
121
     * @return FightersGroup
122
     */
123
    protected function saveGroup($order, $round, $parent): FightersGroup
124
    {
125
        $group = new FightersGroup();
126
        $this->championship->isSingleEliminationType()
127
            ? $group->area = $this->getNumArea($round, $order)
0 ignored issues
show
Documentation introduced by
The property area does not exist on object<Xoco70\LaravelTou...s\Models\FightersGroup>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
128
            : $group->area = 1; // Area limited to 1 in playoff
0 ignored issues
show
Documentation introduced by
The property area does not exist on object<Xoco70\LaravelTou...s\Models\FightersGroup>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
129
130
        $group->order = $order;
0 ignored issues
show
Documentation introduced by
The property order does not exist on object<Xoco70\LaravelTou...s\Models\FightersGroup>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
131
        $group->round = $round;
0 ignored issues
show
Documentation introduced by
The property round does not exist on object<Xoco70\LaravelTou...s\Models\FightersGroup>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
132
        $group->championship_id = $this->championship->id;
0 ignored issues
show
Documentation introduced by
The property championship_id does not exist on object<Xoco70\LaravelTou...s\Models\FightersGroup>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
Documentation introduced by
The property id does not exist on object<Xoco70\LaravelTou...ts\Models\Championship>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
133
        if ($parent != null) {
134
            $group->parent_id = $parent->id;
0 ignored issues
show
Documentation introduced by
The property parent_id does not exist on object<Xoco70\LaravelTou...s\Models\FightersGroup>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
135
        }
136
        $group->save();
137
138
        return $group;
139
    }
140
141
    /**
142
     * @param int $groupSize
143
     *
144
     * @return Collection
145
     */
146
    public function createByeGroup($groupSize): Collection
147
    {
148
        $byeFighter = $this->createByeFighter();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Xoco70\LaravelTournaments\TreeGen\TreeGen as the method createByeFighter() does only exist in the following sub-classes of Xoco70\LaravelTournaments\TreeGen\TreeGen: Xoco70\LaravelTournament...layOffCompetitorTreeGen, Xoco70\LaravelTournament...eGen\PlayOffTeamTreeGen, Xoco70\LaravelTournament...nationCompetitorTreeGen, Xoco70\LaravelTournament...eEliminationTeamTreeGen. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
149
        $group = new Collection();
150
        for ($i = 0; $i < $groupSize; $i++) {
151
            $group->push($byeFighter);
152
        }
153
154
        return $group;
155
    }
156
157
158
159
    /**
160
     * Get All Groups on previous round.
161
     *
162
     * @param $currentRound
163
     *
164
     * @return Collection
165
     */
166
    private function getPreviousRound($currentRound)
167
    {
168
        $previousRound = $this->championship->groupsByRound($currentRound + 1)->get();
169
170
        return $previousRound;
171
    }
172
173
    /**
174
     * Get the next group on the right ( parent ), final round being the ancestor.
175
     *
176
     * @param $matchNumber
177
     * @param Collection $previousRound
178
     *
179
     * @return mixed
180
     */
181
    private function getParentGroup($matchNumber, $previousRound)
182
    {
183
        $parentIndex = intval(($matchNumber + 1) / 2);
184
        $parent = $previousRound->get($parentIndex - 1);
185
186
        return $parent;
187
    }
188
189
    /**
190
     * Group Fighters by area.
191
     * Here is where we fill with empty fighters
192
     *
193
     * @throws TreeGenerationException
194
     *
195
     * @return Collection
196
     */
197
    protected function getFightersByArea()
198
    {
199
        $areas = $this->settings->fightingAreas;
200
        $fighters = $this->getFighters();   // Get Competitor or Team Objects
0 ignored issues
show
Bug introduced by
The method getFighters() does not exist on Xoco70\LaravelTournaments\TreeGen\TreeGen. Did you maybe mean getFightersByEntity()?

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...
201
        $fighterByEntity = $this->getFightersByEntity($fighters);   // Chunk it by entities (Fede, Assoc, Club,...)
202
        $fightersWithBye = $this->adjustFightersGroupWithByes($fighters, $fighterByEntity);     // Fill with Byes
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Xoco70\LaravelTournaments\TreeGen\TreeGen as the method adjustFightersGroupWithByes() does only exist in the following sub-classes of Xoco70\LaravelTournaments\TreeGen\TreeGen: Xoco70\LaravelTournament...nationCompetitorTreeGen, Xoco70\LaravelTournament...eEliminationTeamTreeGen, Xoco70\LaravelTournament...ingleEliminationTreeGen. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
203
        return $fightersWithBye->chunk(count($fightersWithBye) / $areas);   // Chunk user by areas
204
    }
205
206
    /**
207
     * Logically build the tree ( attach a parent to every child for nestedSet Navigation )
208
     *
209
     * @param $numFighters
210
     */
211
    protected function addParentToChildren($numFighters)
212
    {
213
        $numRounds = $this->getNumRounds($numFighters);
214
        $groupsDesc = $this->championship
215
            ->fightersGroups()
216
            ->where('round', '<', $numRounds)
217
            ->orderByDesc('id')->get();
218
219
        $groupsDescByRound = $groupsDesc->groupBy('round');
220
221
        foreach ($groupsDescByRound as $round => $groups) {
222
            $previousRound = $this->getPreviousRound($round);
223
            foreach ($groups->reverse()->values() as $matchNumber => $group) {
224
                $parent = $this->getParentGroup($matchNumber + 1, $previousRound);
225
                $group->parent_id = $parent->id;
226
                $group->save();
227
            }
228
        }
229
    }
230
231
232
    /**
233
     * Destroy Previous Fights for demo.
234
     */
235
    protected function destroyPreviousFights()
236
    {
237
        // Delete previous fight for this championship
238
        $arrGroupsId = $this->championship->fightersGroups()->get()->pluck('id');
239
        if (count($arrGroupsId) > 0) {
240
            Fight::destroy($arrGroupsId);
241
        }
242
    }
243
244
    /**
245
     * Generate Fights for next rounds.
246
     */
247
    public function generateNextRoundsFights()
248
    {
249
        $fightersCount = $this->championship->competitors->count() + $this->championship->teams->count();
0 ignored issues
show
Documentation introduced by
The property competitors does not exist on object<Xoco70\LaravelTou...ts\Models\Championship>. 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...
Documentation introduced by
The property teams does not exist on object<Xoco70\LaravelTou...ts\Models\Championship>. 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...
250
        $maxRounds = $this->getNumRounds($fightersCount);
251
        for ($numRound = 1; $numRound < $maxRounds; $numRound++) {
252
            $groupsByRound = $this->championship->fightersGroups()->where('round', $numRound)->with('parent', 'children')->get();
253
            $this->updateParentFight($groupsByRound); // should be groupsByRound
254
        }
255
    }
256
257
    /**
258
     * @param $groupsByRound
259
     */
260
    protected function updateParentFight($groupsByRound)
261
    {
262
        foreach ($groupsByRound as $keyGroup => $group) {
263
            $parentGroup = $group->parent;
264
            if ($parentGroup == null) {
265
                break;
266
            }
267
            $parentFight = $parentGroup->fights->get(0);
268
269
            // determine whether c1 or c2 must be updated
270
            $this->chooseAndUpdateParentFight($keyGroup, $group, $parentFight);
271
        }
272
    }
273
274
    /**
275
     * @param $group
276
     * @param $parentFight
277
     */
278
    protected function chooseAndUpdateParentFight($keyGroup, FightersGroup $group, Fight $parentFight)
279
    {
280
        // we need to know if the child has empty fighters, is this BYE or undetermined
281
        if ($group->hasDeterminedParent()) {
282
            $valueToUpdate = $group->getValueToUpdate(); // This should be OK
283
            if ($valueToUpdate != null) {
284
                $fighterToUpdate = $group->getParentFighterToUpdate($keyGroup);
285
                $parentFight->$fighterToUpdate = $valueToUpdate;
286
                $parentFight->save();
287
                // Add fighter to pivot table
288
                $parentGroup = $parentFight->group;
0 ignored issues
show
Documentation introduced by
The property group does not exist on object<Xoco70\LaravelTournaments\Models\Fight>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
289
290
                $fighter = $this->getFighter($valueToUpdate);
0 ignored issues
show
Bug introduced by
The method getFighter() does not exist on Xoco70\LaravelTournaments\TreeGen\TreeGen. Did you maybe mean getFightersByEntity()?

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...
291
                $this->addFighterToGroup($parentGroup, $fighter, $fighterToUpdate);
292
            }
293
        }
294
    }
295
296
    /**
297
     * Calculate the area of the group ( group is still not created ).
298
     *
299
     * @param $round
300
     * @param $order
301
     *
302
     * @return int
303
     */
304
    protected function getNumArea($round, $order)
305
    {
306
        $totalAreas = $this->settings->fightingAreas;
307
        $numFighters = $this->championship->fighters->count(); // 4
0 ignored issues
show
Documentation introduced by
The property fighters does not exist on object<Xoco70\LaravelTou...ts\Models\Championship>. 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...
308
        $numGroups = $this->getTreeSize($numFighters, $this->championship->getGroupSize()) / $this->championship->getGroupSize(); // 1 -> 1
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
309
310
        $areaSize = $numGroups / ($totalAreas * pow(2, $round - 1));
311
312
        $numArea = intval(ceil($order / $areaSize)); // if round == 4, and second match 2/2 = 1 BAD
313
        return $numArea;
314
    }
315
316
    protected function generateAllFights()
317
    {
318
        $this->generateFights(); // Abstract
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
319
        $this->generateNextRoundsFights();
320
        Fight::generateFightsId($this->championship);
321
    }
322
}
323