Browse Source

Remise à plat des entities avec php8

François Drouhard 2 years ago
parent
commit
bbc19be3e3

+ 1 - 1
composer.json

@@ -9,7 +9,7 @@
         "doctrine/annotations": "^1.0",
         "doctrine/doctrine-bundle": "^2.7",
         "doctrine/doctrine-migrations-bundle": "^3.2",
-        "doctrine/orm": "^2.11",
+        "doctrine/orm": "^2.13",
         "phpdocumentor/reflection-docblock": "^5.3",
         "sensio/framework-extra-bundle": "^6.2",
         "symfony/apache-pack": "^1.0",

+ 1 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "4526c516ea41b4b30039392fe6ef0c77",
+    "content-hash": "14350783c7766297b9b01ff2f53f5b69",
     "packages": [
         {
             "name": "composer/package-versions-deprecated",

+ 11 - 9
src/Entity/Commentaire.php

@@ -40,53 +40,55 @@ class Commentaire
         $this->dateSubmitted = new \DateTime('now');
     }
 
-    public function getId()
+    public function getId(): int
     {
         return $this->id;
     }
 
-    public function setContenu($contenu)
+    public function setContenu($contenu): self
     {
         $this->contenu = $contenu;
 
         return $this;
     }
 
-    public function getContenu()
+    public function getContenu(): ?string
     {
         return $this->contenu;
     }
 
-    public function getNote()
+    public function getNote(): ?int
     {
         return $this->note;
     }
 
-    public function setNote($note)
+    public function setNote($note): self
     {
         $this->note = $note;
+
+        return $this;
     }
 
-    public function setFilm(\App\Entity\Film $film)
+    public function setFilm(\App\Entity\Film $film): self
     {
         $this->film = $film;
 
         return $this;
     }
 
-    public function getFilm()
+    public function getFilm(): Film
     {
         return $this->film;
     }
 
-    public function setUser(\App\Entity\User $user)
+    public function setUser(\App\Entity\User $user): self
     {
         $this->user = $user;
 
         return $this;
     }
 
-    public function getUser()
+    public function getUser(): User
     {
         return $this->user;
     }

+ 54 - 34
src/Entity/Film.php

@@ -3,6 +3,8 @@
 namespace App\Entity;
 
 use App\Repository\FilmRepository;
+use Doctrine\Common\Collections\Collection;
+use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
 
@@ -76,108 +78,116 @@ class Film
         $this->setDateSubmited(new \DateTime());
     }
 
-    public function getAuthered()
+    public function getAuthered(): ?User
     {
         return $this->authered;
     }
 
-    public function setAuthered(User $authered)
+    public function setAuthered(?User $authered): self
     {
         $this->authered = $authered;
+
+        return $this;
     }
 
-    public function getId()
+    public function getId(): int
     {
         return $this->id;
     }
 
-    public function setTitre($titre)
+    public function setTitre($titre): self
     {
         $this->titre = $titre;
 
         return $this;
     }
 
-    public function getTitre()
+    public function getTitre(): string
     {
         return $this->titre;
     }
 
-    public function setAnnee($annee)
+    public function setAnnee(?\DateTimeInterface $annee): self
     {
         $this->annee = $annee;
 
         return $this;
     }
 
-    public function getAnnee()
+    public function getAnnee(): ?\DateTimeInterface
     {
         return $this->annee;
     }
 
-    public function getLien()
+    public function getLien(): ?string
     {
         return $this->lien;
     }
 
-    public function setLien($lien = null)
+    public function setLien(?string $lien = null): self
     {
         $this->lien = $lien;
+
+        return $this;
     }
 
-    public function getDateSubmited()
+    public function getDateSubmited(): ?\DateTimeInterface
     {
         return $this->dateSubmited;
     }
 
-    public function setDateSubmited(\DateTime $dateSubmited)
+    public function setDateSubmited(?\DateTime $dateSubmited): self
     {
         $this->dateSubmited = $dateSubmited;
+
+        return $this;
     }
 
-    public function isNew()
+    public function isNew(): bool
     {
-        $finNew = $this->getDateSubmited()->modify('+1 day');
+        $finNew = (new \DateTime($this->getDateSubmited()->format("Y/m/d")))->modify('+1 day');
         return (new \DateTime('now') < $finNew);
     }
 
