cleanup src

This commit is contained in:
Tykayn 2021-04-27 12:51:21 +02:00 committed by tykayn
parent 94c02be927
commit 4bf2625908
8 changed files with 40 additions and 39 deletions

View File

@ -142,7 +142,7 @@ class PollController extends EmailsController {
return $this->notFoundPoll( $customUrl ); return $this->notFoundPoll( $customUrl );
} }
if ( md5($poll->getPassword()) === $md5 ) { if ( md5( $poll->getPassword() ) === $md5 ) {
// good matching pass // good matching pass
return $this->json( $poll->display() ); return $this->json( $poll->display() );
} else { } else {

View File

@ -71,7 +71,7 @@ class VoteController extends EmailsController {
$stack = new StackOfVotes(); $stack = new StackOfVotes();
$stack $stack
->setOwner( $foundOwner ) ->setOwner( $foundOwner )
->setIp($_SERVER['REMOTE_ADDR']) ->setIp( $_SERVER[ 'REMOTE_ADDR' ] )
->setPseudo( $data[ 'pseudo' ] ) ->setPseudo( $data[ 'pseudo' ] )
->setPoll( $poll ); ->setPoll( $poll );
foreach ( $data[ 'votes' ] as $voteInfo ) { foreach ( $data[ 'votes' ] as $voteInfo ) {

View File

@ -53,7 +53,7 @@ class Choice {
private $poll; private $poll;
public function __construct( $optionalName = null ) { public function __construct( $optionalName = null ) {
$this->setCreatedAt( new DateTime()); $this->setCreatedAt( new DateTime() );
$this->poll = new ArrayCollection(); $this->poll = new ArrayCollection();
$this->votes = new ArrayCollection(); $this->votes = new ArrayCollection();
$this->setDateTime( new DateTime() ); $this->setDateTime( new DateTime() );

View File

@ -59,6 +59,10 @@ class Comment {
return $this; return $this;
} }
public function getCreatedAt(): ?DateTimeInterface {
return $this->createdAt;
}
function display() { function display() {
return [ return [
'id' => $this->getId(), 'id' => $this->getId(),
@ -92,10 +96,6 @@ class Comment {
return $this; return $this;
} }
public function getCreatedAt(): ?DateTimeInterface {
return $this->createdAt;
}
public function getPoll(): ?Poll { public function getPoll(): ?Poll {
return $this->poll; return $this->poll;
} }

View File

@ -66,7 +66,7 @@ class Owner {
$this->stackOfVotes = new ArrayCollection(); $this->stackOfVotes = new ArrayCollection();
$this->setCreatedAt( new DateTime() ); $this->setCreatedAt( new DateTime() );
$this->setModifierToken( uniqid() ); $this->setModifierToken( uniqid() );
$this->setCreatedAt( new DateTime()); $this->setCreatedAt( new DateTime() );
} }
public function setCreatedAt( DateTimeInterface $createdAt ): self { public function setCreatedAt( DateTimeInterface $createdAt ): self {
@ -75,6 +75,10 @@ class Owner {
return $this; return $this;
} }
public function getCreatedAt(): ?DateTimeInterface {
return $this->createdAt;
}
public function display() { public function display() {
return [ return [
'pseudo' => $this->getPseudo(), 'pseudo' => $this->getPseudo(),
@ -228,10 +232,6 @@ class Owner {
return $this; return $this;
} }
public function getCreatedAt(): ?DateTimeInterface {
return $this->createdAt;
}
public function getRequestedPollsDate() { public function getRequestedPollsDate() {
return $this->requestedPollsDate; return $this->requestedPollsDate;
} }

View File

@ -195,7 +195,7 @@ class Poll {
public function __construct() { public function __construct() {
$this->initiate(); $this->initiate();
$this->setCreatedAt( new DateTime()); $this->setCreatedAt( new DateTime() );
$this->votes = new ArrayCollection(); $this->votes = new ArrayCollection();
$this->stacksOfVotes = new ArrayCollection(); $this->stacksOfVotes = new ArrayCollection();
$this->choices = new ArrayCollection(); $this->choices = new ArrayCollection();
@ -216,6 +216,11 @@ class Poll {
$this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] ); $this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] );
} }
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
public function displayForAdmin() { public function displayForAdmin() {
$content = $this->display(); $content = $this->display();
@ -227,6 +232,8 @@ class Poll {
return $content; return $content;
} }
// counts each number of answer for this choice
public function display() { public function display() {
$computedAnswers = $this->computeAnswers(); $computedAnswers = $this->computeAnswers();
@ -269,7 +276,6 @@ class Poll {
]; ];
} }
// counts each number of answer for this choice
public function computeAnswers() { public function computeAnswers() {
$computedArray = []; $computedArray = [];
$maxScore = 0; $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() { public function getStacksOfVotes() {
return $this->stacksOfVotes; return $this->stacksOfVotes;
} }
@ -344,13 +367,6 @@ class Poll {
return $this; return $this;
} }
/**
* @return Collection|Choice[]
*/
public function getChoices(): Collection {
return $this->choices;
}
/** /**
* @return Collection|Comment[] * @return Collection|Comment[]
*/ */
@ -382,12 +398,6 @@ class Poll {
return $this->createdAt; return $this->createdAt;
} }
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
public function getExpiracyDate(): ?DateTimeInterface { public function getExpiracyDate(): ?DateTimeInterface {
return $this->expiracyDate; return $this->expiracyDate;
} }
@ -418,16 +428,6 @@ class Poll {
return $this; return $this;
} }
public function getKind(): ?string {
return $this->kind;
}
public function setKind( string $kind ): self {
$this->kind = $kind;
return $this;
}
public function getAllowedAnswers(): ?array { public function getAllowedAnswers(): ?array {
return $this->allowedAnswers; return $this->allowedAnswers;
} }

View File

@ -53,7 +53,7 @@ class Vote {
private $stacksOfVotes; private $stacksOfVotes;
public function __construct() { public function __construct() {
$this->setCreatedAt( new DateTime()); $this->setCreatedAt( new DateTime() );
} }
public function display() { public function display() {

View File

@ -2,6 +2,7 @@
namespace App\Traits; namespace App\Traits;
use DateInterval;
use DateTime; use DateTime;
use DateTimeInterface; use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
@ -29,7 +30,7 @@ trait TimeStampableTrait {
public function addDaysToDate( DateTime $date, int $days ) { public function addDaysToDate( DateTime $date, int $days ) {
return $date->add(new \DateInterval('P'.$days.'D')); return $date->add( new DateInterval( 'P' . $days . 'D' ) );
} }