Commit fccab39e authored by Clouard Regis's avatar Clouard Regis
Browse files

Refactored Entity

parent ce7a1dff
......@@ -2,6 +2,7 @@
namespace App\Entity;
use DateTime;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
......@@ -9,9 +10,7 @@ use Doctrine\ORM\Mapping as ORM;
use App\Model\CourseValidator;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Intl\Exception\BadMethodCallException;
// TODO
/**
* @ORM\Entity(repositoryClass="App\Repository\CourseRepository")
*/
......@@ -50,9 +49,9 @@ class Course
/**
* @ORM\Column(type="datetime")
*/
private $updateAt;
private ?DateTimeInterface $updateAt;
private $error;
private string $error;
/**
* @ORM\Column(type="string", length=255)
......@@ -62,12 +61,12 @@ class Course
/**
* @ORM\OneToMany(targetEntity="App\Entity\Track", mappedBy="course", orphanRemoval=true)
*/
private $orienteer;
private Collection $orienteer;
/**
* @ORM\OneToMany(targetEntity="App\Entity\MissingControlPoint", mappedBy="course", orphanRemoval=true)
*/
private $missingControlPoints;
private Collection $missingControlPoints;
/**
* @ORM\Column(type="string", length=255)
......@@ -102,12 +101,12 @@ class Course
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $startDate=null;
private ?DateTime $startDate = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $endDate=null;
private ?DateTime $endDate = null;
public function __construct()
{
......@@ -338,29 +337,27 @@ class Course
return $this;
}
public function getStartDate(): ?\DateTimeInterface
public function getStartDate(): ?DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(?\DateTimeInterface $startDate): self
public function setStartDate(?DateTimeInterface $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function getEndDate(): ?\DateTimeInterface
public function getEndDate(): ?DateTimeInterface
{
return $this->endDate;
}
public function setEndDate(?\DateTimeInterface $endDate): self
public function setEndDate(?DateTimeInterface $endDate): self
{
$this->endDate = $endDate;
return $this;
}
}
......@@ -8,7 +8,6 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Persistence\ObjectManager;
// TODO
/**
* @ORM\Entity(repositoryClass=EventRepository::class)
*/
......@@ -40,12 +39,12 @@ class Event
/**
* @ORM\OneToMany(targetEntity="App\Entity\EventCourse", mappedBy="event", orphanRemoval=true)
*/
private $eventCourses;
private Collection $eventCourses;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Participant", mappedBy="event", orphanRemoval=true)
*/
private $participant;
private Collection $participant;
public function getId(): ?int
{
......
......@@ -7,7 +7,6 @@ use App\Repository\ParticipantMakeEventCourseRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Persistence\ObjectManager;
// TODO
/**
* @ORM\Entity(repositoryClass=EventCourseRepository::class)
*/
......@@ -124,7 +123,7 @@ class EventCourse
return $this->maxTime;
}
public function setMaxTime(?int $maxTime): self
public function setMaxTime(int $maxTime): self
{
$this->maxTime = $maxTime;
......@@ -136,7 +135,7 @@ class EventCourse
return $this->time;
}
public function setTime(?string $time): self
public function setTime(string $time): self
{
$this->time = $time;
......
......@@ -4,7 +4,6 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
// TODO
/**
* @ORM\Entity(repositoryClass="App\Repository\MissingControlPointRepository")
*/
......
......@@ -7,7 +7,6 @@ use App\Repository\ParticipantRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Persistence\ObjectManager;
// TODO
/**
* @ORM\Entity(repositoryClass=ParticipantRepository::class)
*/
......@@ -23,7 +22,7 @@ class Participant
/**
* @ORM\Column(type="string", length=255)
*/
private $nickname;
private ?string $nickname;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Event", inversedBy="participant")
......@@ -69,7 +68,7 @@ class Participant
$entityManager->flush();
}
public function checkNickname(Event $event)
public function checkNickname(Event $event): bool
{
foreach ($event->getParticipants() as $participant) {
if ($this->nickname === $participant->getNickname()) {
......@@ -79,7 +78,7 @@ class Participant
return true;
}
public function create(Event $event, ObjectManager $entityManager)
public function create(Event $event, ObjectManager $entityManager): string
{
if ($this->checkNickname($event)) {
$this->setEvent($event);
......
......@@ -6,7 +6,6 @@ use App\Repository\ParticipantMakeEventCourseRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Persistence\ObjectManager;
// TODO
/**
* @ORM\Entity(repositoryClass=ParticipantMakeEventCourseRepository::class)
*/
......@@ -199,7 +198,7 @@ class ParticipantMakeEventCourse
$this->nbOverTimePenalty = floor(($overTime / 1000) / 60);
$overTime = ($overTime / 1000) % $this->nbOverTimePenalty;
}
if ($overTime = !0) {
if ($overTime != 0) {
$this->nbOverTimePenalty += 1;
}
}
......@@ -217,10 +216,10 @@ class ParticipantMakeEventCourse
if ($this->participant->getEvent()->getType() === 1) {
$t = simplexml_load_string($this->eventCourse->getCourse()->getXml());
$balise = 0;
$controlPointIndex = 0;
foreach ($t->RaceCourseData->Course->CourseControl as $y) {
if ((string)$y->attributes()["type"] === "Control") {
if ((int)$this->track->getControlPoints()[$balise]->punchTime !== 0) {
if ((int)$this->track->getControlPoints()[$controlPointIndex]->punchTime !== 0) {
if (isset($y->Score)) {
$this->score += (int)$y->Score;
} else {
......@@ -229,7 +228,7 @@ class ParticipantMakeEventCourse
}
}
}
$balise++;
$controlPointIndex++;
}
$this->score -= (($this->nbMissingPunchPenalty * $this->eventCourse->getMissingPunchPenalty()) + $this->nbOverTimePenalty * $this->eventCourse->getOverTimePenalty());
}
......
......@@ -4,7 +4,6 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
// TODO
/**
* @ORM\Entity(repositoryClass="App\Repository\TrackRepository")
*/
......
......@@ -12,7 +12,6 @@ use Ambta\DoctrineEncryptBundle\Configuration\Encrypted;
use App\Model\UserValidator;
use Symfony\Component\Validator\Constraints as Assert;
// TODO
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="user")
......@@ -40,38 +39,38 @@ class User implements UserInterface
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
private string $password;
/**
* @Assert\Length(min=8, max=4096)
*/
private $plainPassword;
private ?string $plainPassword;
/**
* @ORM\Column(type="text")
* @Encrypted()
* @var int
*/
private $email;
private ?string $email;
/**
* @ORM\Column(type="text", nullable=true)
* @Encrypted()
* @var int
*/
private $phone;
private ?string $phone;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Course", mappedBy="creator")
*/
private $courses;
private Collection $courses;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Event", mappedBy="creator")
*/
private $events;
private Collection $events;
private $error;
private string $error;
public function __construct()
{
......@@ -112,7 +111,12 @@ class User implements UserInterface
*/
public function getUsername(): string
{
return (string)$this->username;
return $this->username;
}
public function getUserIdentifier(): string
{
return $this->username;
}
public function setUsername(string $username): self
......@@ -146,7 +150,7 @@ class User implements UserInterface
*/
public function getPassword(): string
{
return (string)$this->password;
return $this->password;
}
public function setPassword(string $password): self
......@@ -156,7 +160,7 @@ class User implements UserInterface
return $this;
}
public function getPlainPassword()
public function getPlainPassword(): string
{
return $this->plainPassword;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment