-
Notifications
You must be signed in to change notification settings - Fork 2
Format players' names (URL : 'xml_liste_joueur_o'), trim sets details, and add two Joueur() properties #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fea072f
427919e
e209a7c
87fa415
2b4e983
2f9a41e
fadce3a
c045194
eb4f6f7
59f5899
dee4347
46c3eed
0f777d5
246555f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |||||||||
|
|
||||||||||
| namespace Alamirault\FFTTApi\Model\Factory; | ||||||||||
|
|
||||||||||
| use Accentuation\Accentuation; | ||||||||||
| use Alamirault\FFTTApi\Model\Rencontre\Joueur; | ||||||||||
| use Alamirault\FFTTApi\Model\Rencontre\Partie; | ||||||||||
| use Alamirault\FFTTApi\Model\Rencontre\RencontreDetails; | ||||||||||
|
|
@@ -29,11 +28,14 @@ public function createFromArray(array $array, string $clubEquipeA, string $clubE | |||||||||
| $joueursA = []; | ||||||||||
| $joueursB = []; | ||||||||||
| foreach ($array['joueur'] as $joueur) { | ||||||||||
| $joueursA[] = [$joueur['xja'] ?: '', $joueur['xca'] ?: '']; | ||||||||||
| $joueursB[] = [$joueur['xjb'] ?: '', $joueur['xcb'] ?: '']; | ||||||||||
| $joueursA[] = ['nom' => $joueur['xja'] ?: '', 'points' => $joueur['xca'] ?: '']; | ||||||||||
| $joueursB[] = ['nom' => $joueur['xjb'] ?: '', 'points' => $joueur['xcb'] ?: '']; | ||||||||||
| } | ||||||||||
| $joueursAFormatted = $this->formatJoueurs($joueursA, $clubEquipeA); | ||||||||||
| $joueursBFormatted = $this->formatJoueurs($joueursB, $clubEquipeB); | ||||||||||
|
|
||||||||||
| $wholeTeamAForfeit = 0 === count(array_filter($joueursA, function ($joueurA) { return $joueurA['nom'] && $joueurA['points']; })); | ||||||||||
| $wholeTeamBForfeit = 0 === count(array_filter($joueursB, function ($joueurB) { return $joueurB['nom'] && $joueurB['points']; })); | ||||||||||
| $joueursAFormatted = !$wholeTeamAForfeit ? $this->formatJoueurs($joueursA, $clubEquipeA) : []; | ||||||||||
| $joueursBFormatted = !$wholeTeamBForfeit ? $this->formatJoueurs($joueursB, $clubEquipeB) : []; | ||||||||||
|
|
||||||||||
| $parties = $this->getParties($array['partie']); | ||||||||||
|
|
||||||||||
|
|
@@ -129,7 +131,7 @@ private function getScores(array $parties): array | |||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @param array<array{0: string, 1: string}> $data | ||||||||||
| * @param array<array{nom: string, points: string}> $data | ||||||||||
| * | ||||||||||
| * @return array<string, Joueur> | ||||||||||
| */ | ||||||||||
|
|
@@ -139,9 +141,11 @@ private function formatJoueurs(array $data, string $playerClubId): array | |||||||||
|
|
||||||||||
| $joueurs = []; | ||||||||||
| foreach ($data as $joueurData) { | ||||||||||
| $nomPrenom = $joueurData[0]; | ||||||||||
| [$nom, $prenom] = $this->nomPrenomExtractor->extractNomPrenom($nomPrenom); | ||||||||||
| $joueurs[$this->nomPrenomExtractor->removeSeparatorsDuplication($nomPrenom)] = $this->formatJoueur($prenom, $nom, $joueurData[1], $joueursClub); | ||||||||||
| if ($joueurData['nom'] && $joueurData['points']) { | ||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So in this way, we can have 4 players in left, and 3 players in right, is not a problem ? Historically I wanted always same number of players on left and right |
||||||||||
| $nomPrenom = $joueurData['nom']; | ||||||||||
| [$nom, $prenom] = $this->nomPrenomExtractor->extractNomPrenom($nomPrenom); | ||||||||||
| $joueurs[$this->nomPrenomExtractor->removeSeparatorsDuplication($nomPrenom)] = $this->formatJoueur($prenom, $nom, $joueurData['points'], $joueursClub); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return $joueurs; | ||||||||||
|
|
@@ -157,9 +161,7 @@ private function formatJoueur(string $prenom, string $nom, string $points, array | |||||||||
| } | ||||||||||
|
|
||||||||||
| foreach ($joueursClub as $joueurClub) { | ||||||||||
| $nomJoueurClub = $this->nomPrenomExtractor->removeSeparatorsDuplication($joueurClub->getNom()); | ||||||||||
| $prenomJoueurClub = $this->nomPrenomExtractor->removeSeparatorsDuplication($joueurClub->getPrenom()); | ||||||||||
| if ($nomJoueurClub === Accentuation::remove($nom) && $prenomJoueurClub === $prenom) { | ||||||||||
| if ($joueurClub->getNom() === $nom && $joueurClub->getPrenom() === $prenom) { | ||||||||||
| $return = preg_match('/^(N°[0-9]*- ){0,1}(?<sexe>[A-Z]{1}) (?<points>[0-9]+)pts$/', $points, $result); | ||||||||||
|
|
||||||||||
| if (false === $return) { | ||||||||||
|
|
@@ -169,8 +171,8 @@ private function formatJoueur(string $prenom, string $nom, string $points, array | |||||||||
| $playerPoints = $result['points']; | ||||||||||
|
|
||||||||||
| return new Joueur( | ||||||||||
| $nomJoueurClub, | ||||||||||
| $prenomJoueurClub, | ||||||||||
| $joueurClub->getNom(), | ||||||||||
| $joueurClub->getPrenom(), | ||||||||||
| $joueurClub->getLicence(), | ||||||||||
| (int) $playerPoints, | ||||||||||
| $sexe | ||||||||||
|
|
@@ -190,20 +192,22 @@ private function getParties(array $data): array | |||||||||
| { | ||||||||||
| $parties = []; | ||||||||||
| foreach ($data as $partieData) { | ||||||||||
| $setDetails = explode(' ', $partieData['detail']); | ||||||||||
| $setsDetails = array_map(function ($setDetail) { | ||||||||||
| return intval($setDetail); | ||||||||||
| }, explode(' ', trim($partieData['detail']))); | ||||||||||
|
Comment on lines
+195
to
+197
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like that ?
Suggested change
|
||||||||||
|
|
||||||||||
| /** @var string $adverssaireA */ | ||||||||||
| $adverssaireA = is_array($partieData['ja']) ? 'Absent Absent' : $this->nomPrenomExtractor->removeSeparatorsDuplication($partieData['ja']); | ||||||||||
| /** @var string $adversaireA */ | ||||||||||
| $adversaireA = is_array($partieData['ja']) ? 'Absent Absent' : $this->nomPrenomExtractor->removeSeparatorsDuplication($partieData['ja']); | ||||||||||
|
|
||||||||||
| /** @var string $adverssaireB */ | ||||||||||
| $adverssaireB = is_array($partieData['jb']) ? 'Absent Absent' : $this->nomPrenomExtractor->removeSeparatorsDuplication($partieData['jb']); | ||||||||||
| /** @var string $adversaireB */ | ||||||||||
| $adversaireB = is_array($partieData['jb']) ? 'Absent Absent' : $this->nomPrenomExtractor->removeSeparatorsDuplication($partieData['jb']); | ||||||||||
|
|
||||||||||
| $parties[] = new Partie( | ||||||||||
| $adverssaireA, | ||||||||||
| $adverssaireB, | ||||||||||
| $adversaireA, | ||||||||||
| $adversaireB, | ||||||||||
| '-' === $partieData['scorea'] ? 0 : (int) $partieData['scorea'], | ||||||||||
| '-' === $partieData['scoreb'] ? 0 : (int) $partieData['scoreb'], | ||||||||||
| $setDetails | ||||||||||
| $setsDetails | ||||||||||
| ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace Alamirault\FFTTApi\Tests\Unit\Service\Operation; | ||
|
|
||
| use Alamirault\FFTTApi\Model\Joueur; | ||
| use Alamirault\FFTTApi\Service\FFTTClient; | ||
| use Alamirault\FFTTApi\Service\NomPrenomExtractor; | ||
| use Alamirault\FFTTApi\Service\Operation\ArrayWrapper; | ||
| use Alamirault\FFTTApi\Service\Operation\ListJoueurOperation; | ||
| use Alamirault\FFTTApi\Service\UriGenerator; | ||
| use GuzzleHttp\Client; | ||
| use GuzzleHttp\HandlerStack; | ||
| use GuzzleHttp\Psr7\Response; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** | ||
| * @coversDefaultClass \Alamirault\FFTTApi\Service\Operation\ListJoueurOperation | ||
| */ | ||
| final class ListJoueurOperationTest extends TestCase | ||
| { | ||
| /** | ||
| * @covers ::listJoueursByClub | ||
| * This covers the route 'xml_liste_joueur_o' | ||
| */ | ||
| public function testListJoueursByClub(): void | ||
| { | ||
| /** @var string $responseContent */ | ||
| $responseContent = file_get_contents(__DIR__.'/../fixtures/ListJoueurOperationTest/liste_joueurs_xml_liste_joueur_o.xml'); | ||
| $mock = new MockHandlerStub([ | ||
| new Response(200, [ | ||
| 'content-type' => ['text/html; charset=UTF-8'], | ||
| ], $responseContent), | ||
| ]); | ||
|
|
||
| $handlerStack = HandlerStack::create($mock); | ||
| $client = new Client(['handler' => $handlerStack]); | ||
| $FFTTClient = new FFTTClient($client, new UriGenerator('foo', 'bar')); | ||
|
|
||
| $operation = new ListJoueurOperation($FFTTClient, new ArrayWrapper(), new NomPrenomExtractor()); | ||
|
|
||
| $result = $operation->listJoueursByClub('05650412'); | ||
|
|
||
| $this->assertCount(7, $result); | ||
| $this->assertEquals(new Joueur('9521866', 'CERGY PONTOISE', '05650412', 'HERNANDEZ', 'Francois', 816, null, null), $result[0]); | ||
| $this->assertEquals(new Joueur('9521899', 'CERGY PONTOISE', '05650412', "DE L'EPREVIER PAVRON-SEC", 'Domìtïlle', 812, null, null), $result[1]); | ||
| $this->assertEquals(new Joueur('9521877', 'CERGY PONTOISE', '05650412', 'NDJOM BASSANAGA', 'Moïse Çéliñó', 1216, null, null), $result[2]); | ||
| $this->assertEquals(new Joueur('95218367', 'CERGY PONTOISE', '05650412', 'ÂBBÄS', 'Ãbdel-Jælil', 1456, 'N', 924), $result[3]); | ||
| $this->assertEquals(new Joueur('9521870', 'CERGY PONTOISE', '05650412', 'GARBANI-LECOURT NEVEU', 'Dimitri-Sébastien', 1456, null, null), $result[4]); | ||
| $this->assertEquals(new Joueur('9521876', 'CERGY PONTOISE', '05650412', 'AMOR QUOINTEAU', 'Erwan', 756, null, null), $result[5]); | ||
| $this->assertEquals(new Joueur('9521888', 'CERGY PONTOISE', '05650412', 'MOREAU', 'Véronique', 1956, 'N', 54), $result[6]); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT of this instead ?