Corrections séance F
<?php
abstract class VehiculeAMoteur
{
protected string $typeMoteur;
protected int $nbPassagers;
protected static int $nbVehicules = 0;
public function __construct(string $typeMoteur, int $nbPassagers)
{
$this->verificationtype($typeMoteur);
$this->verificationnbpassagers($nbPassagers);
$this->typeMoteur = $typeMoteur;
$this->nbPassagers = $nbPassagers;
self::$nbVehicules++;
}
public function setypeMoteur(string $typeMoteur): void
{
$this->verificationtype($typeMoteur);
$this->typeMoteur = $typeMoteur;
}
protected function verificationtype(string $type): void
{
if ($type !== 'T' && $type !== 'E') {
throw new \InvalidArgumentException("Type moteur invalide : doit être 'T' ou 'E'.");
}
}
protected function verificationnbpassagers(int $nombre): void
{
if ($nombre < 1) {
throw new \InvalidArgumentException("Le nombre de passagers doit être un entier positif.");
}
}
public static function getNbVehicules(): int
{
return self::$nbVehicules;
}
public function getTypeMoteur(): string
{
return $this->typeMoteur;
}
public function getNbPassagers(): int
{
return $this->nbPassagers;
}
}
Mis à jour