Browse Source

php-cs-fixer

master
vincent 3 months ago
parent
commit
54ba5d1695
20 changed files with 73 additions and 97 deletions
  1. +1
    -4
      src/Controller/HomeController.php
  2. +6
    -5
      src/Controller/ProjectController.php
  3. +19
    -15
      src/Controller/TaskController.php
  4. +0
    -2
      src/DataFixtures/AppFixtures.php
  5. +1
    -2
      src/Entity/Project.php
  6. +7
    -8
      src/Entity/Task.php
  7. +1
    -3
      src/EventSubscriber/TaskLifecycleSubscriber.php
  8. +0
    -2
      src/Form/CommentType.php
  9. +1
    -2
      src/Form/CsvType.php
  10. +0
    -2
      src/Form/TaskLifecycleType.php
  11. +1
    -2
      src/Form/TaskType.php
  12. +2
    -3
      src/Repository/CommentRepository.php
  13. +5
    -6
      src/Repository/TaskRepository.php
  14. +7
    -8
      src/Security/OpenStreetMapAuthenticator.php
  15. +5
    -7
      src/Service/GeoJsonManager.php
  16. +4
    -5
      src/Service/OpenStreetMapClient.php
  17. +2
    -3
      src/Service/OsmoseClient.php
  18. +5
    -6
      src/Service/OverpassClient.php
  19. +1
    -3
      src/Service/SourceGenerator.php
  20. +5
    -9
      src/Service/TaskLifecycleManager.php

+ 1
- 4
src/Controller/HomeController.php View File

@ -3,7 +3,6 @@
namespace App\Controller;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
@ -41,7 +40,7 @@ class HomeController extends AbstractController
return $clientRegistry
->getClient('openstreetmap') // cf `config/packages/knpu_oauth2_client.yaml`
->redirect([
'read_prefs', // TODO est-ce qu’on a même besoin de ça ?
'read_prefs', // TODO est-ce qu’on a même besoin de ça ?
]);
}
@ -69,6 +68,4 @@ class HomeController extends AbstractController
{
return $security->logout();
}
}

+ 6
- 5
src/Controller/ProjectController.php View File

@ -18,7 +18,6 @@ use Symfony\Component\Routing\Attribute\Route;
#[Route('/project')]
class ProjectController extends AbstractController
{
// Page des projets, où l'on voit tous les projets
#[Route('/', name: 'app_project')]
public function index(EntityManagerInterface $entityManager): Response
@ -77,7 +76,7 @@ class ProjectController extends AbstractController
$randomTask = $entityManager->getRepository(Task::class)->findRandomByProject($project, Task::STATUS_TODO); // Trouve la tâche à faire que l’on piochera
$csvForm = $this->createForm(CsvType::class, null, [
'action' => $this->generateUrl('app_project_import', ['slug' => $slug])
'action' => $this->generateUrl('app_project_import', ['slug' => $slug]),
]);
$csvForm->add('submit', SubmitType::class, ['label' => 'Importer']);
@ -178,7 +177,7 @@ class ProjectController extends AbstractController
]);
}
// La suppression d’un projet passe par là
// La suppression d’un projet passe par là
#[Route('/{slug}/remove', name: 'app_project_remove')]
public function remove(EntityManagerInterface $entityManager, $slug): Response
{
@ -212,20 +211,23 @@ class ProjectController extends AbstractController
if (!$project) {
$this->addFlash('warning', 'Projet non trouvé !');
return $this->redirectToRoute('app_project');
}
if (!$project->hasOverpassQuery()) {
$this->addFlash('warning', 'Ce projet n’a pas de requête Overpass !');
return $this->redirectToRoute('app_project_show', ['slug' => $project->getSlug()]);
}
if ($project->hasOverpassResult() and !$project->isOverpassResultOutdated()) {
$this->addFlash('warning', 'Merci d’attendre un peu avant de requêter de nouveau Overpass !');
return $this->redirectToRoute('app_project_show', ['slug' => $project->getSlug()]);
}
$result = $overpassClient->query($project->getOverpassQuery());
$result = $overpassClient->query($project->getOverpassQuery());
$project->setOverpassResult($result);
@ -234,5 +236,4 @@ class ProjectController extends AbstractController
return $this->redirectToRoute('app_project_show', ['slug' => $project->getSlug()]);
}
}