-    public function addCommentaire(\App\Entity\Commentaire $commentaire)
+    public function addCommentaire(\App\Entity\Commentaire $commentaire): self
     {
         $this->commentaires[] = $commentaire;
 
         return $this;
     }
 
-    public function removeCommentaire(\App\Entity\Commentaire $commentaire)
+    public function removeCommentaire(\App\Entity\Commentaire $commentaire): self
     {
         $this->commentaires->removeElement($commentaire);
 
         return $this;
     }
 
-    public function getCommentaires()
+    public function getCommentaires(): Collection
     {
         return $this->commentaires;
     }
 
-    public function addRealisateur(Realisateur $realisateur)
+    public function addRealisateur(Realisateur $realisateur): self
     {
         $this->realisateurs[] = $realisateur;
 
         return $this;
     }
 
-    public function removeRealisateur(Realisateur $realisateur)
+    public function removeRealisateur(Realisateur $realisateur):  self
     {
         $this->realisateurs->removeElement($realisateur);
+
+        return $this;
     }
 
-    public function getRealisateurs()
+    public function getRealisateurs(): Collection
     {
         return $this->realisateurs;
     }
 
-    public function addUserWantToView(User $user)
+    public function addUserWantToView(User $user): self
     {
         $this->usersWantToView[] = $user;
         $user->addFilm($this);
@@ -185,18 +195,20 @@ class Film
         return $this;
     }
 
-    public function removeUserWantToView(User $user)
+    public function removeUserWantToView(User $user): self
     {
         $this->usersWantToView->removeElement($user);
         $user->removeFilm($this);
+
+        return $this;
     }
 
-    public function getUsersWantToView()
+    public function getUsersWantToView(): Collection
     {
         return $this->usersWantToView;
     }
 
-    public function addUserWhoSeen(User $user)
+    public function addUserWhoSeen(User $user):self
     {
         $this->usersWhoSeen[] = $user;
         $user->addFilmVu($this);
@@ -204,52 +216,58 @@ class Film
         return $this;
     }
 
-    public function removeUserWhoSeen(User $user)
+    public function removeUserWhoSeen(User $user): self
     {
         $this->usersWhoSeen->removeElement($user);
         $user->removeFilmVu($this);
+
+        return $this;
     }
 
-    public function getUsersWhoSeen()
+    public function getUsersWhoSeen(): Collection
     {
         return $this->usersWhoSeen;
     }
 
-    public function getGenres()
+    public function getGenres(): Collection
     {
         return $this->genres;
     }
 
-    public function addGenre(Genre $genre)
+    public function addGenre(Genre $genre): self
     {
         $this->genres[] = $genre;
         return $this;
     }
 
-    public function removeGenre(Genre $genre)
+    public function removeGenre(Genre $genre): self
     {
         $this->genres->removeElement($genre);
         return $this;
     }
 
-    public function getNote()
+    public function getNote(): ?float
     {
         return $this->note;
     }
 
-    public function setNote($note)
+    public function setNote($note): self
     {
         $this->note = $note;
+
+        return $this;
     }
 
-    public function getNbComs()
+    public function getNbComs(): int
     {
         return $this->nbComs;
     }
 
-    public function setNbComs($nbComs)
+    public function setNbComs($nbComs): self
     {
         $this->nbComs = $nbComs;
+
+        return $this;
     }
 
     public function getInformation(): ?string
@@ -276,14 +294,16 @@ class Film
         return $this;
     }
 
-    public function getMediaVideo()
+    public function getMediaVideo(): ?MediaVideo
     {
         return $this->mediaVideo;
     }
 
-    public function setMediaVideo(MediaVideo $mediaVideo = null)
+    public function setMediaVideo(?MediaVideo $mediaVideo = null): self
     {
         $this->mediaVideo = $mediaVideo;
+
+        return $this;
     }
 
 

+ 3 - 3
src/Entity/Genre.php

@@ -18,19 +18,19 @@ class Genre
     #[ORM\Column(name: "name", type: "string", length: 191, unique: true)]
     private $name;
 
-    public function getId()
+    public function getId(): ?int
     {
         return $this->id;
     }
 
-    public function setName($name)
+    public function setName($name): self
     {
         $this->name = $name;
 
         return $this;
     }
 
-    public function getName()
+    public function getName(): string
     {
         return $this->name;
     }

+ 16 - 14
src/Entity/MediaVideo.php

@@ -40,48 +40,50 @@ class MediaVideo
     
     private $url;
 
