diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8bbf734..3b8cd8a 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,6 +1,5 @@ true, 'phpdoc_to_comment' => false, 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'parameters']], + 'phpdoc_array_type' => true, + 'phpdoc_param_order' => true, CommentSurroundedBySpacesFixer::name() => true, ConstructorEmptyBracesFixer::name() => true, DeclareAfterOpeningTagFixer::name() => true, MultilineCommentOpeningClosingAloneFixer::name() => true, MultilinePromotedPropertiesFixer::name() => true, - MultilinePromotedPropertiesFixer::name() => true, - PhpdocArrayStyleFixer::name() => true, PhpdocNoSuperfluousParamFixer::name() => true, - PhpdocParamOrderFixer::name() => true, PhpdocTypesTrimFixer::name() => true, PromotedConstructorPropertyFixer::name() => true, -// '@PSR2' => true, -// 'array_syntax' => ['syntax' => 'short'], -// 'no_useless_else' => true, -// 'yoda_style' => false, -// 'function_declaration' => [ -// 'closure_function_spacing' => 'none' //No space before function -// ], -// 'braces' => false, //Disable due to it add space before parenthesis of if or foreach -// 'concat_space' => [ -// 'spacing' => 'one' -// ], -// 'phpdoc_align' => [ -// 'align' => 'left' -// ], -// 'single_blank_line_at_eof' => false, + MultilinePromotedPropertiesFixer::name() => true, ]; $config = new PhpCsFixer\Config(); diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 6d646a9..0000000 --- a/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM php:8.1-apache - -RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -RUN php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" -RUN php composer-setup.php -RUN php -r "unlink('composer-setup.php');" -RUN mv composer.phar /usr/local/bin/composer - -RUN apt-get update && apt-get install -y \ - git \ - zlib1g-dev \ - libzip-dev \ - zip \ - unzip -RUN docker-php-ext-install zip - -RUN pecl install pcov && \ -docker-php-ext-enable pcov \ No newline at end of file diff --git a/README.md b/README.md index 398267c..af22821 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,13 @@ This project is the source code of [alamirault/fftt-api](https://github.com/alam Run docker environment ```bash -docker-compose up -d +docker compose up -d ``` Go inside container ```bash -docker exec -it use-fftt-api-refacto_php_1 bash +docker exec -it fftt-api-src-php-1 bash ``` Install dependencies diff --git a/composer.json b/composer.json index c369151..4f65d7a 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,8 @@ "rector/rector": "^0.14.2" }, "scripts": { - "cs": "./bin/php-cs-fixer fix --verbose --diff --using-cache=no --dry-run", - "cs-fix": "./bin/php-cs-fixer fix --verbose --diff --using-cache=no", + "cs": "./bin/php-cs-fixer fix --verbose --diff --using-cache=no --dry-run --allow-risky=yes", + "cs-fix": "./bin/php-cs-fixer fix --verbose --diff --using-cache=no --allow-risky=yes", "phpstan": "./bin/phpstan analyse", "phpunit": "./bin/phpunit", "coverage": "./bin/phpunit --coverage-html coverage", diff --git a/docker-compose.yml b/docker-compose.yml index d37eb99..7bc13d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,6 @@ version: '3.5' services: php: - build: . + image: alamirault/yolo-php:8.1 volumes: - .:/var/www/html \ No newline at end of file diff --git a/src/Model/Factory/RencontreDetailsFactory.php b/src/Model/Factory/RencontreDetailsFactory.php index b774e52..1ca58ce 100644 --- a/src/Model/Factory/RencontreDetailsFactory.php +++ b/src/Model/Factory/RencontreDetailsFactory.php @@ -165,6 +165,7 @@ private function formatJoueur(string $prenom, string $nom, string $points, array if (false === $return) { throw new \RuntimeException(sprintf("Not able to extract sexe and points in '%s'", $points)); } + /** @var array{sexe: string|null, points: string|null} $result */ $sexe = $result['sexe']; $playerPoints = $result['points']; diff --git a/src/Service/FFTTApi.php b/src/Service/FFTTApi.php index e249e04..58dfad9 100644 --- a/src/Service/FFTTApi.php +++ b/src/Service/FFTTApi.php @@ -185,7 +185,7 @@ public function retrieveVirtualPoints(string $licenceId): VirtualPoints /** * @return array */ - public function listEquipesByClub(string $clubId, string $type = null): array + public function listEquipesByClub(string $clubId, ?string $type = null): array { return $this->listEquipeOperation->listEquipesByClub($clubId, $type); } diff --git a/src/Service/FFTTClient.php b/src/Service/FFTTClient.php index c7865d6..fb379e8 100644 --- a/src/Service/FFTTClient.php +++ b/src/Service/FFTTClient.php @@ -17,7 +17,7 @@ public function __construct( private readonly UriGenerator $uriGenerator, ) {} - public function get(string $path, array $params = [], string $queryParameter = null): array + public function get(string $path, array $params = [], ?string $queryParameter = null): array { $uri = $this->uriGenerator->generate($path, $params, $queryParameter); try { diff --git a/src/Service/FFTTClientInterface.php b/src/Service/FFTTClientInterface.php index 47959ae..34cf19d 100644 --- a/src/Service/FFTTClientInterface.php +++ b/src/Service/FFTTClientInterface.php @@ -17,5 +17,5 @@ interface FFTTClientInterface * @throws InvalidResponseException * @throws InternalServerErrorException */ - public function get(string $path, array $params = [], string $queryParameter = null): array; + public function get(string $path, array $params = [], ?string $queryParameter = null): array; } diff --git a/src/Service/Operation/ListClubOperation.php b/src/Service/Operation/ListClubOperation.php index aab8417..fb5e402 100644 --- a/src/Service/Operation/ListClubOperation.php +++ b/src/Service/Operation/ListClubOperation.php @@ -35,8 +35,8 @@ public function listClubsByName(string $name): array try { /** @var array $rawClubs */ $rawClubs = $this->client->get('xml_club_b', [ - 'ville' => $name, - ])['club'] ?? []; + 'ville' => $name, + ])['club'] ?? []; /** @var array|string}> $rawClubs */ $rawClubs = $this->arrayWrapper->wrapArrayIfUnique($rawClubs); diff --git a/src/Service/Operation/ListEquipeOperation.php b/src/Service/Operation/ListEquipeOperation.php index 00b6fdb..63603a4 100644 --- a/src/Service/Operation/ListEquipeOperation.php +++ b/src/Service/Operation/ListEquipeOperation.php @@ -15,7 +15,7 @@ public function __construct( /** * @return array */ - public function listEquipesByClub(string $clubId, string $type = null): array + public function listEquipesByClub(string $clubId, ?string $type = null): array { $params = [ 'numclu' => $clubId, diff --git a/src/Service/Operation/ListHistoriqueOperation.php b/src/Service/Operation/ListHistoriqueOperation.php index 634c0ec..b40b503 100644 --- a/src/Service/Operation/ListHistoriqueOperation.php +++ b/src/Service/Operation/ListHistoriqueOperation.php @@ -19,8 +19,8 @@ public function listHistorique(string $licenceId): array { /** @var array $classements */ $classements = $this->client->get('xml_histo_classement', [ - 'numlic' => $licenceId, - ])['histo'] ?? []; + 'numlic' => $licenceId, + ])['histo'] ?? []; $classements = $this->arrayWrapper->wrapArrayIfUnique($classements); diff --git a/src/Service/Operation/ListJoueurOperation.php b/src/Service/Operation/ListJoueurOperation.php index 63bb80e..eaa909e 100644 --- a/src/Service/Operation/ListJoueurOperation.php +++ b/src/Service/Operation/ListJoueurOperation.php @@ -22,8 +22,8 @@ public function listJoueursByClub(string $clubId): array { try { $arrayJoueurs = $this->client->get('xml_liste_joueur_o', [ - 'club' => $clubId, - ] + 'club' => $clubId, + ] ); } catch (InvalidResponseException) { throw new ClubNotFoundException($clubId); @@ -52,9 +52,9 @@ public function listJoueursByNom(string $nom, string $prenom = ''): array { /** @var array $arrayJoueurs */ $arrayJoueurs = $this->client->get('xml_liste_joueur', [ - 'nom' => addslashes(Accentuation::remove($nom)), - 'prenom' => addslashes(Accentuation::remove($prenom)), - ] + 'nom' => addslashes(Accentuation::remove($nom)), + 'prenom' => addslashes(Accentuation::remove($prenom)), + ] )['joueur']; $arrayJoueurs = $this->arrayWrapper->wrapArrayIfUnique($arrayJoueurs); diff --git a/src/Service/Operation/ListPartieOperation.php b/src/Service/Operation/ListPartieOperation.php index 09ebf95..9e690b3 100644 --- a/src/Service/Operation/ListPartieOperation.php +++ b/src/Service/Operation/ListPartieOperation.php @@ -26,8 +26,8 @@ public function listPartiesJoueurByLicence(string $licenceId): array { /** @var array $parties */ $parties = $this->client->get('xml_partie_mysql', [ - 'licence' => $licenceId, - ])['partie'] ?? []; + 'licence' => $licenceId, + ])['partie'] ?? []; $parties = $this->arrayWrapper->wrapArrayIfUnique($parties); $res = []; @@ -65,8 +65,8 @@ public function listUnvalidatedPartiesJoueurByLicence(string $joueurId): array /** @var array $allParties */ $allParties = $this->client->get('xml_partie', [ - 'numlic' => $joueurId, - ])['partie'] ?? []; + 'numlic' => $joueurId, + ])['partie'] ?? []; $result = []; foreach ($allParties as $partie) { @@ -76,8 +76,8 @@ public function listUnvalidatedPartiesJoueurByLicence(string $joueurId): array return $partie['date'] === $validatedPartie->getDate()->format('d/m/Y') and $this->removeAccentLowerCaseRegex($nom) === $this->removeAccentLowerCaseRegex($validatedPartie->getAdversaireNom()) and ( - preg_match('/'.$this->removeAccentLowerCaseRegex($prenom).'.*/', $this->removeAccentLowerCaseRegex($validatedPartie->getAdversairePrenom())) or - str_contains($this->removeAccentLowerCaseRegex($prenom), $this->removeAccentLowerCaseRegex($validatedPartie->getAdversairePrenom())) + preg_match('/'.$this->removeAccentLowerCaseRegex($prenom).'.*/', $this->removeAccentLowerCaseRegex($validatedPartie->getAdversairePrenom())) + or str_contains($this->removeAccentLowerCaseRegex($prenom), $this->removeAccentLowerCaseRegex($validatedPartie->getAdversairePrenom())) ); })); diff --git a/src/Service/Operation/RetrieveClassementOperation.php b/src/Service/Operation/RetrieveClassementOperation.php index 8e6c768..ccd25c2 100644 --- a/src/Service/Operation/RetrieveClassementOperation.php +++ b/src/Service/Operation/RetrieveClassementOperation.php @@ -16,8 +16,8 @@ public function retrieveClassement(string $licenceId): Classement { /** @var array $joueurDetails */ $joueurDetails = $this->client->get('xml_joueur', [ - 'licence' => $licenceId, - ])['joueur'] ?? []; + 'licence' => $licenceId, + ])['joueur'] ?? []; if (false === array_key_exists('nom', $joueurDetails)) { throw new JoueurNotFoundException($licenceId); diff --git a/src/Service/Operation/RetrieveClubDetailsOperation.php b/src/Service/Operation/RetrieveClubDetailsOperation.php index 4ad9351..a7d4f0e 100644 --- a/src/Service/Operation/RetrieveClubDetailsOperation.php +++ b/src/Service/Operation/RetrieveClubDetailsOperation.php @@ -18,8 +18,8 @@ public function retrieveClubDetails(string $clubId): ClubDetails { /** @var array $clubData */ $clubData = $this->client->get('xml_club_detail', [ - 'club' => $clubId, - ])['club'] ?? []; + 'club' => $clubId, + ])['club'] ?? []; if (false === array_key_exists('numero', $clubData)) { throw new ClubNotFoundException($clubId); diff --git a/src/Service/UriGenerator.php b/src/Service/UriGenerator.php index 56cd65d..d729125 100644 --- a/src/Service/UriGenerator.php +++ b/src/Service/UriGenerator.php @@ -4,14 +4,14 @@ final class UriGenerator implements UriGeneratorInterface { - private const FFTT_URL = 'http://www.fftt.com/mobile/pxml/'; + private const FFTT_URL = 'https://www.fftt.com/mobile/pxml/'; public function __construct( private readonly string $id, private readonly string $password, ) {} - public function generate(string $path, array $parameters = [], string $queryParameter = null): string + public function generate(string $path, array $parameters = [], ?string $queryParameter = null): string { $time = round(microtime(true) * 1000); $hashedKey = hash_hmac('sha1', (string) $time, md5($this->password)); diff --git a/src/Service/UriGeneratorInterface.php b/src/Service/UriGeneratorInterface.php index 68e88b3..40d1686 100644 --- a/src/Service/UriGeneratorInterface.php +++ b/src/Service/UriGeneratorInterface.php @@ -7,5 +7,5 @@ interface UriGeneratorInterface /** * @param array $parameters */ - public function generate(string $path, array $parameters = [], string $queryParameter = null): string; + public function generate(string $path, array $parameters = [], ?string $queryParameter = null): string; } diff --git a/tests/Unit/Service/Operation/MockHandlerStub.php b/tests/Unit/Service/Operation/MockHandlerStub.php index d2de4cf..49432b3 100644 --- a/tests/Unit/Service/Operation/MockHandlerStub.php +++ b/tests/Unit/Service/Operation/MockHandlerStub.php @@ -32,9 +32,9 @@ final class MockHandlerStub implements \Countable * @return HandlerStack */ public static function createWithMiddleware( - array $queue = null, - callable $onFulfilled = null, - callable $onRejected = null, + ?array $queue = null, + ?callable $onFulfilled = null, + ?callable $onRejected = null, ) { return HandlerStack::create(new self($queue, $onFulfilled, $onRejected)); } @@ -44,14 +44,13 @@ public static function createWithMiddleware( * {@see Psr7\Http\Message\ResponseInterface} objects, Exceptions, * callables, or Promises. * - * @param array $queue * @param callable $onFulfilled callback to invoke when the return value is fulfilled * @param callable $onRejected callback to invoke when the return value is rejected */ public function __construct( - array $queue = null, - callable $onFulfilled = null, - callable $onRejected = null, + ?array $queue = null, + ?callable $onFulfilled = null, + ?callable $onRejected = null, ) { $this->onFulfilled = $onFulfilled; $this->onRejected = $onRejected; @@ -182,8 +181,8 @@ public function reset() private function invokeStats( RequestInterface $request, array $options, - ResponseInterface $response = null, - $reason = null, + ?ResponseInterface $response = null, + $reason = null, ) { if (isset($options['on_stats'])) { $transferTime = isset($options['transfer_time']) ? $options['transfer_time'] : 0; diff --git a/tests/Unit/Service/Operation/RetrieveJoueurDetailsOperationTest.php b/tests/Unit/Service/Operation/RetrieveJoueurDetailsOperationTest.php index d5f02aa..7d7a6cf 100644 --- a/tests/Unit/Service/Operation/RetrieveJoueurDetailsOperationTest.php +++ b/tests/Unit/Service/Operation/RetrieveJoueurDetailsOperationTest.php @@ -52,7 +52,7 @@ public function testRetrieveJoueurDetailsJoueurExistantSansClub(): void $this->assertSame('11340010', $joueurDetails->getNumClub()); $this->assertSame('MONTPELLIER TT', $joueurDetails->getNomClub()); $this->assertTrue($joueurDetails->isHomme()); - $this->assertSame(TypelicenceEnum::Competition, $joueurDetails->getTypeLicence()); + $this->assertSame(TypeLicenceEnum::Competition, $joueurDetails->getTypeLicence()); $this->assertSame('01/08/2022', $joueurDetails->getDateValidation()?->format('d/m/Y')); $this->assertTrue($joueurDetails->isClasseNational()); $this->assertSame('S', $joueurDetails->getCategorie()); @@ -99,7 +99,7 @@ public function testRetrieveJoueurDetailsJoueurExistantAvecClub(): void $this->assertSame('08950978', $joueurDetails->getNumClub()); $this->assertSame('EAUBONNE CSM TT', $joueurDetails->getNomClub()); $this->assertTrue($joueurDetails->isHomme()); - $this->assertSame(TypelicenceEnum::Competition, $joueurDetails->getTypeLicence()); + $this->assertSame(TypeLicenceEnum::Competition, $joueurDetails->getTypeLicence()); $this->assertSame('18/09/2022', $joueurDetails->getDateValidation()?->format('d/m/Y')); $this->assertFalse($joueurDetails->isClasseNational()); $this->assertSame('V1', $joueurDetails->getCategorie()); @@ -361,7 +361,7 @@ public function testRetrieveJoueurDetailsSansJoueurniClub(): void try { $operation->retrieveJoueurDetails('', ''); } catch (\Exception $e) { - $this->assertTrue(str_contains($e->getMessage(), 'Status code 400 on URL "http://www.fftt.com/mobile/pxml/xml_licence_b.php')); + $this->assertTrue(str_contains($e->getMessage(), 'Status code 400 on URL "https://www.fftt.com/mobile/pxml/xml_licence_b.php')); $this->assertSame(InvalidRequestException::class, $e::class); } } diff --git a/tests/Unit/Service/UriGeneratorTest.php b/tests/Unit/Service/UriGeneratorTest.php index 92a1b09..dddae33 100644 --- a/tests/Unit/Service/UriGeneratorTest.php +++ b/tests/Unit/Service/UriGeneratorTest.php @@ -22,7 +22,7 @@ public function testGenerate(): void /** @var array $uriParts */ $uriParts = parse_url($uri); - $this->assertSame('http', $uriParts['scheme']); + $this->assertSame('https', $uriParts['scheme']); $this->assertSame('www.fftt.com', $uriParts['host']); $this->assertSame('/mobile/pxml/baz.php', $uriParts['path']); @@ -50,7 +50,7 @@ public function testGenerateWithParameters(): void /** @var array $uriParts */ $uriParts = parse_url($uri); - $this->assertSame('http', $uriParts['scheme']); + $this->assertSame('https', $uriParts['scheme']); $this->assertSame('www.fftt.com', $uriParts['host']); $this->assertSame('/mobile/pxml/baz.php', $uriParts['path']); @@ -80,7 +80,7 @@ public function testGenerateWithQueryParameter(): void /** @var array $uriParts */ $uriParts = parse_url($uri); - $this->assertSame('http', $uriParts['scheme']); + $this->assertSame('https', $uriParts['scheme']); $this->assertSame('www.fftt.com', $uriParts['host']); $this->assertSame('/mobile/pxml/baz.php', $uriParts['path']);