+ 19
- 15
src/Controller/TaskController.php View File

@ -8,7 +8,6 @@ use App\Entity\Task;
use App\Form\CommentType;
use App\Form\TaskType;
use App\Service\GeoJsonManager;
use App\Service\OpenStreetMapClient;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -24,12 +23,13 @@ use Symfony\Component\Workflow\WorkflowInterface;
#[Route('/task')]
class TaskController extends AbstractController
{
// Page de créatiom d’une tâche
// Page de créatiom d’une tâche
#[Route('/create', name: 'app_task_create')]
public function create(Request $request, EntityManagerInterface $entityManager): Response
{
if (!$request->query->has('slug')) {
$this->addFlash( 'warning', 'Projet non spécifié !');
$this->addFlash('warning', 'Projet non spécifié !');
return $this->redirectToRoute('app_project');
}
@ -39,7 +39,8 @@ class TaskController extends AbstractController
$project = $repository->findOneBySlug($slug);
if (!$project) {
$this->addFlash( 'warning', 'Projet non trouvé !');
$this->addFlash('warning', 'Projet non trouvé !');
return $this->redirectToRoute('app_project');
}
@ -70,13 +71,12 @@ class TaskController extends AbstractController
}
}
return $this->render('task/create.html.twig', [
'project' => $project,
'create_form' => $createForm,
]);
}
// Page spécifique à une tâche, où l’on trouve tout ce qui la concerne
#[Route('/{slug}', name: 'app_task_show')]
public function show(Request $request, EntityManagerInterface $entityManager, GeoJsonManager $geoJsonManager, $slug): Response
@ -90,6 +90,7 @@ class TaskController extends AbstractController
if (!$request->headers->has('Referer')) {
throw $this->createNotFoundException('Task not found');
}
return $this->redirect($request->headers->get('Referer'));
}
@ -135,8 +136,8 @@ class TaskController extends AbstractController
'left' => $bbox['minx'],
'right' => $bbox['maxx'],
'changeset_comment' => sprintf('%s %s', $project->getName(), $task->getName()),
'changeset_source' => $project->getSource(),
'changeset_hashtags' => $project->getHashtags(),
'changeset_source' => $project->getSource(),
'changeset_hashtags' => $project->getHashtags(),
];
}
@ -177,9 +178,8 @@ class TaskController extends AbstractController
try {
$entityManager->persist($comment);
$entityManager->flush();
} catch (\Exception $exception) {
$this->addFlash('danger', 'Impossible de commenter ! ' . $exception->getMessage());
$this->addFlash('danger', 'Impossible de commenter ! '.$exception->getMessage());
}
}
@ -234,13 +234,13 @@ class TaskController extends AbstractController
if (!$task) {
$this->addFlash('warning', 'Tâche non trouvée !');
return $this->redirect($request->headers->get('Referer'));
}
$project = $task->getProject();
try {
$entityManager->remove($task);
$entityManager->flush();
@ -260,6 +260,7 @@ class TaskController extends AbstractController
if (!$task) {
$this->addFlash('warning', 'Tâche non trouvée !');
return $this->redirectToRoute('app_project');
}
@ -317,6 +318,7 @@ class TaskController extends AbstractController
if (!$request->headers->has('Referer')) {
throw $this->createNotFoundException('Task not found');
}
return $this->redirect($request->headers->get('Referer'));
}
@ -346,6 +348,7 @@ class TaskController extends AbstractController
if (!$request->headers->has('Referer')) {
throw $this->createNotFoundException('Task not found');
}
return $this->redirect($request->headers->get('Referer'));
}
@ -383,6 +386,7 @@ class TaskController extends AbstractController
'warning',
'Tâche non trouvée !'
);
return $this->redirect($request->headers->get('referer'));
}
@ -401,7 +405,7 @@ class TaskController extends AbstractController
return $response;
}
// Renvoie la liste des tâches du projet sous forme de CSV (ce qui devrait
// corresponddre à ce que l’on a pu importer)
#[Route('/download/{slug}.csv', name: 'app_task_csv')]
@ -412,6 +416,7 @@ class TaskController extends AbstractController
if (!$project) {
$this->addFlash('warning', 'Projet non trouvé !');
return $this->redirect($request->headers->get('referer'));
}
@ -428,9 +433,9 @@ class TaskController extends AbstractController
'status',
]
);
foreach($project->getTasks() as $task) {
foreach ($project->getTasks() as $task) {
fputcsv(
$output,
$output,
[
$task->getName(),
$task->getDescription(),
@ -452,5 +457,4 @@ class TaskController extends AbstractController
return $response;
}
}

+ 0
- 2
src/DataFixtures/AppFixtures.php View File

@ -2,9 +2,7 @@
namespace App\DataFixtures;
use App\Entity\Project;
use App\Entity\Tag;
use App\Entity\Task;
use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;


+ 1
- 2
src/Entity/Project.php View File

@ -271,11 +271,10 @@ class Project
$generatedAt = new \DateTimeImmutable($data['osm3s']['timestamp_osm_base']);
$now = new \DateTimeImmutable('now');
$minimum = new \DateInterval('PT5M');
$minimum = new \DateInterval('PT5M');
$isOutdated = ($generatedAt->add($minimum) < $now);
return $isOutdated;
}
}

