Skip to content

Commit

Permalink
improve type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
fiste788 committed Oct 3, 2024
1 parent c135c77 commit 636c5f7
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 217 deletions.
303 changes: 154 additions & 149 deletions composer.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Model/Entity/Championship.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @property \App\Model\Entity\League $league
* @property \App\Model\Entity\Season $season
* @property \App\Model\Entity\Team[] $teams
* @property \App\Model\Entity\RollOfHonor[] $roll_of_honor
*/
class Championship extends Entity
{
Expand Down
1 change: 0 additions & 1 deletion src/Model/Entity/Club.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace App\Model\Entity;
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Entity/Disposition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* @property int $consideration
* @property float|null $points
* @property int $lineup_id
* @property int $member_id
* @property int|null $member_id
*
* @property \App\Model\Entity\Rating|null $rating
* @property \App\Model\Entity\Lineup $lineup
* @property \App\Model\Entity\Member $member
* @property \App\Model\Entity\Member|null $member
*/
class Disposition extends Entity
{
Expand Down
14 changes: 7 additions & 7 deletions src/Model/Entity/MembersStat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* MembersStat Entity
*
* @property int $member_id
* @property string|null $sum_present
* @property string|null $sum_valued
* @property int|null $sum_present
* @property int|null $sum_valued
* @property float|null $avg_points
* @property float|null $avg_rating
* @property string|null $sum_goals
* @property string|null $sum_goals_against
* @property string|null $sum_assist
* @property string|null $sum_yellow_card
* @property string|null $sum_red_card
* @property int|null $sum_goals
* @property int|null $sum_goals_against
* @property int|null $sum_assist
* @property int|null $sum_yellow_card
* @property int|null $sum_red_card
* @property int $quotation
*
* @property \App\Model\Entity\Member $member
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Entity/PublicKeyCredentialSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @property string $id
* @property string $public_key_credential_id
* @property string $type
* @property string $transports
* @property string|null $transports
* @property string $attestation_type
* @property string $trust_path
* @property string $aaguid
Expand Down Expand Up @@ -82,7 +82,7 @@ public function toCredentialSource(SerializerInterface $serializer): WebauthnPub
return $serializer->deserialize(json_encode([
'publicKeyCredentialId' => $this->public_key_credential_id,
'type' => $this->type,
'transports' => json_decode($this->transports),
'transports' => json_decode($this->transports != null ? $this->transports : ''),
'attestationType' => $this->attestation_type,
'trustPath' => json_decode($this->trust_path),
'aaguid' => $this->aaguid,
Expand Down
9 changes: 5 additions & 4 deletions src/Model/Entity/RollOfHonor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
* @property int $championship_id
* @property int $league_id
* @property float|null $points
* @property int|null $rank
* @property int $rank
*
* @property \App\Model\Entity\Member $member
* @property \App\Model\Entity\League $league
* @property \App\Model\Entity\Championship $championship
* @property \App\Model\Entity\Team $team
*/
class RollOfHonor extends Entity
{
Expand All @@ -27,7 +30,5 @@ class RollOfHonor extends Entity
*
* @var array<string, bool>
*/
protected array $_accessible = [

];
protected array $_accessible = [];
}
1 change: 0 additions & 1 deletion src/Model/Entity/Traits/HasPhotoTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace App\Model\Entity\Traits;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Table/ChampionshipsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @property \App\Model\Table\LeaguesTable&\Cake\ORM\Association\BelongsTo $Leagues
* @property \App\Model\Table\SeasonsTable&\Cake\ORM\Association\BelongsTo $Seasons
* @property \App\Model\Table\RollOfHonorsTable&\Cake\ORM\Association\BelongsTo $RollOfHonors
* @property \App\Model\Table\RollOfHonorsTable&\Cake\ORM\Association\HasMany $RollOfHonors
* @property \App\Model\Table\TeamsTable&\Cake\ORM\Association\HasMany $Teams
* @method \App\Model\Entity\Championship get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \App\Model\Entity\Championship newEntity(array $data, array $options = [])
Expand Down
5 changes: 2 additions & 3 deletions src/Model/Table/LineupsTable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace App\Model\Table;
Expand All @@ -21,8 +20,8 @@
* Lineups Model
*
* @property \App\Model\Table\MembersTable&\Cake\ORM\Association\BelongsTo $Captain
* @property \App\Model\Table\MembersTable&\Cake\ORM\Association\BelongsTo $VCaptain
* @property \App\Model\Table\MembersTable&\Cake\ORM\Association\BelongsTo $VVCaptain
* @property \App\Model\Table\MembersTable&\Cake\ORM\Association\BelongsTo $Vcaptain
* @property \App\Model\Table\MembersTable&\Cake\ORM\Association\BelongsTo $VVcaptain
* @property \App\Model\Table\MatchdaysTable&\Cake\ORM\Association\BelongsTo $Matchdays
* @property \App\Model\Table\TeamsTable&\Cake\ORM\Association\BelongsTo $Teams
* @property \App\Model\Table\DispositionsTable&\Cake\ORM\Association\HasMany $Dispositions
Expand Down
28 changes: 15 additions & 13 deletions src/Model/Table/RollOfHonorsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
* MembersStats Model
*
* @property \App\Model\Table\TeamsTable&\Cake\ORM\Association\BelongsTo $Teams
* @method \App\Model\Entity\MembersStat get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \App\Model\Entity\MembersStat newEntity(array $data, array $options = [])
* @method \App\Model\Entity\MembersStat[] newEntities(array $data, array $options = [])
* @method \App\Model\Entity\MembersStat|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \App\Model\Entity\MembersStat patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \App\Model\Entity\MembersStat[] patchEntities(iterable $entities, array $data, array $options = [])
* @method \App\Model\Entity\MembersStat findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \App\Model\Entity\MembersStat saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \App\Model\Entity\MembersStat newEmptyEntity()
* @method \App\Model\Entity\MembersStat[]|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, array $options = [])
* @method \App\Model\Entity\MembersStat[]|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, array $options = [])
* @method \App\Model\Entity\MembersStat[]|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, array $options = [])
* @method \App\Model\Entity\MembersStat[]|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, array $options = [])
* @method \App\Model\Entity\RollOfHonor get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \App\Model\Entity\RollOfHonor newEntity(array $data, array $options = [])
* @method \App\Model\Entity\RollOfHonor[] newEntities(array $data, array $options = [])
* @method \App\Model\Entity\RollOfHonor|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \App\Model\Entity\RollOfHonor patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \App\Model\Entity\RollOfHonor[] patchEntities(iterable $entities, array $data, array $options = [])
* @method \App\Model\Entity\RollOfHonor findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \App\Model\Entity\RollOfHonor saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \App\Model\Entity\RollOfHonor newEmptyEntity()
* @method \App\Model\Entity\RollOfHonor[]|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, array $options = [])
* @method \App\Model\Entity\RollOfHonor[]|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, array $options = [])
* @method \App\Model\Entity\RollOfHonor[]|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, array $options = [])
* @method \App\Model\Entity\RollOfHonor[]|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, array $options = [])
* @property \App\Model\Table\LeaguesTable&\Cake\ORM\Association\BelongsTo $Leagues
* @property \App\Model\Table\ChampionshipsTable&\Cake\ORM\Association\BelongsTo $Championships
*/
class RollOfHonorsTable extends Table
{
Expand Down
78 changes: 45 additions & 33 deletions src/Service/ComputeScoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,32 @@ public function compute(
}
foreach ($lineup->dispositions as $disposition) {
$member = $disposition->member;
if ($disposition->position <= 11) {
if (empty($member->ratings) || !$member->ratings[0]->valued) {
$notValueds[] = $member;
} else {
$sum += $this->regularize($disposition, $subtractBonusGoals, $subtractBonusCleanSheet, $cap);
}
} else {
foreach ($notValueds as $key => $notValued) {
$ratings = $member->ratings;
if (
$substitution < $lineup->team->championship->number_substitutions &&
$member->role_id == $notValued->role_id &&
!empty($ratings) &&
$ratings[0]->valued
) {
if ($member) {
if ($disposition->position <= 11) {
if (empty($member->ratings) || !$member->ratings[0]->valued) {
$notValueds[] = $member;
} else {
$sum += $this->regularize($disposition, $subtractBonusGoals, $subtractBonusCleanSheet, $cap);
$substitution++;
unset($notValueds[$key]);
break;
}
} else {
foreach ($notValueds as $key => $notValued) {
$ratings = $member->ratings;
if (
$substitution < $lineup->team->championship->number_substitutions &&
$member->role_id == $notValued->role_id &&
!empty($ratings) &&
$ratings[0]->valued
) {
$sum += $this->regularize(
$disposition,
$subtractBonusGoals,
$subtractBonusCleanSheet,
$cap
);
$substitution++;
unset($notValueds[$key]);
break;
}
}
}
}
Expand Down Expand Up @@ -215,7 +222,7 @@ function ($value) use ($cap) {
}
);
$disposition = array_shift($dispositions);
if ($disposition && $disposition->member->ratings[0]->valued) {
if ($disposition && $disposition->member && $disposition->member->ratings[0]->valued) {
return $cap;
}
}
Expand All @@ -239,21 +246,26 @@ private function regularize(
bool $subtractBonusCleanSheet,
?int $cap = null
): float {
$disposition->consideration = 1;
$rating = $disposition->member->ratings[0];
$points = $rating->points;
if ($subtractBonusGoals) {
$points -= $rating->getBonusPointsGoals($disposition->member);
}
if ($subtractBonusCleanSheet) {
$points -= $rating->getBonusCleanSheetPoints($disposition->member);
}
$disposition->points = $points;
if ($cap != null && $disposition->member->id == $cap) {
$disposition->consideration = 2;
$points *= 2;
if ($disposition->member) {
$disposition->consideration = 1;

$rating = $disposition->member->ratings[0];
$points = $rating->points;
if ($subtractBonusGoals) {
$points -= $rating->getBonusPointsGoals($disposition->member);
}
if ($subtractBonusCleanSheet) {
$points -= $rating->getBonusCleanSheetPoints($disposition->member);
}
$disposition->points = $points;
if ($cap != null && $disposition->member->id == $cap) {
$disposition->consideration = 2;
$points *= 2;
}

return $points;
}

return $points;
return 0;
}
}
4 changes: 3 additions & 1 deletion src/Stream/Verb/Lineup.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public function getBody(): string
$regular = array_splice($lineup->dispositions, 0, 11);
$players = [];
foreach ($regular as $disposition) {
$players[] = $disposition->member->player->surname;
if ($disposition->member) {
$players[] = $disposition->member->player->surname;
}
}

return implode(', ', $players);
Expand Down

0 comments on commit 636c5f7

Please sign in to comment.