diff --git a/.github/workflows/dev.yml b/.github/workflows/deploy-backend-dev.yml similarity index 52% rename from .github/workflows/dev.yml rename to .github/workflows/deploy-backend-dev.yml index 86e88da..31008fb 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/deploy-backend-dev.yml @@ -1,9 +1,15 @@ -name: SSH Upload and Composer Install on DEV +name: Upload backend to dev server and lint on: push: branches: - dev + pull_request: + branches: + - dev + +env: + FLUTTER_VERSION: 3.10.1 jobs: deploy: @@ -21,7 +27,13 @@ jobs: - name: Upload PHP code run: scp -o StrictHostKeyChecking=no -r * ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }}:/home/julesartd/www/api-dev-edt-3il - - name: SSH into server and run composer install + + install_dependencies: + needs: deploy + runs-on: ubuntu-latest + + steps: + - name: SSH Into Server and Install Composer Dependencies uses: appleboy/ssh-action@master with: host: ${{ secrets.SERVER_HOST }} @@ -29,4 +41,17 @@ jobs: key: ${{ secrets.SSH_PRIVATE_KEY }} script: | cd /home/julesartd/www/api-dev-edt-3il/backend - composer2 install \ No newline at end of file + composer2 install + + - name: SSH Into Server and execute Linter for PHP + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: | + cd /home/julesartd/www/api-dev-edt-3il/backend + vendor/bin/php-cs-fixer fix src + + + \ No newline at end of file diff --git a/.github/workflows/execute-linter-front.yml b/.github/workflows/execute-linter-front.yml new file mode 100644 index 0000000..a0bd504 --- /dev/null +++ b/.github/workflows/execute-linter-front.yml @@ -0,0 +1,39 @@ +name: Execute Lint and Format + +concurrency: + group: $-$ + cancel-in-progress: true + +on: + push: + branches: + - main + - dev + pull_request: + branches: + - main + - dev + +env: + FLUTTER_VERSION: 3.19.2 + +jobs: + format-lint: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup Flutter + uses: subosito/flutter-action@v2 + with: + cache: true + cache-key: ":os:-modules-:hash:" + channel: "stable" + flutter-version: ${{ env.FLUTTER_VERSION }} + + - name: Formatting + run: dart --disable-analytics format --set-exit-if-changed frontend/app_student/lib + + - name: Lint + run: flutter analyze lib \ No newline at end of file diff --git a/backend/.gitignore b/backend/.gitignore index a67f91e..3260930 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -8,3 +8,8 @@ /var/ /vendor/ ###< symfony/framework-bundle ### + +###> friendsofphp/php-cs-fixer ### +/.php-cs-fixer.php +/.php-cs-fixer.cache +###< friendsofphp/php-cs-fixer ### diff --git a/backend/.php-cs-fixer.dist.php b/backend/.php-cs-fixer.dist.php new file mode 100644 index 0000000..3788194 --- /dev/null +++ b/backend/.php-cs-fixer.dist.php @@ -0,0 +1,13 @@ +in(__DIR__) + ->exclude('var') +; + +return (new PhpCsFixer\Config()) + ->setRules([ + '@Symfony' => true, + ]) + ->setFinder($finder) +; diff --git a/backend/README.md b/backend/README.md index dcb680b..76eadbb 100644 --- a/backend/README.md +++ b/backend/README.md @@ -18,7 +18,6 @@ Pour installer l'API et ses dépendances, suivez les étapes ci-dessous : 3. Exécutez la commande `composer install` pour installer toutes les dépendances nécessaires. - ## Endpoints L'API offre les endpoints suivants : @@ -26,6 +25,8 @@ L'API offre les endpoints suivants : - `/api/timetable?class_param=XX` : Permet de récupérer l'emploi du temps d'une classe spécifique. - `/api/classes` : Permet de récupérer la liste des classes disponibles. +Vous pouvez retrouver la spécification OpenApi à la racine du projet Symfony + ## Utilisation Une fois l'API installée et configurée, vous pouvez commencer à l'utiliser en effectuant des requêtes HTTP vers les endpoints mentionnés ci-dessus. Assurez-vous de respecter les méthodes HTTP appropriées (GET, POST, etc.) pour interagir avec les données de l'API. diff --git a/backend/composer.json b/backend/composer.json index 0ca2eaa..123344a 100644 --- a/backend/composer.json +++ b/backend/composer.json @@ -27,6 +27,7 @@ "symfony/yaml": "6.4.*" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.51", "symfony/debug-bundle": "6.4.*", "symfony/maker-bundle": "^1.56" }, diff --git a/backend/composer.lock b/backend/composer.lock index 11f17db..7a1038f 100644 --- a/backend/composer.lock +++ b/backend/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "251b242f1c244121fc81b576193a6cb6", + "content-hash": "09041e7e38ac2ca548118cffc4e2bf78", "packages": [ { "name": "doctrine/cache", @@ -4520,6 +4520,316 @@ } ], "packages-dev": [ + { + "name": "composer/pcre", + "version": "3.1.2", + "source": { + "type": "git", + "url": "https://github.com/composer/pcre.git", + "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/pcre/zipball/4775f35b2d70865807c89d32c8e7385b86eb0ace", + "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.3", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Pcre\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "PCRE wrapping library that offers type-safe preg_* replacements.", + "keywords": [ + "PCRE", + "preg", + "regex", + "regular expression" + ], + "support": { + "issues": "https://github.com/composer/pcre/issues", + "source": "https://github.com/composer/pcre/tree/3.1.2" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2024-03-07T15:38:35+00:00" + }, + { + "name": "composer/semver", + "version": "3.4.0", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/35e8d0af4486141bc745f23a29cc2091eb624a32", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.4", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "ircs://irc.libera.chat:6697/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.4.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2023-08-31T09:50:34+00:00" + }, + { + "name": "composer/xdebug-handler", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/composer/xdebug-handler.git", + "reference": "ced299686f41dce890debac69273b47ffe98a40c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c", + "reference": "ced299686f41dce890debac69273b47ffe98a40c", + "shasum": "" + }, + "require": { + "composer/pcre": "^1 || ^2 || ^3", + "php": "^7.2.5 || ^8.0", + "psr/log": "^1 || ^2 || ^3" + }, + "require-dev": { + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Composer\\XdebugHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "John Stevenson", + "email": "john-stevenson@blueyonder.co.uk" + } + ], + "description": "Restarts a process without Xdebug.", + "keywords": [ + "Xdebug", + "performance" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/xdebug-handler/issues", + "source": "https://github.com/composer/xdebug-handler/tree/3.0.3" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-02-25T21:32:43+00:00" + }, + { + "name": "friendsofphp/php-cs-fixer", + "version": "v3.51.0", + "source": { + "type": "git", + "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", + "reference": "127fa74f010da99053e3f5b62672615b72dd6efd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/127fa74f010da99053e3f5b62672615b72dd6efd", + "reference": "127fa74f010da99053e3f5b62672615b72dd6efd", + "shasum": "" + }, + "require": { + "composer/semver": "^3.4", + "composer/xdebug-handler": "^3.0.3", + "ext-filter": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0", + "sebastian/diff": "^4.0 || ^5.0 || ^6.0", + "symfony/console": "^5.4 || ^6.0 || ^7.0", + "symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0", + "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", + "symfony/finder": "^5.4 || ^6.0 || ^7.0", + "symfony/options-resolver": "^5.4 || ^6.0 || ^7.0", + "symfony/polyfill-mbstring": "^1.28", + "symfony/polyfill-php80": "^1.28", + "symfony/polyfill-php81": "^1.28", + "symfony/process": "^5.4 || ^6.0 || ^7.0", + "symfony/stopwatch": "^5.4 || ^6.0 || ^7.0" + }, + "require-dev": { + "facile-it/paraunit": "^1.3 || ^2.0", + "justinrainbow/json-schema": "^5.2", + "keradus/cli-executor": "^2.1", + "mikey179/vfsstream": "^1.6.11", + "php-coveralls/php-coveralls": "^2.7", + "php-cs-fixer/accessible-object": "^1.1", + "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.4", + "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.4", + "phpunit/phpunit": "^9.6 || ^10.5.5 || ^11.0.2", + "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0", + "symfony/yaml": "^5.4 || ^6.0 || ^7.0" + }, + "suggest": { + "ext-dom": "For handling output formats in XML", + "ext-mbstring": "For handling non-UTF8 characters." + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "PhpCsFixer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz Rumiński", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "keywords": [ + "Static code analysis", + "fixer", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.51.0" + }, + "funding": [ + { + "url": "https://github.com/keradus", + "type": "github" + } + ], + "time": "2024-02-28T19:50:06+00:00" + }, { "name": "nikic/php-parser", "version": "v5.0.2", @@ -4578,6 +4888,73 @@ }, "time": "2024-03-05T20:51:40+00:00" }, + { + "name": "sebastian/diff", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "ab83243ecc233de5655b76f577711de9f842e712" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ab83243ecc233de5655b76f577711de9f842e712", + "reference": "ab83243ecc233de5655b76f577711de9f842e712", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T07:30:33+00:00" + }, { "name": "symfony/debug-bundle", "version": "v6.4.3", @@ -4744,6 +5121,73 @@ ], "time": "2024-03-04T13:36:45+00:00" }, + { + "name": "symfony/options-resolver", + "version": "v6.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "22301f0e7fdeaacc14318928612dee79be99860e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/22301f0e7fdeaacc14318928612dee79be99860e", + "reference": "22301f0e7fdeaacc14318928612dee79be99860e", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an improved replacement for the array_replace PHP function", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "support": { + "source": "https://github.com/symfony/options-resolver/tree/v6.4.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-08-08T10:16:24+00:00" + }, { "name": "symfony/process", "version": "v6.4.4", diff --git a/backend/src/Controller/Api/ClassesController.php b/backend/src/Controller/Api/ClassesController.php index 8888f56..9928859 100644 --- a/backend/src/Controller/Api/ClassesController.php +++ b/backend/src/Controller/Api/ClassesController.php @@ -1,11 +1,12 @@ jsonService = $jsonService; } - /** * @throws TransportExceptionInterface */ @@ -30,6 +30,7 @@ public function getClasses(): Response { $classes = $this->classesScraperService->scrapeClasses(); $jsonClasses = $this->jsonService->EntityToJson($classes); + return new Response($jsonClasses, Response::HTTP_OK, ['Content-Type' => 'application/json']); } } diff --git a/backend/src/Controller/Api/TimetableController.php b/backend/src/Controller/Api/TimetableController.php index dd7d0a2..5f25e58 100644 --- a/backend/src/Controller/Api/TimetableController.php +++ b/backend/src/Controller/Api/TimetableController.php @@ -24,11 +24,9 @@ public function __construct(TimetableService $timetableService, JsonService $jso $this->jsonService = $jsonService; } - /** - * Get the timetable for a given class + * Get the timetable for a given class. * - * @param Request $request * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface @@ -41,12 +39,13 @@ public function index(Request $request): Response if (!$classParam) { return $this->json(['error' => 'class_param is missing'], Response::HTTP_BAD_REQUEST); } - + $xmlUrl = $this->timetableService->getXmlFile($classParam); if ($xmlUrl) { $timetable = $this->timetableService->fetchAndParseData($xmlUrl); $jsonTimeTable = $this->jsonService->EntityToJson($timetable); + return new Response($jsonTimeTable, Response::HTTP_OK, ['Content-Type' => 'application/json']); } else { return $this->json(['error' => 'Invalid XML url'], Response::HTTP_BAD_REQUEST); diff --git a/backend/src/Entity/EventHours.php b/backend/src/Entity/EventHours.php index 1575c7f..7a2a79d 100644 --- a/backend/src/Entity/EventHours.php +++ b/backend/src/Entity/EventHours.php @@ -29,8 +29,6 @@ public function setId(?int $id): void $this->id = $id; } - - public function getStartAt(): ?string { return $this->startAt; diff --git a/backend/src/Entity/WeekSchedule.php b/backend/src/Entity/WeekSchedule.php index 988aca5..98dd553 100644 --- a/backend/src/Entity/WeekSchedule.php +++ b/backend/src/Entity/WeekSchedule.php @@ -21,7 +21,6 @@ class WeekSchedule #[ORM\OneToMany(targetEntity: DaySchedule::class, mappedBy: 'weekSchedule')] private Collection $DaySchedule; - public function __construct() { $this->DaySchedule = new ArrayCollection(); @@ -80,6 +79,4 @@ public function removeDaySchedule(DaySchedule $daySchedule): static return $this; } - - } diff --git a/backend/src/Service/ClassesScraperService.php b/backend/src/Service/ClassesScraperService.php index 2d2e7ea..9ae65af 100644 --- a/backend/src/Service/ClassesScraperService.php +++ b/backend/src/Service/ClassesScraperService.php @@ -3,8 +3,8 @@ namespace App\Service; use App\Entity\ClassGroups; -use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\DomCrawler\Crawler; +use Symfony\Component\HttpClient\HttpClient; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; class ClassesScraperService @@ -17,9 +17,8 @@ public function __construct(string $schedule_url) } /** - * Scrape the classes from the schedule website + * Scrape the classes from the schedule website. * - * @return array * @throws TransportExceptionInterface */ public function scrapeClasses(): array diff --git a/backend/src/Service/JsonService.php b/backend/src/Service/JsonService.php index aa68bad..4dac926 100644 --- a/backend/src/Service/JsonService.php +++ b/backend/src/Service/JsonService.php @@ -10,12 +10,8 @@ class JsonService { - /** - * Convert an entity to a JSON string - * - * @param $entity - * @return string + * Convert an entity to a JSON string. */ public function EntityToJson($entity): string { @@ -30,10 +26,10 @@ public function EntityToJson($entity): string ], ]; - $normalizer = array(new DateTimeNormalizer(), new ObjectNormalizer(null, null, null, null, null, null, $defaultContext)); + $normalizer = [new DateTimeNormalizer(), new ObjectNormalizer(null, null, null, null, null, null, $defaultContext)]; $serializer = new Serializer($normalizer, [$encoder]); + return $serializer->serialize($entity, 'json'); } - -} \ No newline at end of file +} diff --git a/backend/src/Service/TimetableService.php b/backend/src/Service/TimetableService.php index 8975005..f804683 100644 --- a/backend/src/Service/TimetableService.php +++ b/backend/src/Service/TimetableService.php @@ -13,7 +13,6 @@ class TimetableService { - private ClassesScraperService $classesScraperService; private string $schedule_url; private XMLService $xmlService; @@ -26,10 +25,8 @@ public function __construct(ClassesScraperService $classesScraperService, string } /** - * Get the xml file for a given class + * Get the xml file for a given class. * - * @param string $classParam - * @return string|null * @throws TransportExceptionInterface */ public function getXmlFile(string $classParam): ?string @@ -38,7 +35,8 @@ public function getXmlFile(string $classParam): ?string foreach ($classesList as $class) { if ($class->getName() === $classParam) { $encodedClassFile = str_replace(' ', '%20', $class->getFile()); - return $this->schedule_url . $encodedClassFile; + + return $this->schedule_url.$encodedClassFile; } } @@ -46,27 +44,22 @@ public function getXmlFile(string $classParam): ?string } /** - * Define the time slots for the timetable - * - * @return array + * Define the time slots for the timetable. */ public function defineCreneaux(): array { return [ - "1" => ["start" => "8h30", "end" => "10h"], - "2" => ["start" => "10h30", "end" => "12h"], - "3" => ["start" => "12h", "end" => "13h30"], - "4" => ["start" => "13h30", "end" => "15h"], - "5" => ["start" => "15h15", "end" => "16h45"], - "6" => ["start" => "17h", "end" => "18h30"] + '1' => ['start' => '8h30', 'end' => '10h'], + '2' => ['start' => '10h30', 'end' => '12h'], + '3' => ['start' => '12h', 'end' => '13h30'], + '4' => ['start' => '13h30', 'end' => '15h'], + '5' => ['start' => '15h15', 'end' => '16h45'], + '6' => ['start' => '17h', 'end' => '18h30'], ]; } /** - * Put the parsed data into entity objects - * - * @param array $parsedData - * @return array + * Put the parsed data into entity objects. */ public function parseData(array $parsedData): array { @@ -74,7 +67,6 @@ public function parseData(array $parsedData): array $weeks = []; foreach ($parsedData['GROUPE']['PLAGES']['SEMAINE'] as $week) { - $weekSchedule = new WeekSchedule(); $weekSchedule->setId($week['SemId']); $weekSchedule->setCode($week['SemCod']); @@ -100,15 +92,14 @@ public function parseData(array $parsedData): array $event = new Event(); $event->setCreneau($creneau['Creneau']); - $event->setActivite($creneau['Activite'] ?? "Pas cours"); + $event->setActivite($creneau['Activite'] ?? 'Pas cours'); $event->setId($creneau['Id'] ?? 0); - $event->setCouleur($creneau['Couleur'] ?? "#000000"); + $event->setCouleur($creneau['Couleur'] ?? '#000000'); $event->setHoraire($eventHours); - $event->setSalle($creneau['Salles'] ?? ""); + $event->setSalle($creneau['Salles'] ?? ''); $event->setVisio(str_contains($creneau['Salles'] ?? null, 'Teams')); $daySchedule->addEvent($event); - } } @@ -121,9 +112,10 @@ public function parseData(array $parsedData): array } /** - * Fetch and parse the xml file + * Fetch and parse the xml file. * * @param string $xmlUrl The url of the xml file + * * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface @@ -133,6 +125,7 @@ public function fetchAndParseData(string $xmlUrl): array { $xmlContent = $this->xmlService->fetchXmlData($xmlUrl); $parsedXml = $this->xmlService->parseXmlData($xmlContent); + return $this->parseData($parsedXml); } } diff --git a/backend/src/Service/XMLService.php b/backend/src/Service/XMLService.php index 9888c81..6bba22d 100644 --- a/backend/src/Service/XMLService.php +++ b/backend/src/Service/XMLService.php @@ -11,9 +11,10 @@ class XMLService { /** - * Fetch XML data from a given URL + * Fetch XML data from a given URL. * * @param string $xmlUrl The URL of the XML file + * * @throws TransportExceptionInterface * @throws ServerExceptionInterface * @throws RedirectionExceptionInterface @@ -22,18 +23,19 @@ class XMLService public function fetchXmlData(string $xmlUrl): string { $httpClient = HttpClient::create(); + return $httpClient->request('GET', $xmlUrl)->getContent(); } -/** - * Parse XML data into an array + /** + * Parse XML data into an array. * * @param string $xmlContent The content of the XML file - * @return array */ public function parseXmlData(string $xmlContent): array { $xmlHash = simplexml_load_string($xmlContent); + return json_decode(json_encode($xmlHash), true); } -} \ No newline at end of file +} diff --git a/backend/symfony.lock b/backend/symfony.lock index 64bf4cb..8602a7e 100644 --- a/backend/symfony.lock +++ b/backend/symfony.lock @@ -26,6 +26,18 @@ "./migrations/.gitignore" ] }, + "friendsofphp/php-cs-fixer": { + "version": "3.51", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "3.0", + "ref": "be2103eb4a20942e28a6dd87736669b757132435" + }, + "files": [ + "./.php-cs-fixer.dist.php" + ] + }, "symfony/apache-pack": { "version": "1.0", "recipe": { diff --git a/frontend/app_student/analysis_options.yaml b/frontend/app_student/analysis_options.yaml index 0d29021..3570a3b 100644 --- a/frontend/app_student/analysis_options.yaml +++ b/frontend/app_student/analysis_options.yaml @@ -23,6 +23,9 @@ linter: rules: # avoid_print: false # Uncomment to disable the `avoid_print` rule # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + avoid_print: true + prefer_single_quotes: true + prefer_const_constructors: true # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/frontend/app_student/devtools_options.yaml b/frontend/app_student/devtools_options.yaml new file mode 100644 index 0000000..7e7e7f6 --- /dev/null +++ b/frontend/app_student/devtools_options.yaml @@ -0,0 +1 @@ +extensions: diff --git a/frontend/app_student/lib/classes/bloc/class_bloc.dart b/frontend/app_student/lib/classes/bloc/class_bloc.dart index 8fdcab1..f07f1df 100644 --- a/frontend/app_student/lib/classes/bloc/class_bloc.dart +++ b/frontend/app_student/lib/classes/bloc/class_bloc.dart @@ -3,8 +3,6 @@ import 'dart:async'; import 'package:app_student/api/classes/entities/class.dart'; import 'package:app_student/api/classes/repositories/class_repository.dart'; - - class ClassBloc { final ClassRepository classRepository; final _classController = StreamController>(); diff --git a/frontend/app_student/lib/classes/views/class.dart b/frontend/app_student/lib/classes/views/class.dart index 465b331..0b8de9a 100644 --- a/frontend/app_student/lib/classes/views/class.dart +++ b/frontend/app_student/lib/classes/views/class.dart @@ -2,7 +2,6 @@ import 'package:app_student/api/classes/entities/class.dart'; import 'package:flutter/material.dart'; import 'package:app_student/classes/bloc/class_bloc.dart'; - class ClassListPage extends StatefulWidget { final ClassBloc classBloc; diff --git a/frontend/app_student/lib/login/views/login_page.dart b/frontend/app_student/lib/login/views/login_page.dart index 506e802..486d1ec 100644 --- a/frontend/app_student/lib/login/views/login_page.dart +++ b/frontend/app_student/lib/login/views/login_page.dart @@ -13,7 +13,7 @@ class LoginPage extends StatelessWidget { body: Column( children: [ HeaderLogo(), - HeaderText("Bonjour :)"), + HeaderText('Bonjour :)'), Expanded(child: FormLogin()), ], ), diff --git a/frontend/app_student/lib/login/widgets/form/inputs/input_prenom.dart b/frontend/app_student/lib/login/widgets/form/inputs/input_prenom.dart index d402f45..89219a2 100644 --- a/frontend/app_student/lib/login/widgets/form/inputs/input_prenom.dart +++ b/frontend/app_student/lib/login/widgets/form/inputs/input_prenom.dart @@ -27,7 +27,7 @@ class FirstnameTextField extends StatelessWidget { contentPadding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0), border: OutlineInputBorder( - borderSide: BorderSide(color: Colors.grey), + borderSide: const BorderSide(color: Colors.grey), borderRadius: BorderRadius.circular(3.0), ), focusedBorder: OutlineInputBorder(