+ 7
- 8
src/Entity/Task.php View File

@ -14,14 +14,14 @@ use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: TaskRepository::class)]
class Task
{
const STATUS_TODO = 'todo';
const STATUS_DOING = 'doing';
const STATUS_DONE = 'done';
public const STATUS_TODO = 'todo';
public const STATUS_DOING = 'doing';
public const STATUS_DONE = 'done';
const TRANSITION_START = 'start';
const TRANSITION_FINISH = 'finish';
const TRANSITION_CANCEL = 'cancel';
const TRANSITION_RESET = 'reset';
public const TRANSITION_START = 'start';
public const TRANSITION_FINISH = 'finish';
public const TRANSITION_CANCEL = 'cancel';
public const TRANSITION_RESET = 'reset';
#[ORM\Id]
#[ORM\GeneratedValue]
@ -351,5 +351,4 @@ class Task
return $this;
}
}

+ 1
- 3
src/EventSubscriber/TaskLifecycleSubscriber.php View File

@ -19,7 +19,6 @@ use Twig\Environment;
// circonstances
class TaskLifecycleSubscriber implements EventSubscriberInterface
{
public function __construct(
protected EntityManagerInterface $entityManager,
protected Environment $twig,
@ -78,7 +77,7 @@ class TaskLifecycleSubscriber implements EventSubscriberInterface
}
$event->setBlocked(false);
}
}
// Cas où on commence une tâche
public function onStart(Event $event): void
@ -130,5 +129,4 @@ class TaskLifecycleSubscriber implements EventSubscriberInterface
EnteredEvent::getName('task_lifecycle', Task::STATUS_DONE) => 'onDone',
];
}
}

+ 0
- 2
src/Form/CommentType.php View File

@ -3,8 +3,6 @@
namespace App\Form;
use App\Entity\Comment;
use App\Entity\Task;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;


+ 1
- 2
src/Form/CsvType.php View File

@ -5,7 +5,6 @@ namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\File;
class CsvType extends AbstractType
@ -24,7 +23,7 @@ class CsvType extends AbstractType
'text/plain',
],
'mimeTypesMessage' => 'Type MIME inattendu',
])
]),
],
'help' => 'Fichier CSV classique (encodé en UTF8, séparé par des virgules, entouré avec des doubles guillemets, échappé avec des barres obliques et avec des retours chariots UNIX) contenant une ligne de noms de colonnes « name,description,osm,geojson,status » et enfin dans la colonne « status » la valeur « todo », « doing » ou « done ».',
])


+ 0
- 2
src/Form/TaskLifecycleType.php View File

