Skip to content

Commit

Permalink
chore: refactored person type entities
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent 93b053d commit 30c5e55
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 415 deletions.
142 changes: 3 additions & 139 deletions src/Entity/Coach.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,14 @@

use ProgrammatorDev\SportMonksFootball\Util\EntityTrait;

class Coach
class Coach extends Person
{
use EntityTrait;

private int $id;

private int $playerId;

private int $sportId;

private int $countryId;

private int $nationalityId;

private ?int $cityId;

private ?string $commonName;

private ?string $firstName;

private ?string $lastName;

private ?string $name;

private ?string $displayName;

private ?string $imagePath;

private ?int $height;

private ?int $weight;

private ?\DateTimeImmutable $birthdate;

private ?string $gender;

private ?Sport $sport;

private ?Country $country;

private ?Country $nationality;

/** @var ?ParticipantTrophy[] */
private ?array $trophies;

Expand All @@ -62,131 +28,29 @@ class Coach

public function __construct(array $data, string $timezone)
{
$this->id = $data['id'];
parent::__construct($data, $timezone);

$this->playerId = $data['player_id'];
$this->sportId = $data['sport_id'];
$this->countryId = $data['country_id'];
$this->nationalityId = $data['nationality_id'];

// select
$this->cityId = $data['city_id'] ?? null;
$this->commonName = $data['common_name'] ?? null;
$this->firstName = $data['firstname'] ?? null;
$this->lastName = $data['lastname'] ?? null;
$this->name = $data['name'] ?? null;
$this->displayName = $data['display_name'] ?? null;
$this->imagePath = $data['image_path'] ?? null;
$this->height = $data['height'] ?? null;
$this->weight = $data['weight'] ?? null;
$this->birthdate = isset($data['date_of_birth']) ? new \DateTimeImmutable($data['date_of_birth']) : null;
$this->gender = $data['gender'] ?? null;

// include
$this->sport = isset($data['sport']) ? new Sport($data['sport']) : null;
$this->country = isset($data['country']) ? new Country($data['country'], $timezone) : null;
$this->nationality = isset($data['nationality']) ? new Country($data['nationality'], $timezone) : null;
$this->trophies = isset($data['trophies']) ? $this->createEntityCollection(ParticipantTrophy::class, $data['trophies']) : null;
$this->player = isset($data['player']) ? new Player($data['player'], $timezone) : null;
$this->fixtures = isset($data['fixtures']) ? $this->createEntityCollection(Fixture::class, $data['fixtures'], $timezone) : null;
$this->teams = isset($data['teams']) ? $this->createEntityCollection(TeamCoach::class, $data['teams'], $timezone) : null;
$this->statistics = isset($data['statistics']) ? $this->createEntityCollection(CoachStatistic::class, $data['statistics'], $timezone) : null;
}

public function getId(): int
{
return $this->id;
}

public function getPlayerId(): int
{
return $this->playerId;
}

public function getSportId(): int
{
return $this->sportId;
}

public function getCountryId(): int
{
return $this->countryId;
}

public function getNationalityId(): int
{
return $this->nationalityId;
}

public function getCityId(): ?int
{
return $this->cityId;
}

public function getCommonName(): ?string
{
return $this->commonName;
}

public function getFirstName(): ?string
{
return $this->firstName;
}

public function getLastName(): ?string
{
return $this->lastName;
}

public function getName(): ?string
{
return $this->name;
}

public function getDisplayName(): ?string
{
return $this->displayName;
}

public function getImagePath(): ?string
{
return $this->imagePath;
}

public function getHeight(): ?int
{
return $this->height;
}

public function getWeight(): ?int
{
return $this->weight;
}

public function getBirthdate(): ?\DateTimeImmutable
{
return $this->birthdate;
}

public function getGender(): ?string
{
return $this->gender;
}

public function getSport(): ?Sport
{
return $this->sport;
}

public function getCountry(): ?Country
{
return $this->country;
}

public function getNationality(): ?Country
{
return $this->nationality;
}

public function getTrophies(): ?array
{
return $this->trophies;
Expand Down
154 changes: 154 additions & 0 deletions src/Entity/Person.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Entity;

use ProgrammatorDev\SportMonksFootball\Util\EntityTrait;

class Person
{
use EntityTrait;

private int $id;

private int $sportId;

private ?int $countryId;

private ?int $cityId;

private ?string $commonName;

private ?string $firstName;

private ?string $lastName;

private ?string $name;

private ?string $displayName;

private ?string $imagePath;

private ?int $height;

private ?int $weight;

private ?\DateTimeImmutable $birthdate;

private ?string $gender;

private ?Sport $sport;

private ?Country $country;

private ?Country $nationality;

public function __construct(array $data, string $timezone)
{
$this->id = $data['id'];
$this->sportId = $data['sport_id'];
$this->countryId = $data['country_id'] ?? null;
$this->cityId = $data['city_id'] ?? null;

// select
$this->commonName = $data['common_name'] ?? null;
$this->firstName = $data['firstname'] ?? null;
$this->lastName = $data['lastname'] ?? null;
$this->name = $data['name'] ?? null;
$this->displayName = $data['display_name'] ?? null;
$this->imagePath = $data['image_path'] ?? null;
$this->height = $data['height'] ?? null;
$this->weight = $data['weight'] ?? null;
$this->birthdate = isset($data['date_of_birth']) ? new \DateTimeImmutable($data['date_of_birth']) : null;
$this->gender = $data['gender'] ?? null;

// include
$this->sport = isset($data['sport']) ? new Sport($data['sport']) : null;
$this->country = isset($data['country']) ? new Country($data['country'], $timezone) : null;
$this->nationality = isset($data['nationality']) ? new Country($data['nationality'], $timezone) : null;
}

public function getId(): int
{
return $this->id;
}

public function getSportId(): int
{
return $this->sportId;
}

public function getCountryId(): ?int
{
return $this->countryId;
}

public function getCityId(): ?int
{
return $this->cityId;
}

public function getCommonName(): ?string
{
return $this->commonName;
}

public function getFirstName(): ?string
{
return $this->firstName;
}

public function getLastName(): ?string
{
return $this->lastName;
}

public function getName(): ?string
{
return $this->name;
}

public function getDisplayName(): ?string
{
return $this->displayName;
}

public function getImagePath(): ?string
{
return $this->imagePath;
}

public function getHeight(): ?int
{
return $this->height;
}

public function getWeight(): ?int
{
return $this->weight;
}

public function getBirthdate(): ?\DateTimeImmutable
{
return $this->birthdate;
}

public function getGender(): ?string
{
return $this->gender;
}

public function getSport(): ?Sport
{
return $this->sport;
}

public function getCountry(): ?Country
{
return $this->country;
}

public function getNationality(): ?Country
{
return $this->nationality;
}
}
Loading

0 comments on commit 30c5e55

Please sign in to comment.