Skip to content

Commit

Permalink
phpstan code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lsv committed May 8, 2018
1 parent b46b4a3 commit 5c037e7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 68 deletions.
14 changes: 6 additions & 8 deletions src/Model/Standing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@

class Standing
{

/**
* @var Stand[]
* @var Stand[]|null
*/
private $standings;

/**
* @var Stand[]
* @var Stand[]|null
*/
private $homeStandings;

/**
* @var Stand[]
* @var Stand[]|null
*/
private $awayStandings;

Expand Down Expand Up @@ -63,7 +62,7 @@ public function addAwayStanding(Stand $stand): void
public function getTotalStandings(): array
{
$standings = $this->standings;
usort($standings, function(Stand $a, Stand $b) {
usort($standings, function (Stand $a, Stand $b) {
return $a->getData()->getRank() <=> $b->getData()->getRank();
});
return $standings;
Expand All @@ -75,7 +74,7 @@ public function getTotalStandings(): array
public function getHomeStandings(): array
{
$standings = $this->homeStandings;
usort($standings, function(Stand $a, Stand $b) {
usort($standings, function (Stand $a, Stand $b) {
return $a->getData()->getRank() <=> $b->getData()->getRank();
});
return $standings;
Expand All @@ -87,7 +86,7 @@ public function getHomeStandings(): array
public function getAwayStandings(): array
{
$standings = $this->awayStandings;
usort($standings, function(Stand $a, Stand $b) {
usort($standings, function (Stand $a, Stand $b) {
return $a->getData()->getRank() <=> $b->getData()->getRank();
});
return $standings;
Expand All @@ -100,5 +99,4 @@ public function getStage(): TournamentStage
{
return $this->stage;
}

}
2 changes: 0 additions & 2 deletions src/Model/Standing/Stand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class Stand
{

/**
* @var Participant
*/
Expand All @@ -30,5 +29,4 @@ public function getData(): StandData
{
return $this->data;
}

}
2 changes: 0 additions & 2 deletions src/Model/Standing/StandData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class StandData
{

/**
* @var int
*/
Expand Down Expand Up @@ -120,5 +119,4 @@ public function getPoints(): int
{
return $this->points;
}

}
1 change: 0 additions & 1 deletion src/Provider/ParticipantProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,4 @@ protected function queryBuilder(int $eventId): QueryBuilder
$this->removeDeleted($qb, ['ep', 'p', 'c', 'r']);
return $qb;
}

}
112 changes: 57 additions & 55 deletions src/Provider/StandingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
use SDM\Enetpulse\Model\Standing;
use SDM\Enetpulse\Model\Tournament;
use SDM\Enetpulse\Model\Tournament\TournamentStage;
use SDM\Enetpulse\Utils\Utils;

class StandingProvider extends AbstractProvider
{

/**
* @param TournamentStage $stage
*
* @return Standing
*/
public function getStandingFromTournamentStage(TournamentStage $stage): Standing
public function getStandingFromTournamentStage(TournamentStage $stage): ?Standing
{
return $this->getStandingFromTournamentStageId($stage->getId());
}
Expand All @@ -27,7 +25,7 @@ public function getStandingFromTournamentStage(TournamentStage $stage): Standing
*
* @return Standing
*/
public function getStandingFromTournamentStageId(int $stage): Standing
public function getStandingFromTournamentStageId(int $stage): ?Standing
{
return $this->build($this->queryBuilder($stage));
}
Expand All @@ -37,69 +35,74 @@ public function getStandingFromTournamentStageId(int $stage): Standing
*
* @return Standing
*/
private function build(QueryBuilder $qb): Standing
private function build(QueryBuilder $qb): ?Standing
{
return $this->createObject($this->fetchSingle($qb));
}

protected function createObject(\stdClass $data): Standing
protected function createObject(?\stdClass $data): ?Standing
{
$standing = new Standing(
new TournamentStage(
$data->ts_id,
$data->ts_name,
$data->country_name,
$this->createDate($data->ts_startdate),
$this->createDate($data->ts_enddate),
new Tournament(
$data->t_id,
$data->t_name,
new Tournament\TournamentTemplate(
$data->tt_id,
$data->tt_name,
new Sport(
$data->sport_id,
$data->sport_name
), $data->tt_gender
if ($data) {
$standing = new Standing(
new TournamentStage(
$data->ts_id,
$data->ts_name,
$data->country_name,
$this->createDate($data->ts_startdate),
$this->createDate($data->ts_enddate),
new Tournament(
$data->t_id,
$data->t_name,
new Tournament\TournamentTemplate(
$data->tt_id,
$data->tt_name,
new Sport(
$data->sport_id,
$data->sport_name
),
$data->tt_gender
)
)
)
)
);

$standingBuilder = $this->queryBuilderStandingData($data->ts_id);
foreach ($this->fetchObjects($standingBuilder) as $object) {
$participant = new Standing\Participant(
$object->p_id,
$object->p_name,
$object->p_type,
$object->country_name,
$this->createImage($object->i_contenttype, $object->i_value)
);

$standing->addStanding(
new Standing\Stand(
$participant,
$this->queryBuilderStandingDataValues($object->standing_p_id, 'total')
)
);
$standing->addHomeStanding(
new Standing\Stand(
$participant,
$this->queryBuilderStandingDataValues($object->standing_p_id, 'home')
)
);
$standing->addAwayStanding(
new Standing\Stand(
$participant,
$this->queryBuilderStandingDataValues($object->standing_p_id, 'away')
)
);
$standingBuilder = $this->queryBuilderStandingData($data->ts_id);
foreach ($this->fetchObjects($standingBuilder) as $object) {
$participant = new Standing\Participant(
$object->p_id,
$object->p_name,
$object->p_type,
$object->country_name,
$this->createImage($object->i_contenttype, $object->i_value)
);

$standing->addStanding(
new Standing\Stand(
$participant,
$this->queryBuilderStandingDataValues($object->standing_p_id, 'total')
)
);
$standing->addHomeStanding(
new Standing\Stand(
$participant,
$this->queryBuilderStandingDataValues($object->standing_p_id, 'home')
)
);
$standing->addAwayStanding(
new Standing\Stand(
$participant,
$this->queryBuilderStandingDataValues($object->standing_p_id, 'away')
)
);
}

return $standing;
}

return $standing;
return null;
}

protected function queryBuilder($stageId) : QueryBuilder
protected function queryBuilder($stageId): QueryBuilder
{
$qb = $this->getBuilder();

Expand Down Expand Up @@ -212,5 +215,4 @@ private function queryBuilderStandingDataValues($id, $type): Standing\StandData
$points
);
}

}

0 comments on commit 5c037e7

Please sign in to comment.