@ -2,12 +2,10 @@
namespace App\Form;
use App\Entity\Task;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Workflow\WorkflowInterface;
use Symfony\Component\DependencyInjection\Attribute\Target;
class TaskLifecycleType extends AbstractType
{


+ 1
- 2
src/Form/TaskType.php View File

@ -3,7 +3,6 @@
namespace App\Form;
use App\Entity\Task;
use App\Form\TaskLifecycleType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
@ -33,7 +32,7 @@ class TaskType extends AbstractType
'help' => 'XML décrivant ce qu’il faut charger dans la feuille de données de JOSM (cf <a href="https://wiki.openstreetmap.org/wiki/FR:OSM_XML" target="_blank">FR:OSM XML - OpenStreetMap Wiki</a>)',
])
->add('status', TaskLifecycleType::class, [
'label' => 'État'
'label' => 'État',
])
->add('urgent', null, [
'label' => 'Urgence',


+ 2
- 3
src/Repository/CommentRepository.php View File

@ -2,9 +2,8 @@
namespace App\Repository;
use App\Entity\Task;
use App\Entity\Project;
use App\Entity\Comment;
use App\Entity\Project;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@ -30,7 +29,7 @@ class CommentRepository extends ServiceEntityRepository
->orderBy('c.createdAt', 'DESC')
->getQuery()
->getResult()
;
;
}
// public function findOneBySomeField($value): ?Comment


+ 5
- 6
src/Repository/TaskRepository.php View File

@ -9,7 +9,7 @@ use Doctrine\Persistence\ManagerRegistry;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* @extends ServiceEntityRepository<Task>
*/
@ -76,7 +76,7 @@ class TaskRepository extends ServiceEntityRepository
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
;
;
}
public function findRandomByProject(Project $project, $status = null)
@ -92,11 +92,10 @@ class TaskRepository extends ServiceEntityRepository
$tasks = $qb->getQuery()
->getResult()
;
;
shuffle($tasks);
return reset($tasks);
}
return reset($tasks);
}
}

+ 7
- 8
src/Security/OpenStreetMapAuthenticator.php View File