-    public function getId()
+    public function getId(): ?int
     {
         return $this->id;
     }
 
-    public function getUrl()
+    public function getUrl(): ?string
     {
         return $this->url;
     }
 
-    public function setUrl($url)
+    public function setUrl($url): self
     {
-        return $this->url = $url;
+        $this->url = $url;
+
+        return $this;
     }
     
-    public function setType($type)
+    public function setType($type): self
     {
         $this->type = $type;
 
         return $this;
     }
 
-    public function getType()
+    public function getType(): ?string
     {
         return $this->type;
     }
     
-    public function setIdentif($identif)
+    public function setIdentif($identif): self
     {
         $this->identif = $identif;
 
         return $this;
     }
     
-    public function getIdentif()
+    public function getIdentif(): ?string
     {
         return $this->identif;
     }
 
     /////////////////////
     // Méthodes
-    private function peertubeId($url)
+    private function peertubeId($url): void
     {
         $tableau = explode("/", $url);
         $id = $tableau[count($tableau)-1];
@@ -89,7 +91,7 @@ class MediaVideo
         $this->setType('peertube');
     }
     
-    private function youtubeId($url)
+    private function youtubeId($url): void
     {
         $tableaux = explode("=", $url);  // découpe l’url en deux  avec le signe ‘=’
 
@@ -97,7 +99,7 @@ class MediaVideo
         $this->setType('youtube');  // signale qu’il s’agit d’une video youtube et l’inscrit dans l’attribut $type
     }
 
-    private function youtubeCourteId($url)
+    private function youtubeCourteId($url): void
     {
         $tableaux = explode("/", $url);  // on découpe l’url grâce au « / »
         $id = $tableaux[count($tableaux)-1];  // on retient la dernière partie qui contient l’identifiant
@@ -105,7 +107,7 @@ class MediaVideo
         $this->setType('youtube');  // signale qu’il s’agit d’une video youtube et l’inscrit dans l’attribut $type
     }
 
-    private function dailymotionId($url)
+    private function dailymotionId($url): void
     {
         $cas = explode("/", $url); // On sépare la première partie de l'url des 2 autres
         $idb = $cas[4];  // On récupère la partie qui nous intéressent
@@ -116,7 +118,7 @@ class MediaVideo
         $this->setType('dailymotion'); // signale qu’il s’agit d’une video dailymotion et l’inscrit dans l’attribut $type
     }
 
