Browse Source

php-cs-fixer

master
vincent 6 days ago
parent
commit
8edd3a950e
15 changed files with 85 additions and 90 deletions
  1. +2
    -5
      lib/OSM/Box.php
  2. +8
    -6
      lib/OSM/Element/Element.php
  3. +8
    -7
      lib/OSM/Element/Member/Member.php
  4. +2
    -4
      lib/OSM/Element/Member/Node.php
  5. +9
    -6
      lib/OSM/Element/Member/Way.php
  6. +28
    -26
      lib/OSM/Element/Relation.php
  7. +4
    -5
      lib/OSM/Element/Tag.php
  8. +6
    -8
      lib/OSM/GeoJsonConverter.php
  9. +4
    -4
      lib/OSM/OSM.php
  10. +5
    -3
      lib/OSM/Point.php
  11. +2
    -3
      src/Controller/BadgeController.php
  12. +4
    -8
      src/Controller/ToolsController.php
  13. +2
    -4
      src/Form/CityToolType.php
  14. +0
    -1
      src/Repository/ProjectRepository.php
  15. +1
    -0
      src/Service/OverpassClient.php

+ 2
- 5
lib/OSM/Box.php View File

@ -2,11 +2,8 @@
namespace OSM;
use OSM\Point;
class Box {
class Box
{
public Point $mininum;
public Point $maximum;
}

+ 8
- 6
lib/OSM/Element/Element.php View File

@ -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;
}
}

+ 8
- 7
lib/OSM/Element/Member/Member.php View File

@ -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;
}
}

+ 2
- 4
lib/OSM/Element/Member/Node.php View File

@ -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;
}
}

+ 9
- 6
lib/OSM/Element/Member/Way.php View File

@ -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;
}
}

+ 28
- 26
lib/OSM/Element/Relation.php View File

@ -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;
}
}

+ 4
- 5
lib/OSM/Element/Tag.php View File

@ -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;


+ 6
- 8
lib/OSM/GeoJsonConverter.php View File

@ -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]);
}
}

+ 4
- 4
lib/OSM/OSM.php View File

@ -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;
}
}

+ 5
- 3
lib/OSM/Point.php View File

@ -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;
}
}

+ 2
- 3
src/Controller/BadgeController.php View File

@ -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;
}
}

+ 4
- 8
src/Controller/ToolsController.php View File

@ -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,
]);
}
}

+ 2
- 4
src/Form/CityToolType.php View File

@ -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',


+ 0
- 1
src/Repository/ProjectRepository.php View File

@ -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;


+ 1
- 0
src/Service/OverpassClient.php View File

@ -29,6 +29,7 @@ class OverpassClient
return $response->getContent();
}
public function rawQuery($query)
{
$response = $this->client->request('GET', 'https://overpass-api.de/api/interpreter', [


Loading…
Cancel
Save