diff --git a/lib/OSM/Box.php b/lib/OSM/Box.php index c40e5b6..638bb3f 100644 --- a/lib/OSM/Box.php +++ b/lib/OSM/Box.php @@ -2,11 +2,8 @@ namespace OSM; -use OSM\Point; - -class Box { - +class Box +{ public Point $mininum; public Point $maximum; - } diff --git a/lib/OSM/Element/Element.php b/lib/OSM/Element/Element.php index d1fbe42..a3c8cbe 100644 --- a/lib/OSM/Element/Element.php +++ b/lib/OSM/Element/Element.php @@ -3,15 +3,15 @@ namespace OSM\Element; use OSM\Element\Member\Member; -use OSM\Element\Tag; - -class Element { +class Element +{ public ?int $id = null; public array $members = []; public array $tags = []; - public static function createFromArray($array) { + public static function createFromArray($array) + { assert(is_array($array)); $hasType = isset($array['type']); @@ -55,16 +55,18 @@ class Element { return $this; } - public function getTagValue(string $key): ?string { + public function getTagValue(string $key): ?string + { $foundTags = array_filter($this->tags, function ($tag) use ($key) { return $tag->key === $key; }); - if (count($foundTags) !== 1) { + if (1 !== count($foundTags)) { return null; } $tag = reset($foundTags); + return $tag->value; } } diff --git a/lib/OSM/Element/Member/Member.php b/lib/OSM/Element/Member/Member.php index 6e8cf22..2b1cc6f 100644 --- a/lib/OSM/Element/Member/Member.php +++ b/lib/OSM/Element/Member/Member.php @@ -2,12 +2,13 @@ namespace OSM\Element\Member; -class Member { - +class Member +{ public int $ref; public string $role; - public static function createFromArray($array) { + public static function createFromArray($array) + { assert(is_array($array)); $hasType = isset($array['type']); @@ -30,9 +31,9 @@ class Member { return $instance; } - - public function isSame(Member $other): bool { - return ($this->ref === $other->ref); - } + public function isSame(Member $other): bool + { + return $this->ref === $other->ref; + } } diff --git a/lib/OSM/Element/Member/Node.php b/lib/OSM/Element/Member/Node.php index daf3801..762dd3c 100644 --- a/lib/OSM/Element/Member/Node.php +++ b/lib/OSM/Element/Member/Node.php @@ -2,11 +2,10 @@ namespace OSM\Element\Member; -use OSM\Element\Member\Member; use OSM\Point; -class Node extends Member { - +class Node extends Member +{ public Point $point; public function completeFromArray(array $array): static @@ -15,5 +14,4 @@ class Node extends Member { return $this; } - } diff --git a/lib/OSM/Element/Member/Way.php b/lib/OSM/Element/Member/Way.php index 1f2ea19..67d094b 100644 --- a/lib/OSM/Element/Member/Way.php +++ b/lib/OSM/Element/Member/Way.php @@ -2,11 +2,10 @@ namespace OSM\Element\Member; -use OSM\Element\Member\Member; use OSM\Point; -class Way extends Member { - +class Way extends Member +{ public array $points = []; public function completeFromArray(array $array): static @@ -23,16 +22,20 @@ class Way extends Member { return $this; } - public function getFirstPoint(): Point { + public function getFirstPoint(): Point + { return reset($this->points); } - public function getLastPoint(): Point { + public function getLastPoint(): Point + { return end($this->points); } - public function reversePoints(): static { + public function reversePoints(): static + { $this->points = array_reverse($this->points); + return $this; } } diff --git a/lib/OSM/Element/Relation.php b/lib/OSM/Element/Relation.php index b9dfba0..55edcb4 100644 --- a/lib/OSM/Element/Relation.php +++ b/lib/OSM/Element/Relation.php @@ -2,50 +2,53 @@ namespace OSM\Element; -use OSM\Element\Element; use OSM\Element\Member\Way; use OSM\Point; -class Relation extends Element { - - public function getOuterWays(): array { +class Relation extends Element +{ + public function getOuterWays(): array + { return array_filter($this->members, function ($member) { - return ( - ($member instanceof \OSM\Element\Member\Way) - and ($member->role === 'outer') - ); + return + ($member instanceof Way) + and ('outer' === $member->role) + ; }); } - public function getOuterWaysStartingWith(Point $point, ?Way $exclude = null): array { + public function getOuterWaysStartingWith(Point $point, ?Way $exclude = null): array + { return array_filter($this->members, function ($member) use ($point, $exclude) { - return ( - ($member instanceof \OSM\Element\Member\Way) - and ($member->role === 'outer') - and ($point->isSame($member->getFirstPoint())) + return + ($member instanceof Way) + and ('outer' === $member->role) + and $point->isSame($member->getFirstPoint()) and ( is_null($exclude) or !$member->isSame($exclude) ) - ); + ; }); } - public function getOuterWaysStopingWith(Point $point, ?Way $exclude = null): array { + public function getOuterWaysStopingWith(Point $point, ?Way $exclude = null): array + { return array_filter($this->members, function ($member) use ($point, $exclude) { - return ( - ($member instanceof \OSM\Element\Member\Way) - and ($member->role === 'outer') - and ($point->isSame($member->getLastPoint())) + return + ($member instanceof Way) + and ('outer' === $member->role) + and $point->isSame($member->getLastPoint()) and ( is_null($exclude) or !$member->isSame($exclude) ) - ); + ; }); } - public function getOrderedOuterWays(): array { + public function getOrderedOuterWays(): array + { $orderedWays = []; $ways = $this->getOuterWays(); @@ -53,10 +56,10 @@ class Relation extends Element { $veryFirstPoint = $currentWay->getFirstPoint(); $isDone = false; while (!$isDone) { - $orderedWays[] = $currentWay; + $orderedWays[] = $currentWay; $nextWays = $this->getOuterWaysStartingWith($currentWay->getLastPoint(), $currentWay); assert(count($nextWays) <= 1); - if (count($nextWays) === 1) { + if (1 === count($nextWays)) { $nextWay = reset($nextWays); if ($veryFirstPoint->isSame($nextWay->getFirstPoint())) { break; @@ -64,9 +67,9 @@ class Relation extends Element { $currentWay = $nextWay; continue; } else { - $nextWays = $this->getOuterWaysStopingWith($currentWay->getLastPoint(), $currentWay); + $nextWays = $this->getOuterWaysStopingWith($currentWay->getLastPoint(), $currentWay); assert(count($nextWays) <= 1); - if (count($nextWays) === 1) { + if (1 === count($nextWays)) { $nextWay = reset($nextWays); $nextWay->reversePoints(); if ($veryFirstPoint->isSame($nextWay->getFirstPoint())) { @@ -82,5 +85,4 @@ class Relation extends Element { return $orderedWays; } - } diff --git a/lib/OSM/Element/Tag.php b/lib/OSM/Element/Tag.php index e35376d..395f6f1 100644 --- a/lib/OSM/Element/Tag.php +++ b/lib/OSM/Element/Tag.php @@ -2,16 +2,15 @@ namespace OSM\Element; -class Tag { - +class Tag +{ public ?string $key; public ?string $value; public static function createFromValues( string $key, - string $value - ): static - { + string $value, + ): static { $instance = new self(); $instance->key = $key; diff --git a/lib/OSM/GeoJsonConverter.php b/lib/OSM/GeoJsonConverter.php index 1df9b2a..73c6107 100644 --- a/lib/OSM/GeoJsonConverter.php +++ b/lib/OSM/GeoJsonConverter.php @@ -2,24 +2,22 @@ namespace OSM; -class GeoJsonConverter { - +class GeoJsonConverter +{ public static function convertRelationToPolygon( - \OSM\Element\Relation $relation - ): \GeoJson\Geometry\Polygon - { + Element\Relation $relation, + ): \GeoJson\Geometry\Polygon { $positions = []; foreach ($relation->getOrderedOuterWays() as $way) { foreach ($way->points as $point) { $positions[] = new \GeoJson\Geometry\Point([ $point->longitude, - $point->latitude + $point->latitude, ]); } } - return new \GeoJson\Geometry\Polygon([ $positions ]); + return new \GeoJson\Geometry\Polygon([$positions]); } - } diff --git a/lib/OSM/OSM.php b/lib/OSM/OSM.php index e6e5710..1841b7e 100644 --- a/lib/OSM/OSM.php +++ b/lib/OSM/OSM.php @@ -4,11 +4,12 @@ namespace OSM; use OSM\Element\Element; -class OSM { - +class OSM +{ public array $elements = []; - public static function createFromJson($json) { + public static function createFromJson($json) + { $array = json_decode($json, true); $instance = new self(); @@ -21,5 +22,4 @@ class OSM { return $instance; } - } diff --git a/lib/OSM/Point.php b/lib/OSM/Point.php index aaf8d94..bbe8951 100644 --- a/lib/OSM/Point.php +++ b/lib/OSM/Point.php @@ -2,8 +2,8 @@ namespace OSM; -class Point { - +class Point +{ public float $latitude; public float $longitude; @@ -20,11 +20,13 @@ class Point { return $instance; } - public function isSame(Point $other): bool { + public function isSame(Point $other): bool + { $isSame = ( ($other->latitude === $this->latitude) and ($other->longitude === $this->longitude) ); + return $isSame; } } diff --git a/src/Controller/BadgeController.php b/src/Controller/BadgeController.php index ddf5c5a..27cf753 100644 --- a/src/Controller/BadgeController.php +++ b/src/Controller/BadgeController.php @@ -3,7 +3,6 @@ namespace App\Controller; use App\Entity\Project; -use App\Entity\Task; use App\Service\TaskLifecycleManager; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -62,7 +61,7 @@ class BadgeController extends AbstractController $middle = floor(strlen($left) * $charWidth); $svg = $xml->createElement('svg'); - $svg->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns', 'http://www.w3.org/2000/svg'); + $svg->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.w3.org/2000/svg'); $svg->setAttribute('width', $totalWidth); $svg->setAttribute('height', $totalHeight); @@ -128,7 +127,7 @@ class BadgeController extends AbstractController echo $xml->saveXML(); }); + return $response; } - } diff --git a/src/Controller/ToolsController.php b/src/Controller/ToolsController.php index 6d4e761..4eb7bb8 100644 --- a/src/Controller/ToolsController.php +++ b/src/Controller/ToolsController.php @@ -4,14 +4,11 @@ namespace App\Controller; use App\Form\CityToolType; use App\Service\OverpassClient; -use KnpU\OAuth2ClientBundle\Client\ClientRegistry; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\HeaderUtils; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\Routing\Attribute\Route; @@ -29,8 +26,7 @@ class ToolsController extends AbstractController public function city( Request $request, OverpassClient $overpass, - ): Response - { + ): Response { $form = $this->createForm(CityToolType::class, []); $form->add('submit', SubmitType::class, ['label' => 'Générer']); @@ -44,7 +40,7 @@ class ToolsController extends AbstractController $response->headers->set('Content-Type', 'text/csv'); $response->headers->set( - 'Content-Disposition', + 'Content-Disposition', HeaderUtils::makeDisposition( HeaderUtils::DISPOSITION_ATTACHMENT, sprintf('cities-in-%d.csv', $areaId) @@ -78,13 +74,14 @@ class ToolsController extends AbstractController $name, $name, '', - json_encode(new \GeoJson\Feature\FeatureCollection([ $feature ])), + json_encode(new \GeoJson\Feature\FeatureCollection([$feature])), 'todo', ]); } fclose($csv); }); + return $response; } @@ -92,5 +89,4 @@ class ToolsController extends AbstractController 'form' => $form, ]); } - } diff --git a/src/Form/CityToolType.php b/src/Form/CityToolType.php index 7cac502..d0b7548 100644 --- a/src/Form/CityToolType.php +++ b/src/Form/CityToolType.php @@ -5,10 +5,8 @@ namespace App\Form; use App\Service\OverpassClient; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; -use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\Validator\Constraints\File; class CityToolType extends AbstractType { @@ -30,7 +28,7 @@ class CityToolType extends AbstractType $entries = explode("\n", $entries); foreach ($entries as $index => $entry) { $entry = explode("\t", $entry); - if ($index === 0) { + if (0 === $index) { $col = $entry; } else { if (count($col) === count($entry)) { @@ -45,7 +43,7 @@ class CityToolType extends AbstractType } $session->set('city_tool_choices', $choices); - + $builder ->add('area', ChoiceType::class, [ 'label' => 'Département', diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php index cbdd125..64f792a 100644 --- a/src/Repository/ProjectRepository.php +++ b/src/Repository/ProjectRepository.php @@ -3,7 +3,6 @@ namespace App\Repository; use App\Entity\Project; -use App\Entity\Task; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; diff --git a/src/Service/OverpassClient.php b/src/Service/OverpassClient.php index d928048..61d7fef 100644 --- a/src/Service/OverpassClient.php +++ b/src/Service/OverpassClient.php @@ -29,6 +29,7 @@ class OverpassClient return $response->getContent(); } + public function rawQuery($query) { $response = $this->client->request('GET', 'https://overpass-api.de/api/interpreter', [