@ -2,7 +2,7 @@
namespace App\Security;
use App\Entity\User;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use KnpU\OAuth2ClientBundle\Security\Authenticator\OAuth2Authenticator;
@ -17,19 +17,18 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
class OpenStreetMapAuthenticator extends OAuth2Authenticator implements AuthenticationEntrypointInterface
class OpenStreetMapAuthenticator extends OAuth2Authenticator implements AuthenticationEntryPointInterface
{
public function __construct(
private ClientRegistry $clientRegistry,
private EntityManagerInterface $entityManager,
private RouterInterface $router,
)
{
) {
}
public function supports(Request $request): ?bool
{
return $request->attributes->get('_route') === 'app_osm_callback';
return 'app_osm_callback' === $request->attributes->get('_route');
}
public function authenticate(Request $request): Passport
@ -41,7 +40,7 @@ class OpenStreetMapAuthenticator extends OAuth2Authenticator implements Authenti
$session->set('access_token', $accessToken);
return new SelfValidatingPassport(
new UserBadge($accessToken->getToken(), function() use ($accessToken, $client) {
new UserBadge($accessToken->getToken(), function () use ($accessToken, $client) {
$resourceOwner = $client->fetchUserFromToken($accessToken);
$existingUser = $this->entityManager->getRepository(User::class)->findOneBy(['osmId' => $resourceOwner->getId()]);
@ -72,8 +71,8 @@ class OpenStreetMapAuthenticator extends OAuth2Authenticator implements Authenti
{
return null;
}
public function start(Request $request, AuthenticationException $authException = null): Response
public function start(Request $request, ?AuthenticationException $authException = null): Response
{
return new RedirectResponse(
'/',


+ 5
- 7
src/Service/GeoJsonManager.php View File

@ -10,7 +10,6 @@ use Symfony\Component\Workflow\WorkflowInterface;
class GeoJsonManager
{
public function __construct(
private UrlGeneratorInterface $router,
private WorkflowInterface $taskLifecycleStateMachine,
@ -32,12 +31,12 @@ class GeoJsonManager
if (!isset($data['features']) or empty($data['features'])) {
return null;
}
}
foreach($data['features'] as $index => $feature) {
foreach ($data['features'] as $index => $feature) {
if (!isset($feature['properties'])) {
continue;
}
}
$feature['properties'] = array_merge($feature['properties'], [
'name' => $task->getName(),
'url' => $this->router->generate('app_task_show', ['slug' => $task->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),
@ -45,12 +44,12 @@ class GeoJsonManager
]);
$data['features'][$index] = $feature;
}
return $data;
}
// Produit le geojson d’un projet ou d’une tâche de façon transparente pour simplifier
public function generateGeoJson($entity)
public function generateGeoJson($entity)
{
$geoJsons = [];
@ -72,5 +71,4 @@ class GeoJsonManager
return $geoJsons;
}
}

+ 4
- 5
src/Service/OpenStreetMapClient.php View File

@ -7,8 +7,8 @@ use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\HttpClient\HttpClientInterface;
// Fournit un accès à l’API OSM
class OpenStreetMapClient {
class OpenStreetMapClient
{
public function __construct(
private ClientRegistry $clientRegistry,
private HttpClientInterface $client,
@ -28,12 +28,12 @@ class OpenStreetMapClient {
*/
$token = $accessToken->getToken();
$response = $this->client->request($method, 'https://api.openstreetmap.org/api/0.6/' . $path, [
$response = $this->client->request($method, 'https://api.openstreetmap.org/api/0.6/'.$path, [
'auth_bearer' => $token,
'query' => $params,
]);
$isStatusCodeOk = ($response->getStatusCode() === 200);
$isStatusCodeOk = (200 === $response->getStatusCode());
if (!$isStatusCodeOk) {
throw new \RuntimeException();
@ -81,5 +81,4 @@ class OpenStreetMapClient {
return $changesets;
}
}

+ 2
- 3
src/Service/OsmoseClient.php View File

@ -22,11 +22,10 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
// Fournira un accès à l’API Osmose si nécessaire (histoire de vérifier qu’on a
// pas trop oublié de tenir compte de la validation côté JOSM lors de la
// contribution sur une tâche ?)
class OsmoseClient {
class OsmoseClient
{
public function __construct(
private HttpClientInterface $client,
) {
}
}

+ 5
- 6
src/Service/OverpassClient.php View File

@ -5,8 +5,8 @@ namespace App\Service;
use Symfony\Contracts\HttpClient\HttpClientInterface;
// Founit un accès à l’API Overpass
class OverpassClient {
class OverpassClient
{
public function __construct(
private HttpClientInterface $client,
) {
@ -16,12 +16,12 @@ class OverpassClient {
{
$response = $this->client->request('GET', 'https://overpass-api.de/api/interpreter', [
'query' => [
'data' => $prefix . $query . $suffix,
'data' => $prefix.$query.$suffix,
],
]);
$isStatusCodeOk = ($response->getStatusCode() === 200);
$isContentTypeJson = ($response->getHeaders()['content-type'][0] === 'application/json');
$isStatusCodeOk = (200 === $response->getStatusCode());
$isContentTypeJson = ('application/json' === $response->getHeaders()['content-type'][0]);
if (!$isStatusCodeOk or !$isContentTypeJson) {
throw new \RuntimeException();
@ -29,5 +29,4 @@ class OverpassClient {
return $response->getContent();
}
}

+ 1
- 3
src/Service/SourceGenerator.php View File

@ -7,7 +7,6 @@ use App\Entity\Task;
// Génère la source de changeset
class SourceGenerator
{
public function generate(Task $task): string
{
$parts = [];
@ -17,7 +16,7 @@ class SourceGenerator
$parts[] = $project->getName();
$parts[] = $task->getName();
foreach(explode(' ', $project->getHashtags()) as $hashtag) {
foreach (explode(' ', $project->getHashtags()) as $hashtag) {
$parts[] = $hashtag;
}
@ -25,5 +24,4 @@ class SourceGenerator
return $source;
}
}

+ 5
- 9
src/Service/TaskLifecycleManager.php View File

@ -9,7 +9,6 @@ use Symfony\Component\Workflow\WorkflowInterface;
// Utilistaire pour récupérer facilement les stats de réalisation d’un projet ou d’une tâche
class TaskLifecycleManager
{
public function __construct(
private WorkflowInterface $taskLifecycleStateMachine,
) {
@ -41,13 +40,12 @@ class TaskLifecycleManager
}
$max = 0;
foreach ($project->getTasks() as $task)
{
$stats[$task->getStatus()]['value'] += 1;
$max += 1;
foreach ($project->getTasks() as $task) {
++$stats[$task->getStatus()]['value'];
++$max;
}
if ($max === 0) {
if (0 === $max) {
return $stats;
}
@ -56,10 +54,8 @@ class TaskLifecycleManager
$data['percentage'] = ((float) $data['value'] * 100.0) / $max;
return $data;
}, $stats);
}, $stats);
return $stats;
}
}

Loading…
Cancel
Save