-    private function vimeoId($url)
+    private function vimeoId($url): void
     {
         $tableaux = explode("/", $url);  // on découpe l’url grâce au « / »
         $id = $tableaux[count($tableaux)-1];  // on reticent la dernière partie qui contient l’identifiant
@@ -128,7 +130,7 @@ class MediaVideo
     #[ORM\PreUpdate()]
     #[ORM\PreFlush()]
     
-    public function extractIdentif()
+    public function extractIdentif(): void
     {
         $url = $this->getUrl();  // on récupère l’url
 

+ 9 - 6
src/Entity/Realisateur.php

@@ -3,6 +3,7 @@
 namespace App\Entity;
 
 use App\Repository\RealisateurRepository;
+use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\Mapping as ORM;
 
 #[ORM\Table(name: "realisateur")]
@@ -22,7 +23,7 @@ class Realisateur
     #[ORM\ManyToMany(targetEntity: Film::class, mappedBy: "realisateurs", cascade: ["persist"])]
     private $films;
 
-    public function getId()
+    public function getId(): ?int
     {
         return $this->id;
     }
@@ -32,29 +33,31 @@ class Realisateur
         $this->films = new \Doctrine\Common\Collections\ArrayCollection();
     }
 
-    public function addFilm(\App\Entity\Film $film)
+    public function addFilm(\App\Entity\Film $film): self
     {
         $this->films[] = $film;
 
         return $this;
     }
 
-    public function removeFilm(\App\Entity\Film $film)
+    public function removeFilm(\App\Entity\Film $film): self
     {
         $this->films->removeElement($film);
+
+        return $this;
     }
 
-    public function getFilms()
+    public function getFilms(): Collection
     {
         return $this->films;
     }
 
-    public function getNomComplet ()
+    public function getNomComplet (): ?string
     {
         return $this->nomComplet;
     }
 
-    public function setNomComplet($nom)
+    public function setNomComplet($nom): self
     {
         $this->nomComplet = $nom;
 

+ 65 - 43
src/Entity/User.php

@@ -3,6 +3,7 @@
 namespace App\Entity;
 
 use App\Repository\UserRepository;
+use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Security\Core\User\UserInterface;
 use Symfony\Component\Validator\Constraints as Assert;
@@ -69,86 +70,96 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
     #[Assert\Type("DateTime")]
     private $lastActivity;
 
-    public function getLastActivity()
+    public function getLastActivity(): ?\DateTimeInterface
     {
         return $this->lastActivity;
     }
 
-    public function setLastActivity($lastActivity)
+    public function setLastActivity(?\DateTimeInterface $lastActivity): self
     {
         $this->lastActivity = $lastActivity;
+
+        return $this;
     }
 
-    public function isActiveNow()
+    public function isActiveNow(): bool
     {
         $delay = new \DateTime('5 minutes ago');
 
         return ( $this->getLastActivity() > $delay );
     }
 
-    public function getId()
+    public function getId(): ?int
     {
         return $this->id;
     }
 
-    public function setUsername($username)
+    public function setUsername($username): self
     {
         $this->username = $username;
 
         return $this;
     }
 
-    public function getUsername()
+    public function getUsername(): ?string
     {
         return (string) $this->username;
     }
 
-    public function getUserIdentifier()
+    public function getUserIdentifier(): ?string
     {
         return $this->username;
     }
 
-    public function setActivated($activated)
+    public function setActivated($activated): self
     {
         $this->isActive = $activated;
+
+        return $this;
     }
 
-    public function getActivated()
+    public function getActivated(): bool
     {
         return $this->isActive;
     }
 
-    public function getPrenom()
+    public function getPrenom(): ?string
     {
         return $this->prenom;
     }
 
-    public function setPrenom($prenom)
+    public function setPrenom($prenom): self
     {
         $this->prenom = $prenom;
+
+        return $this;
     }
 
-    public function getNom()
+    public function getNom(): ?string
     {
         return $this->nom;
     }
 
-    public function setNom($nom)
+    public function setNom($nom): self
     {
         $this->nom = $nom;
+
+        return $this;
     }
 
-    public function getMail()
+    public function getMail(): ?string
     {
         return $this->mail;
     }
 
-    public function setMail($mail)
+    public function setMail($mail): self
     {
         $this->mail = $mail;
+
+        return $this;
     }
 
-    public function setPassword($password)
+    public function setPassword($password): self
     {
         $this->password = $password;
 
@@ -160,24 +171,24 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
         return $this->password;
     }
 
-    public function setSalt($salt)
+    public function setSalt($salt): self
     {
         $this->salt = $salt;
 
         return $this;
     }
 
-    public function getSalt()
+    public function getSalt(): ?string
     {
         return $this->salt;
     }
 
-    public function getToken()
+    public function getToken(): ?string
     {
         return $this->token;
     }
 
-    public function setToken($token)
+    public function setToken($token): self
     {
         //$this->token = hash("sha512", uniqid());
         $this->token = $token;
@@ -186,37 +197,44 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
         return $this;
     }
 
-    public function getTokenValidity()
+    public function getTokenValidity(): ?\DateTimeInterface
     {
         return $this->tokenValidity;
     }
 
-    private function setTokenValidity(\DateTime $tokenValidity)
+    private function setTokenValidity(\DateTimeInterface $tokenValidity)
     {
         $this->tokenValidity = $tokenValidity;
 
         return $this;
     }
 
-    public function isValidToken()
+    public function isValidToken(): bool
     {
-        $expire = $this->getTokenValidity()->modify('+1 hour');
+        $expire = (new \DateTime($this->getTokenValidity()->format("Y-m-d H:i:s")))->modify('+1 hour');
+        dump($expire);
+        dump(new \DateTime('now'));
         return ( $expire > new \DateTime('now') );
     }
 
-    public function setRoles($roles)
+    public function setRoles($roles): self
     {
         $this->roles = $roles;
 
         return $this;
     }
 
-    public function getRoles()
+    /**
+     * @see UserInterface
+     */
+    public function getRoles(): array
     {
-        return $this->roles;
+        $roles = $this->roles;
+        return array_unique($roles);
+
     }
 
-    public function eraseCredentials()
+    public function eraseCredentials(): void
     {
 
     }
@@ -231,43 +249,47 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
 
     ///////////////////////////////////////////////////////////////
    
-    public function addFilm(\App\Entity\Film $film)
+    public function addFilm(\App\Entity\Film $film): self
     {
         $this->films[] = $film;
 
         return $this;
     }
 
-    public function removeFilm(\App\Entity\Film $film)
+    public function removeFilm(\App\Entity\Film $film): self
     {
         $this->films->removeElement($film);
+
+        return $this;
     }
 
-    public function getFilms()
+    public function getFilms(): Collection
     {
         return $this->films;
     }
 
     ///////////////////////////////////////////////////////////////////////////
 
-    public function addFilmVu(\App\Entity\Film $film)
+    public function addFilmVu(\App\Entity\Film $film): self
     {
         $this->filmsVus[] = $film;
 
         return $this;
     }
 
-    public function removeFilmVu(\App\Entity\Film $film)
+    public function removeFilmVu(\App\Entity\Film $film): self
     {
         $this->filmsVus->removeElement($film);
+
+        return $this;
     }
 
-    public function getFilmsVus()
+    public function getFilmsVus(): Collection
     {
         return $this->filmsVus;
     }
 
-    public function getNomComplet()
+    public function getNomComplet(): ?string
     {
         if ($this->prenom == null && $this->nom == null)
         {
@@ -276,27 +298,27 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
         return $this->getPrenom()." ".$this->getNom();
     }
 
-    public function isAccountNonExpired()
+    public function isAccountNonExpired(): bool
     {
         return true;
     }
 
-    public function isAccountNonLocked()
+    public function isAccountNonLocked(): bool
     {
         return true;
     }
 
-    public function isCredentialsNonExpired()
+    public function isCredentialsNonExpired(): bool
     {
         return true;
     }
 
-    public function isEnabled()
+    public function isEnabled(): bool
     {
         return $this->isActive;
     }
 
-    public function serialize()
+    public function serialize(): ?string
     {
         return serialize(array(
             $this->id,
@@ -308,7 +330,7 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
         ));
     }
 
-    public function unserialize($serialized)
+    public function unserialize($serialized):void 
     {
         list (
             $this->id,
@@ -321,12 +343,12 @@ class User implements UserInterface,PasswordAuthenticatedUserInterface
             ) = unserialize($serialized, array('allowed_classes' => false));
     }
 
-    public function wantToSee(Film $film)
+    public function wantToSee(Film $film): bool
     {
         return $this->getFilms()->contains($film);
     }
 
-    public function haveSeen(Film $film)
+    public function haveSeen(Film $film): bool
     {
         return $this->getFilmsVus()->contains($film);
     }

+ 2 - 1
src/Form/MediaVideoType.php

@@ -2,6 +2,7 @@
 
 namespace App\Form;
 
+use App\Entity\MediaVideo;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\Extension\Core\Type\TextType;
 use Symfony\Component\Form\FormBuilderInterface;
@@ -24,7 +25,7 @@ class MediaVideoType extends AbstractType
     public function configureOptions(OptionsResolver $resolver)
     {
         $resolver->setDefaults(array(
-            'data_class' => 'App\Entity\MediaVideo',
+            'data_class' => MediaVideo::class,
         ));
     }
 

+ 1 - 1
templates/security/mail_activate.html.twig

@@ -1,6 +1,6 @@
 Bonjour {{ user.nomComplet }},
 
-Votre compte est bien enregistré, merci de cliquer sur le lien suivant pour l'activer.
+Votre compte est bien enregistré, merci de cliquer sur le lien suivant pour l'activer (valable 1h)
 
 {{ lien }}
 

+ 1 - 1
templates/security/mail_tokenmdp.html.twig

@@ -1,6 +1,6 @@
 Bonjour {{ user.nomComplet }},
 
-Voici le lien pour modifier votre mot de passe. Il est valable 2 heures.
+Voici le lien pour modifier votre mot de passe. Il est valable 1 heure.
 
 {{ lien }}
 

+ 1 - 1
templates/security/password.html.twig

@@ -4,8 +4,8 @@
 {% block titre %}Changer de mot de passe{%  endblock %}
 
 {% block body %}
+    <h2>Vous pouvez changer de mot de passe ici</h2>
     <div class="d-flex justify-content-center">
-        <h2>Vous pouvez changer de mot de passe ici</h2>
         {{ form(form) }}
     </div>
 {% endblock %}