Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Use Sofascore
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Jul 7, 2024
1 parent 5b34613 commit 8638b2b
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 273 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.github/ export-ignore
/tests/ export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
12 changes: 6 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
php-versions: ['8.1', '8.2', '8.3']
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
Expand All @@ -26,7 +26,7 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down Expand Up @@ -58,13 +58,13 @@ jobs:
- name: Archive logs
if: ${{ failure() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: logs
name: logs-php-${{ matrix.php-versions }}
path: vendor/endroid/quality/application/var/log

- name: Archive code coverage results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage
name: coverage-php-${{ matrix.php-versions }}
path: tests/coverage
6 changes: 1 addition & 5 deletions src/Loader/TeamLoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

namespace Endroid\SoccerData\Loader;

use Endroid\SoccerData\Model\Competition;
use Endroid\SoccerData\Model\Team;

interface TeamLoaderInterface
{
public function loadByName(string $name): Team;

/** @return array<Team> */
public function loadByCompetition(Competition $competition): array;
public function load(string $identifier): Team;
}
2 changes: 1 addition & 1 deletion src/Model/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
final class Game
{
public function __construct(
public readonly string $id,
public readonly string|int $id,
public readonly \DateTimeImmutable $date,
public readonly Team $teamHome,
public readonly Team $teamAway,
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class Team
private array $games = [];

public function __construct(
public readonly string $id,
public readonly string|int $id,
public readonly string $name
) {
}
Expand Down
48 changes: 48 additions & 0 deletions src/Sofascore/Loader/TeamLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Endroid\SoccerData\Sofascore\Loader;

use Endroid\SoccerData\Loader\TeamLoaderInterface;
use Endroid\SoccerData\Model\Game;
use Endroid\SoccerData\Model\Team;

final class TeamLoader implements TeamLoaderInterface
{
/** @var array<Team> */
private array $teams = [];

public function load(string $identifier): Team
{
if (isset($this->teams[$identifier])) {
return $this->teams[$identifier];
}

$searchUrl = 'https://www.sofascore.com/api/v1/search/all?q='.urlencode($identifier).'&sport=soccer';
$contents = file_get_contents($searchUrl);
$searchData = json_decode($contents, true);

Check failure on line 24 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 24 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 24 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 24 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 24 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 24 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #1 $json of function json_decode expects string, string|false given.

$team = new Team(
$searchData['results'][0]['entity']['id'],
$searchData['results'][0]['entity']['shortName']
);

$gamesUrl = 'https://www.sofascore.com/api/v1/team/'.$team->id.'/events/next/0';
$contents = file_get_contents($gamesUrl);
$gamesData = json_decode($contents, true);

Check failure on line 33 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 33 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 33 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 33 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 33 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 33 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #1 $json of function json_decode expects string, string|false given.

foreach ($gamesData['events'] as $event) {
$game = new Game(
$event['id'],
\DateTimeImmutable::createFromFormat('U', (string) $event['startTimestamp']),

Check failure on line 38 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Parameter #2 $date of class Endroid\SoccerData\Model\Game constructor expects DateTimeImmutable, DateTimeImmutable|false given.

Check failure on line 38 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #2 $date of class Endroid\SoccerData\Model\Game constructor expects DateTimeImmutable, DateTimeImmutable|false given.

Check failure on line 38 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #2 $date of class Endroid\SoccerData\Model\Game constructor expects DateTimeImmutable, DateTimeImmutable|false given.

Check failure on line 38 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Parameter #2 $date of class Endroid\SoccerData\Model\Game constructor expects DateTimeImmutable, DateTimeImmutable|false given.

Check failure on line 38 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #2 $date of class Endroid\SoccerData\Model\Game constructor expects DateTimeImmutable, DateTimeImmutable|false given.

Check failure on line 38 in src/Sofascore/Loader/TeamLoader.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #2 $date of class Endroid\SoccerData\Model\Game constructor expects DateTimeImmutable, DateTimeImmutable|false given.
new Team($event['homeTeam']['id'], $event['homeTeam']['shortName']),
new Team($event['awayTeam']['id'], $event['awayTeam']['shortName']),
null
);
$team->addGame($game);
}

return $team;
}
}
43 changes: 0 additions & 43 deletions src/Vi/Client.php

This file was deleted.

37 changes: 0 additions & 37 deletions src/Vi/Loader/CompetitionLoader.php

This file was deleted.

93 changes: 0 additions & 93 deletions src/Vi/Loader/GameLoader.php

This file was deleted.

52 changes: 0 additions & 52 deletions src/Vi/Loader/TeamLoader.php

This file was deleted.

35 changes: 0 additions & 35 deletions tests/Vi/Loader/GameLoaderTest.php

This file was deleted.

Loading

0 comments on commit 8638b2b

Please sign in to comment.