From 4bf2625908c488f22fff78aa909127a8cdf4b431 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Tue, 27 Apr 2021 12:51:21 +0200 Subject: [PATCH] cleanup src --- src/Controller/api/PollController.php | 2 +- src/Controller/api/VoteController.php | 2 +- src/Entity/Choice.php | 2 +- src/Entity/Comment.php | 8 ++--- src/Entity/Owner.php | 10 +++--- src/Entity/Poll.php | 50 +++++++++++++------------- src/Entity/Vote.php | 2 +- src/Traits/TimeStampableTraitTrait.php | 3 +- 8 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/Controller/api/PollController.php b/src/Controller/api/PollController.php index 6034575..6c0d3f3 100644 --- a/src/Controller/api/PollController.php +++ b/src/Controller/api/PollController.php @@ -142,7 +142,7 @@ class PollController extends EmailsController { return $this->notFoundPoll( $customUrl ); } - if ( md5($poll->getPassword()) === $md5 ) { + if ( md5( $poll->getPassword() ) === $md5 ) { // good matching pass return $this->json( $poll->display() ); } else { diff --git a/src/Controller/api/VoteController.php b/src/Controller/api/VoteController.php index a2b2aa9..3ff2a01 100644 --- a/src/Controller/api/VoteController.php +++ b/src/Controller/api/VoteController.php @@ -71,7 +71,7 @@ class VoteController extends EmailsController { $stack = new StackOfVotes(); $stack ->setOwner( $foundOwner ) - ->setIp($_SERVER['REMOTE_ADDR']) + ->setIp( $_SERVER[ 'REMOTE_ADDR' ] ) ->setPseudo( $data[ 'pseudo' ] ) ->setPoll( $poll ); foreach ( $data[ 'votes' ] as $voteInfo ) { diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index b06af21..783ef45 100755 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -53,7 +53,7 @@ class Choice { private $poll; public function __construct( $optionalName = null ) { - $this->setCreatedAt( new DateTime()); + $this->setCreatedAt( new DateTime() ); $this->poll = new ArrayCollection(); $this->votes = new ArrayCollection(); $this->setDateTime( new DateTime() ); diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index 96b9a7a..209b41a 100755 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -59,6 +59,10 @@ class Comment { return $this; } + public function getCreatedAt(): ?DateTimeInterface { + return $this->createdAt; + } + function display() { return [ 'id' => $this->getId(), @@ -92,10 +96,6 @@ class Comment { return $this; } - public function getCreatedAt(): ?DateTimeInterface { - return $this->createdAt; - } - public function getPoll(): ?Poll { return $this->poll; } diff --git a/src/Entity/Owner.php b/src/Entity/Owner.php index 9515df2..d14fd15 100755 --- a/src/Entity/Owner.php +++ b/src/Entity/Owner.php @@ -66,7 +66,7 @@ class Owner { $this->stackOfVotes = new ArrayCollection(); $this->setCreatedAt( new DateTime() ); $this->setModifierToken( uniqid() ); - $this->setCreatedAt( new DateTime()); + $this->setCreatedAt( new DateTime() ); } public function setCreatedAt( DateTimeInterface $createdAt ): self { @@ -75,6 +75,10 @@ class Owner { return $this; } + public function getCreatedAt(): ?DateTimeInterface { + return $this->createdAt; + } + public function display() { return [ 'pseudo' => $this->getPseudo(), @@ -228,10 +232,6 @@ class Owner { return $this; } - public function getCreatedAt(): ?DateTimeInterface { - return $this->createdAt; - } - public function getRequestedPollsDate() { return $this->requestedPollsDate; } diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index e08513f..fd322c5 100755 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -195,7 +195,7 @@ class Poll { public function __construct() { $this->initiate(); - $this->setCreatedAt( new DateTime()); + $this->setCreatedAt( new DateTime() ); $this->votes = new ArrayCollection(); $this->stacksOfVotes = new ArrayCollection(); $this->choices = new ArrayCollection(); @@ -216,6 +216,11 @@ class Poll { $this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] ); } + public function setCreatedAt( DateTimeInterface $createdAt ): self { + $this->createdAt = $createdAt; + + return $this; + } public function displayForAdmin() { $content = $this->display(); @@ -227,6 +232,8 @@ class Poll { return $content; } + // counts each number of answer for this choice + public function display() { $computedAnswers = $this->computeAnswers(); @@ -269,7 +276,6 @@ class Poll { ]; } - // counts each number of answer for this choice public function computeAnswers() { $computedArray = []; $maxScore = 0; @@ -334,6 +340,23 @@ class Poll { ]; } + /** + * @return Collection|Choice[] + */ + public function getChoices(): Collection { + return $this->choices; + } + + public function getKind(): ?string { + return $this->kind; + } + + public function setKind( string $kind ): self { + $this->kind = $kind; + + return $this; + } + public function getStacksOfVotes() { return $this->stacksOfVotes; } @@ -344,13 +367,6 @@ class Poll { return $this; } - /** - * @return Collection|Choice[] - */ - public function getChoices(): Collection { - return $this->choices; - } - /** * @return Collection|Comment[] */ @@ -382,12 +398,6 @@ class Poll { return $this->createdAt; } - public function setCreatedAt( DateTimeInterface $createdAt ): self { - $this->createdAt = $createdAt; - - return $this; - } - public function getExpiracyDate(): ?DateTimeInterface { return $this->expiracyDate; } @@ -418,16 +428,6 @@ class Poll { return $this; } - public function getKind(): ?string { - return $this->kind; - } - - public function setKind( string $kind ): self { - $this->kind = $kind; - - return $this; - } - public function getAllowedAnswers(): ?array { return $this->allowedAnswers; } diff --git a/src/Entity/Vote.php b/src/Entity/Vote.php index 3d75040..2ab8b56 100755 --- a/src/Entity/Vote.php +++ b/src/Entity/Vote.php @@ -53,7 +53,7 @@ class Vote { private $stacksOfVotes; public function __construct() { - $this->setCreatedAt( new DateTime()); + $this->setCreatedAt( new DateTime() ); } public function display() { diff --git a/src/Traits/TimeStampableTraitTrait.php b/src/Traits/TimeStampableTraitTrait.php index 782801e..96e0080 100755 --- a/src/Traits/TimeStampableTraitTrait.php +++ b/src/Traits/TimeStampableTraitTrait.php @@ -2,6 +2,7 @@ namespace App\Traits; +use DateInterval; use DateTime; use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; @@ -29,7 +30,7 @@ trait TimeStampableTrait { public function addDaysToDate( DateTime $date, int $days ) { - return $date->add(new \DateInterval('P'.$days.'D')); + return $date->add( new DateInterval( 'P' . $days . 'D' ) ); }