Add PHPStan project with level 1.

This commit is contained in:
Pol Dellaiera
2021-11-09 11:31:20 +00:00
committed by Julien Fastré
parent 94e84fbdf0
commit e2ab3bfc6e
8 changed files with 827 additions and 35 deletions

View File

@@ -97,9 +97,9 @@ class CalendarController extends AbstractController
'calendarItems' => $calendarItems,
'user' => $user
]);
}
} elseif ($accompanyingPeriod instanceof AccompanyingPeriod) {
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$total = $this->calendarRepository->countByAccompanyingPeriod($accompanyingPeriod);
$paginator = $this->paginator->create($total);
$calendarItems = $this->calendarRepository->findBy(
@@ -117,6 +117,8 @@ class CalendarController extends AbstractController
'paginator' => $paginator
]);
}
throw new \Exception('Unable to list actions.');
}
/**

View File

@@ -145,5 +145,7 @@ class DocGeneratorTemplateController extends AbstractController
} catch (TransferException $e) {
throw $e;
}
throw new \Exception('Unable to generate document.');
}
}

View File

@@ -504,6 +504,8 @@ class ApiController extends AbstractCRUDController
$this->getContextForSerializationPostAlter($action, $request, $_format, $entity, [$postedData])
);
}
throw new \Exception('Unable to handle such request method.');
}
/**

View File

@@ -4,13 +4,9 @@ namespace Chill\MainBundle\Doctrine\Model;
use \JsonSerializable;
/**
* Description of Point
*
*/
class Point implements JsonSerializable {
private ?float $lat = null;
private ?float $lon = null;
private ?float $lat;
private ?float $lon;
public static string $SRID = '4326';
private function __construct(?float $lon, ?float $lat)
@@ -22,6 +18,7 @@ class Point implements JsonSerializable {
public function toGeoJson(): string
{
$array = $this->toArrayGeoJson();
return \json_encode($array);
}
@@ -33,60 +30,53 @@ class Point implements JsonSerializable {
public function toArrayGeoJson(): array
{
return [
"type" => "Point",
"coordinates" => [ $this->lon, $this->lat ]
'type' => 'Point',
'coordinates' => [$this->lon, $this->lat],
];
}
/**
*
* @return string
*/
public function toWKT(): string
{
return 'SRID='.self::$SRID.';POINT('.$this->lon.' '.$this->lat.')';
return sprintf("SRID=%s;POINT(%s %s)", self::$SRID, $this->lon, $this->lat);
}
/**
*
* @param type $geojson
* @return Point
*/
public static function fromGeoJson(string $geojson): Point
public static function fromGeoJson(string $geojson): self
{
$a = json_decode($geojson);
//check if the geojson string is correct
if (NULL === $a or !isset($a->type) or !isset($a->coordinates)){
if (null === $a) {
throw PointException::badJsonString($geojson);
}
if ($a->type != 'Point'){
if (null === $a->type || null === $a->coordinates) {
throw PointException::badJsonString($geojson);
}
if ($a->type !== 'Point'){
throw PointException::badGeoType();
}
$lat = $a->coordinates[1];
$lon = $a->coordinates[0];
[$lon, $lat] = $a->coordinates;
return Point::fromLonLat($lon, $lat);
}
public static function fromLonLat(float $lon, float $lat): Point
public static function fromLonLat(float $lon, float $lat): self
{
if (($lon > -180 && $lon < 180) && ($lat > -90 && $lat < 90))
{
if (($lon > -180 && $lon < 180) && ($lat > -90 && $lat < 90)) {
return new Point($lon, $lat);
} else {
throw PointException::badCoordinates($lon, $lat);
}
throw PointException::badCoordinates($lon, $lat);
}
public static function fromArrayGeoJson(array $array): Point
public static function fromArrayGeoJson(array $array): self
{
if ($array['type'] == 'Point' &&
isset($array['coordinates']))
{
if ($array['type'] === 'Point' && isset($array['coordinates'])) {
return self::fromLonLat($array['coordinates'][0], $array['coordinates'][1]);
}
throw new \Exception('Unable to build a point from input data.');
}
public function getLat(): float

View File

@@ -98,5 +98,7 @@ class PasswordRecoverVoter extends Voter
return true;
}
return false;
}
}