From 5844b4da90756acf741ddd38511dab9ca9e84b67 Mon Sep 17 00:00:00 2001 From: slvler Date: Tue, 3 Dec 2024 14:38:05 +0300 Subject: [PATCH] v2.0.0 --- README.md | 22 +-- composer.json | 45 +++-- src/Api/Api.php | 15 +- src/Api/Coachs.php | 9 +- src/Api/Countries.php | 9 +- src/Api/Fixtures.php | 40 ++-- src/Api/General.php | 8 +- src/Api/Injuries.php | 8 +- src/Api/Leagues.php | 12 +- src/Api/Odds.php | 31 +-- src/Api/Players.php | 37 ++-- src/Api/Predictions.php | 10 +- src/Api/Setting.php | 24 ++- src/Api/Sidelined.php | 9 +- src/Api/Standings.php | 8 +- src/Api/Teams.php | 25 +-- src/Api/Transfers.php | 8 +- src/Api/Trophies.php | 9 +- src/Api/Venues.php | 9 +- src/Exceptions/MissingApiKey.php | 20 ++ src/Exceptions/TransformResponseException.php | 7 +- src/Facedes/LiveScore.php | 3 + src/LiveScoreClient.php | 55 +++--- src/LiveScoreServiceProvider.php | 11 +- src/Log/Record.php | 10 +- src/Message/ResponseTransformer.php | 11 +- tests/LiveSoccerClientTest.php | 178 +++++++++--------- 27 files changed, 362 insertions(+), 271 deletions(-) create mode 100644 src/Exceptions/MissingApiKey.php diff --git a/README.md b/README.md index 43b60a4..bccf31c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # Live Score Service [![tests](https://github.com/slvler/livescore-service/actions/workflows/Tests.yml/badge.svg)](https://github.com/slvler/livescore-service/actions/workflows/Tests.yml) -[![Latest Stable Version](https://poser.pugx.org/slvler/livescore-service/v)](https://packagist.org/packages/slvler/livescore-service) -[![Latest Unstable Version](https://poser.pugx.org/slvler/livescore-service/v/unstable)](https://packagist.org/packages/slvler/livescore-service) +[![Latest Stable Version](https://img.shields.io/packagist/v/slvler/livescore-service.svg)](https://packagist.org/packages/slvler/livescore-service) [![Total Downloads](https://poser.pugx.org/slvler/livescore-service/downloads)](https://packagist.org/packages/slvler/livescore-service) [![License](https://poser.pugx.org/slvler/livescore-service/license)](https://packagist.org/packages/slvler/livescore-service) @@ -10,23 +9,22 @@ Live Score Client for api-football.com Welcome to Api-Football! You can use our API to access all API endpoints, which can get information about Football Leagues & Cups. -## Installation +## Requirements +- PHP 8.1 +- Laravel 9.x | 10.x +## Installation To install this package tou can use composer: - ```bash composer require slvler/livescore-service ``` -## Usage +## Usage - First, you should extract the config/livescore.php file to the config folder. - ```php php artisan vendor:publish --tag=livescore ``` - - API key to be obtained from api-football.com address should be declared. This is your private API key, specific to this API. - ```php 'livescore' => [ 'base_url' => 'v3.football.api-sports.io', @@ -38,7 +36,7 @@ php artisan vendor:publish --tag=livescore ### Example ```php -use slvler\LiveScoreService\LiveScoreClient; +use Slvler\LiveScoreService\LiveScoreClient; $client = new LiveScoreClient(); ``` @@ -370,16 +368,16 @@ $client->odds()->getOddsBets(); ``` ### Testing - ```bash composer test ``` ## Credits - - [slvler](https://github.com/slvler) ## License - The MIT License (MIT). Please see [License File](https://github.com/slvler/btcturk-api/blob/main/LICENSE) for more information. +## Contributing +You're very welcome to contribute. +Please see [CONTRIBUTING](https://github.com/slvler/phone-validation/blob/main/CONTRIBUTING.md) for details. diff --git a/composer.json b/composer.json index 6b1a4b6..510a246 100644 --- a/composer.json +++ b/composer.json @@ -1,43 +1,58 @@ { "name": "slvler/livescore-service", - "license": "MIT", "description": "live score service API for api-football.com", - "type": "package", + "license": "MIT", + "keywords": [ + "livescore", + "laravel", + "php" + ], "authors": [ { "name": "slvler", "email": "slvler@proton.me" } ], + "homepage": "https://github.com/slvler/livescore-service", + "require": { + "php": "^8.1", + "guzzlehttp/guzzle": "^7.2", + "illuminate/support": "^9.0|^10.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.6", + "orchestra/testbench": "^7.0", + "phpunit/phpunit": "^9.5.8", + "laravel/pint": "^1.18" + }, "autoload": { "psr-4": { - "slvler\\LiveScoreService\\": "src/" + "Slvler\\LiveScoreService\\": "src/" } }, "autoload-dev": { "psr-4": { - "slvler\\LiveScoreService\\Tests\\": "tests/" + "Slvler\\LiveScoreService\\Tests\\": "tests/" } }, - "require": {}, - "require-dev": { - "orchestra/testbench": "^6.18.0", - "phpunit/phpunit": "^9.5", - "guzzlehttp/guzzle": "^7.0.1" - }, - "scripts": { - "test": "vendor/bin/phpunit tests" - }, "extra": { "laravel": { "providers": [ - "slvler\\LiveScoreService\\LiveScoreServiceProvider" + "Slvler\\LiveScoreService\\LiveScoreServiceProvider" ], "aliases": { - "LiveScore": "slvler\\LiveScoreService\\Facades\\LiveScore" + "LiveScore": "Slvler\\LiveScoreService\\Facades\\LiveScore" } } }, + "scripts": { + "test": "vendor/bin/phpunit tests --colors=always", + "test-coverage": "vendor/bin/phpunit --coverage-html coverage", + "pint": "vendor/bin/pint", + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ] + }, "minimum-stability": "stable", "prefer-stable": true } diff --git a/src/Api/Api.php b/src/Api/Api.php index cc48e4c..5074108 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -1,11 +1,11 @@ client = $client; } - public function get(string $uri, array $option = []) + public function get(string $uri, array $option = []) { - $response = $this->client->getHttpClient()->request("GET", $uri , $option); + $response = $this->client->getHttpClient()->request('GET', $uri, $option); $this->transformer = new ResponseTransformer($response); + return $this->transformer->toArray(); } - - } diff --git a/src/Api/Coachs.php b/src/Api/Coachs.php index fd8a5c8..7fda134 100644 --- a/src/Api/Coachs.php +++ b/src/Api/Coachs.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/coachs', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } } diff --git a/src/Api/Countries.php b/src/Api/Countries.php index d1354f1..07eee60 100644 --- a/src/Api/Countries.php +++ b/src/Api/Countries.php @@ -1,21 +1,24 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/countries', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } } diff --git a/src/Api/Fixtures.php b/src/Api/Fixtures.php index 5d74c6b..b37d287 100644 --- a/src/Api/Fixtures.php +++ b/src/Api/Fixtures.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/fixtures/rounds', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -23,12 +26,13 @@ public function getFixtures(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/fixtures', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -36,12 +40,13 @@ public function getHeadToHead(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/fixtures/headtohead', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -49,12 +54,13 @@ public function getStatistics(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/fixtures/statistics', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -62,12 +68,13 @@ public function getEvents(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/fixtures/events', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -75,12 +82,13 @@ public function getLineups(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/fixtures/lineups', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -88,13 +96,13 @@ public function getPlayersStatistics(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/fixtures/players', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } - } diff --git a/src/Api/General.php b/src/Api/General.php index d15a1e2..fbac6be 100644 --- a/src/Api/General.php +++ b/src/Api/General.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/status', [ 'base_uri' => 'https://v3.football.api-sports.io', - 'headers' => $headers + 'headers' => $headers, ]); } } diff --git a/src/Api/Injuries.php b/src/Api/Injuries.php index bda6a9b..2d8b006 100644 --- a/src/Api/Injuries.php +++ b/src/Api/Injuries.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/injuries', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } } diff --git a/src/Api/Leagues.php b/src/Api/Leagues.php index aed654e..18a0bf1 100644 --- a/src/Api/Leagues.php +++ b/src/Api/Leagues.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/leagues', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -24,12 +26,12 @@ public function getLeaguesSeasons(): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/leagues/seasons', [ 'base_uri' => 'https://v3.football.api-sports.io', - 'headers' => $headers + 'headers' => $headers, ]); } } diff --git a/src/Api/Odds.php b/src/Api/Odds.php index bf820d8..0a2938e 100644 --- a/src/Api/Odds.php +++ b/src/Api/Odds.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/odds/live', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -24,12 +26,13 @@ public function getOddsLivBets(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/odds/live/bets', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -37,12 +40,13 @@ public function getOdds(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/odds', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -50,13 +54,13 @@ public function getOddsMapping(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/odds/mapping', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -64,13 +68,13 @@ public function getOddsBookmakers(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/odds/bookmakers', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -78,14 +82,13 @@ public function getOddsBets(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/odds/bets', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } - } diff --git a/src/Api/Players.php b/src/Api/Players.php index 133ba04..064a006 100644 --- a/src/Api/Players.php +++ b/src/Api/Players.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/players/seasons', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -23,13 +26,13 @@ public function getPlayers(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/players', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -37,13 +40,13 @@ public function getSquads(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/players/squads', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -51,12 +54,13 @@ public function getTopScorers(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/players/topscorers', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -64,12 +68,13 @@ public function getTopAssists(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/players/topassists', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -77,13 +82,13 @@ public function getTopYellowCards(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/players/topyellowcards', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -91,15 +96,13 @@ public function getTopRedCards(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/players/topredcards', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } - - } diff --git a/src/Api/Predictions.php b/src/Api/Predictions.php index 51c9b05..620694f 100644 --- a/src/Api/Predictions.php +++ b/src/Api/Predictions.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/predictions', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } - } diff --git a/src/Api/Setting.php b/src/Api/Setting.php index 596ef4d..d86bda1 100644 --- a/src/Api/Setting.php +++ b/src/Api/Setting.php @@ -1,19 +1,31 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/sidelined', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } } diff --git a/src/Api/Standings.php b/src/Api/Standings.php index 0e82360..79963c2 100644 --- a/src/Api/Standings.php +++ b/src/Api/Standings.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/standings', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } } diff --git a/src/Api/Teams.php b/src/Api/Teams.php index e062b8a..ef31f03 100644 --- a/src/Api/Teams.php +++ b/src/Api/Teams.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/teams', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -24,12 +26,13 @@ public function getTeamsStatistics(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/teams/statistics', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -37,12 +40,13 @@ public function getTeamsSeasons(array $params = []): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/teams/seasons', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } @@ -50,13 +54,12 @@ public function getTeamCountries(): array { $headers = [ 'x-rapidapi-host' => Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/teams/countries', [ 'base_uri' => 'https://v3.football.api-sports.io', - 'headers' => $headers + 'headers' => $headers, ]); } - - } diff --git a/src/Api/Transfers.php b/src/Api/Transfers.php index 45c8d49..0ef6e59 100644 --- a/src/Api/Transfers.php +++ b/src/Api/Transfers.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; return $this->get('/transfers', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } } diff --git a/src/Api/Trophies.php b/src/Api/Trophies.php index 102040c..22d28fd 100644 --- a/src/Api/Trophies.php +++ b/src/Api/Trophies.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/trophies', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } } diff --git a/src/Api/Venues.php b/src/Api/Venues.php index 94334fe..5147487 100644 --- a/src/Api/Venues.php +++ b/src/Api/Venues.php @@ -1,6 +1,8 @@ Setting::getBaseUrl(), - "x-rapidapi-key" => Setting::getApiKey() + 'x-rapidapi-key' => Setting::getApiKey(), ]; + return $this->get('/venues', [ 'base_uri' => 'https://v3.football.api-sports.io', 'headers' => $headers, - 'query' => $params + 'query' => $params, ]); } } diff --git a/src/Exceptions/MissingApiKey.php b/src/Exceptions/MissingApiKey.php new file mode 100644 index 0000000..68cac95 --- /dev/null +++ b/src/Exceptions/MissingApiKey.php @@ -0,0 +1,20 @@ +logged = new Record(); + $this->logged = new Record; $this->httpClient = $client ?: new Client( [ - 'handler' => $this->logged->loggered() + 'handler' => $this->logged->loggered(), ]); } @@ -43,62 +41,77 @@ public function getHttpClient(): Client { return $this->httpClient; } + public function countries(): Countries { return new Countries($this); } + public function leagues(): Leagues { return new Leagues($this); } + public function general(): General { return new General($this); } + public function team(): Teams { return new Teams($this); } + public function venues(): Venues { return new Venues($this); } + public function standings(): Standings { return new Standings($this); } + public function fixtures(): Fixtures { return new Fixtures($this); } + public function injuries(): Injuries { return new Injuries($this); } + public function predictions(): Predictions { return new Predictions($this); } + public function coachs(): Coachs { return new Coachs($this); } + public function players(): Players { return new Players($this); } + public function transfer(): Transfers { return new Transfers($this); } + public function trophies(): Trophies { return new Trophies($this); } + public function sidelined(): Sidelined { return new Sidelined($this); } + public function odds(): Odds { return new Odds($this); diff --git a/src/LiveScoreServiceProvider.php b/src/LiveScoreServiceProvider.php index 3709c6b..8082fbc 100644 --- a/src/LiveScoreServiceProvider.php +++ b/src/LiveScoreServiceProvider.php @@ -1,18 +1,21 @@ app->bind('LiveScore', function($app) { + $this->app->bind('LiveScore', function ($app) { return new LiveScore(); }); } + public function boot() { if ($this->app->runningInConsole()) { @@ -26,8 +29,4 @@ protected function publishResources() __DIR__.'/../config/livescore.php' => config_path('livescore.php'), ], 'livescore'); } - - - - } diff --git a/src/Log/Record.php b/src/Log/Record.php index deb58e2..50773af 100644 --- a/src/Log/Record.php +++ b/src/Log/Record.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace slvler\LiveScoreService\Log; +namespace Slvler\LiveScoreService\Log; use GuzzleHttp\HandlerStack; use GuzzleHttp\MessageFormatter; @@ -12,21 +12,21 @@ class Record { + const logName = 'LiveScore'; - CONST logName = 'LiveScore'; - CONST logFile = 'LiveScore.log'; + const logFile = 'LiveScore.log'; public function loggered() { $logger = new Logger(self::logName); - $logger->pushHandler(new StreamHandler(__DIR__ . '/'. self::logFile)); + $logger->pushHandler(new StreamHandler(__DIR__.'/'.self::logFile)); $stack = HandlerStack::create(); $stack->push(Middleware::log( $logger, new MessageFormatter('{req_body} - {res_body}') )); + return $stack; } - } diff --git a/src/Message/ResponseTransformer.php b/src/Message/ResponseTransformer.php index e82708e..f277454 100644 --- a/src/Message/ResponseTransformer.php +++ b/src/Message/ResponseTransformer.php @@ -1,11 +1,10 @@ response->getBody(); } + public function toArray(): array { $body = (string) $this->response->getBody(); if (strpos($this->response->getHeaderLine('Content-Type'), 'application/json') === 0) { $content = json_decode($body, true); - if (JSON_ERROR_NONE === json_last_error()) { + if (json_last_error() === JSON_ERROR_NONE) { return $content; } throw new TransformResponseException('Error transforming response to array. JSON_ERROR: ' - . json_last_error() . ' --' . $body . '---'); + .json_last_error().' --'.$body.'---'); } throw new TransformResponseException('Error transforming response to array. Content-Type is not application/json'); } - } diff --git a/tests/LiveSoccerClientTest.php b/tests/LiveSoccerClientTest.php index 57040ba..9ac1971 100644 --- a/tests/LiveSoccerClientTest.php +++ b/tests/LiveSoccerClientTest.php @@ -7,256 +7,248 @@ class LiveSoccerClientTest extends TestCase { - public function testgetAll() + public function testget_all() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->countries()->getAll(['code' => 'FR', 'name' => 'england']); $this->assertIsArray($variable); } - public function testgetLeagues() + + public function testget_leagues() { - $client = new LiveScoreClient(); - $variable =$client->leagues()->getLeagues(['season' => '2018', 'id' => '33']); + $client = new LiveScoreClient; + $variable = $client->leagues()->getLeagues(['season' => '2018', 'id' => '33']); $this->assertIsArray($variable); } - public function testgetLeaguesSeasons() + + public function testget_leagues_seasons() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->leagues()->getLeaguesSeasons(); $this->assertIsArray($variable); } - public function testgetTeamsInformation() + + public function testget_teams_information() { - $client = new LiveScoreClient(); - $variable = $client->team()->getTeamsInformation(['id' => "33"]); + $client = new LiveScoreClient; + $variable = $client->team()->getTeamsInformation(['id' => '33']); $this->assertIsArray($variable); } - public function testgetTeamsStatistics() + public function testget_teams_statistics() { - $client = new LiveScoreClient(); - $variable = $client->team()->getTeamsStatistics(['league' => '39', 'team' => '33', 'season' => '2019']); + $client = new LiveScoreClient; + $variable = $client->team()->getTeamsStatistics(['league' => '39', 'team' => '33', 'season' => '2019']); $this->assertIsArray($variable); } - public function testgetTeamCountries() + public function testget_team_countries() { - $client = new LiveScoreClient(); - $variable = $client->team()->getTeamsStatistics(['league' => '39', 'team' => '33', 'season' => '2019']); + $client = new LiveScoreClient; + $variable = $client->team()->getTeamsStatistics(['league' => '39', 'team' => '33', 'season' => '2019']); $this->assertIsArray($variable); } - public function testgetVenues() + public function testget_venues() { - $client = new LiveScoreClient(); - $variable = $client->venues()->getVenues([ 'name' => 'Old Trafford']); + $client = new LiveScoreClient; + $variable = $client->venues()->getVenues(['name' => 'Old Trafford']); $this->assertIsArray($variable); } - public function testgetStandings() + public function testget_standings() { - $client = new LiveScoreClient(); - $variable = $client->standings()->getStandings([ 'league' => '39', 'season' => '2019']); + $client = new LiveScoreClient; + $variable = $client->standings()->getStandings(['league' => '39', 'season' => '2019']); $this->assertIsArray($variable); } - public function testgetRounds() + public function testget_rounds() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->fixtures()->getRounds(['league' => '39', 'season' => 2019]); $this->assertIsArray($variable); } - public function testgetFixtures() + public function testget_fixtures() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->fixtures()->getFixtures(['id' => '215662']); $this->assertIsArray($variable); } - public function testgetHeadToHead() + public function testget_head_to_head() { - $client = new LiveScoreClient(); - $variable = $client->fixtures()->getHeadToHead(['h2h' => '33-34']); + $client = new LiveScoreClient; + $variable = $client->fixtures()->getHeadToHead(['h2h' => '33-34']); $this->assertIsArray($variable); } - public function testgetStatistics() + public function testget_statistics() { - $client = new LiveScoreClient(); - $variable = $client->fixtures()->getStatistics(['fixture' => '215662']); + $client = new LiveScoreClient; + $variable = $client->fixtures()->getStatistics(['fixture' => '215662']); $this->assertIsArray($variable); } - public function testgetEvents() + public function testget_events() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->fixtures()->getEvents(['fixture' => '215662']); $this->assertIsArray($variable); } - public function testgetLineups() + public function testget_lineups() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->fixtures()->getLineups(['fixture' => '592872']); $this->assertIsArray($variable); } - public function testgetPlayersStatistics() + public function testget_players_statistics() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->fixtures()->getPlayersStatistics(['fixture' => '169080']); $this->assertIsArray($variable); } - public function testgetInjuries() + public function testget_injuries() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->injuries()->getInjuries(['league' => '2', 'season' => '2020']); $this->assertIsArray($variable); } - public function testgetPredictions() + public function testget_predictions() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->predictions()->getPredictions(['fixture' => '198772']); $this->assertIsArray($variable); } - public function testgetCoachs() + public function testget_coachs() { - $client = new LiveScoreClient(); - $variable = $client->coachs()->getCoachs(['id' => '1']); + $client = new LiveScoreClient; + $variable = $client->coachs()->getCoachs(['id' => '1']); $this->assertIsArray($variable); } - public function testgetSeasons() + public function testget_seasons() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->players()->getSeasons(['player' => '276']); $this->assertIsArray($variable); } - public function testgetPlayers() + public function testget_players() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->players()->getPlayers(['id' => '19088', 'season' => '2018']); $this->assertIsArray($variable); } - public function testgetSquads() + public function testget_squads() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->players()->getSquads(['team' => '33']); $this->assertIsArray($variable); } - public function testgetTopScorers() + public function testget_top_scorers() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->players()->getTopScorers(['season' => '2018', 'league' => '61']); $this->assertIsArray($variable); } - public function testgetTopAssists() + public function testget_top_assists() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->players()->getTopAssists(['season' => '2020', 'league' => '61']); $this->assertIsArray($variable); } - public function testgetTopYellowCards() + public function testget_top_yellow_cards() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->players()->getTopYellowCards(['season' => '2020', 'league' => '61']); $this->assertIsArray($variable); } - public function testgetTopRedCards() + public function testget_top_red_cards() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->players()->getTopRedCards(['season' => '2020', 'league' => '61']); $this->assertIsArray($variable); } - public function testgetTransfer() + public function testget_transfer() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->transfer()->getTransfer(['player' => '35845']); $this->assertIsArray($variable); } - public function testgetTrophies() + public function testget_trophies() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->trophies()->getTrophies(['player' => '35845']); $this->assertIsArray($variable); } - public function testgetSidelined() + public function testget_sidelined() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->sidelined()->getSidelined(['player' => '276']); $this->assertIsArray($variable); } - public function testgetOddsLive() + public function testget_odds_live() { - $client = new LiveScoreClient(); - $variable = $client->odds()->getOddsLive(); + $client = new LiveScoreClient; + $variable = $client->odds()->getOddsLive(); $this->assertIsArray($variable); } - public function testgetOddsLivBets() + public function testget_odds_liv_bets() { - $client = new LiveScoreClient(); - $variable = $client->odds()->getOddsLivBets(['id' => "1"]); + $client = new LiveScoreClient; + $variable = $client->odds()->getOddsLivBets(['id' => '1']); $this->assertIsArray($variable); } - public function testgetOdds() + public function testget_odds() { - $client = new LiveScoreClient(); - $variable = $client->odds()->getOdds(['date' => "2020-05-15"]); + $client = new LiveScoreClient; + $variable = $client->odds()->getOdds(['date' => '2020-05-15']); $this->assertIsArray($variable); } - public function testgetOddsMapping() + public function testget_odds_mapping() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->odds()->getOddsMapping(); $this->assertIsArray($variable); } - public function testgetOddsBookmakers() + public function testget_odds_bookmakers() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->odds()->getOddsBookmakers(); $this->assertIsArray($variable); } - public function testgetOddsBets() + public function testget_odds_bets() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->odds()->getOddsBets(); $this->assertIsArray($variable); } - public function testgetStatus() + public function testget_status() { - $client = new LiveScoreClient(); + $client = new LiveScoreClient; $variable = $client->general()->getStatus(); $this->assertIsArray($variable); } - - - - - - - - - - - }