Skip to content

Commit

Permalink
Replace http by https (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamirault authored Nov 29, 2024
1 parent 5bdb0b5 commit 6fcb4e8
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 84 deletions.
23 changes: 3 additions & 20 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixerCustomFixers\Fixer\CommentSurroundedBySpacesFixer;
use PhpCsFixerCustomFixers\Fixer\ConstructorEmptyBracesFixer;
use PhpCsFixerCustomFixers\Fixer\DeclareAfterOpeningTagFixer;
Expand All @@ -11,7 +10,6 @@
use PhpCsFixerCustomFixers\Fixer\PhpdocParamOrderFixer;
use PhpCsFixerCustomFixers\Fixer\PhpdocTypesTrimFixer;
use PhpCsFixerCustomFixers\Fixer\PromotedConstructorPropertyFixer;
use PhpCsFixerCustomFixers\Fixer\ReadonlyPromotedPropertiesFixer;

$excludes = [
'vendor',
Expand All @@ -28,32 +26,17 @@
'@Symfony' => 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();
Expand Down
18 changes: 0 additions & 18 deletions Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ version: '3.5'

services:
php:
build: .
image: alamirault/yolo-php:8.1
volumes:
- .:/var/www/html
1 change: 1 addition & 0 deletions src/Model/Factory/RencontreDetailsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
2 changes: 1 addition & 1 deletion src/Service/FFTTApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function retrieveVirtualPoints(string $licenceId): VirtualPoints
/**
* @return array<Equipe>
*/
public function listEquipesByClub(string $clubId, string $type = null): array
public function listEquipesByClub(string $clubId, ?string $type = null): array
{
return $this->listEquipeOperation->listEquipesByClub($clubId, $type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Service/FFTTClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/Service/FFTTClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/Service/Operation/ListClubOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function listClubsByName(string $name): array
try {
/** @var array<mixed> $rawClubs */
$rawClubs = $this->client->get('xml_club_b', [
'ville' => $name,
])['club'] ?? [];
'ville' => $name,
])['club'] ?? [];

/** @var array<array{numero: string, nom: string, validation: array<mixed>|string}> $rawClubs */
$rawClubs = $this->arrayWrapper->wrapArrayIfUnique($rawClubs);
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Operation/ListEquipeOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
/**
* @return array<Equipe>
*/
public function listEquipesByClub(string $clubId, string $type = null): array
public function listEquipesByClub(string $clubId, ?string $type = null): array
{
$params = [
'numclu' => $clubId,
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Operation/ListHistoriqueOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function listHistorique(string $licenceId): array
{
/** @var array<mixed> $classements */
$classements = $this->client->get('xml_histo_classement', [
'numlic' => $licenceId,
])['histo'] ?? [];
'numlic' => $licenceId,
])['histo'] ?? [];

$classements = $this->arrayWrapper->wrapArrayIfUnique($classements);

Expand Down
10 changes: 5 additions & 5 deletions src/Service/Operation/ListJoueurOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -52,9 +52,9 @@ public function listJoueursByNom(string $nom, string $prenom = ''): array
{
/** @var array<mixed> $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);
Expand Down
12 changes: 6 additions & 6 deletions src/Service/Operation/ListPartieOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function listPartiesJoueurByLicence(string $licenceId): array
{
/** @var array<mixed> $parties */
$parties = $this->client->get('xml_partie_mysql', [
'licence' => $licenceId,
])['partie'] ?? [];
'licence' => $licenceId,
])['partie'] ?? [];
$parties = $this->arrayWrapper->wrapArrayIfUnique($parties);

$res = [];
Expand Down Expand Up @@ -65,8 +65,8 @@ public function listUnvalidatedPartiesJoueurByLicence(string $joueurId): array

/** @var array<array{victoire: string, forfait: string, nom: string, date: string, epreuve: string, idpartie: string, coefchamp: string, classement: string}> $allParties */
$allParties = $this->client->get('xml_partie', [
'numlic' => $joueurId,
])['partie'] ?? [];
'numlic' => $joueurId,
])['partie'] ?? [];

$result = [];
foreach ($allParties as $partie) {
Expand All @@ -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()))
);
}));

Expand Down
4 changes: 2 additions & 2 deletions src/Service/Operation/RetrieveClassementOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function retrieveClassement(string $licenceId): Classement
{
/** @var array<mixed> $joueurDetails */
$joueurDetails = $this->client->get('xml_joueur', [
'licence' => $licenceId,
])['joueur'] ?? [];
'licence' => $licenceId,
])['joueur'] ?? [];

if (false === array_key_exists('nom', $joueurDetails)) {
throw new JoueurNotFoundException($licenceId);
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Operation/RetrieveClubDetailsOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function retrieveClubDetails(string $clubId): ClubDetails
{
/** @var array<mixed> $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);
Expand Down
4 changes: 2 additions & 2 deletions src/Service/UriGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/Service/UriGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface UriGeneratorInterface
/**
* @param array<string, string> $parameters
*/
public function generate(string $path, array $parameters = [], string $queryParameter = null): string;
public function generate(string $path, array $parameters = [], ?string $queryParameter = null): string;
}
17 changes: 8 additions & 9 deletions tests/Unit/Service/Operation/MockHandlerStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Service/UriGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGenerate(): void
/** @var array<string, string> $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']);

Expand Down Expand Up @@ -50,7 +50,7 @@ public function testGenerateWithParameters(): void
/** @var array<string, string> $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']);

Expand Down Expand Up @@ -80,7 +80,7 @@ public function testGenerateWithQueryParameter(): void
/** @var array<string, string> $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']);

Expand Down

0 comments on commit 6fcb4e8

Please sign in to comment.