blood72 / laravel-riot-api

Riot API wrapper for Laravel
MIT License
3 stars 1 forks source link

Setup Error #1

Closed safakocamanoglu closed 4 years ago

safakocamanoglu commented 4 years ago

When I run composer for installation I get argument error

composer require blood72/laravel-riot-api

Terminal error code start

@php artisan package:discover --ansi

TypeError

Argument 1 passed to RiotAPI\DataDragonAPI\DataDragonAPI::initByRegion() must be of the type string, null given, called in D:\AppServ\www\test\vendor\blood72\laravel-riot-api\src\Rio tAPIServiceProvider.php on line 88

at D:\AppServ\www\test\vendor\dolejska-daniel\riot-api\src\DataDragonAPI\DataDragonAPI.php:227 223| @param array $customSettings 224| 225| @throws RequestException 226| / -> 227| public static function initByRegion( string $region_name, array $customSettings = [] ) 228| { 229| $region_name = strtolower($region_name); 230| $data = file_get_contents(self::getDataDragonUrl() . "/realms/$region_name.json"); 231| if ($data == false)

1 D:\AppServ\www\test\vendor\blood72\laravel-riot-api\src\RiotAPIServiceProvider.php:88 RiotAPI\DataDragonAPI\DataDragonAPI::initByRegion([])

2 D:\AppServ\www\test\vendor\blood72\laravel-riot-api\src\RiotAPIServiceProvider.php:40 Blood72\RiotAPI\RiotAPIServiceProvider::resolveDataDragonAPI() Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Installation failed, reverting ./composer.json to its original content.

Terminal error code finish

I'm new to Laravel yet, couldn't find a valid method to run the package. Thank you in advance for your help

blood72 commented 4 years ago

I checked this problem. The problem was that the service provider's parameter exception was insufficient. The current issue is where the DataDragon API checks the region value and it is null (or invalid region).

Define the RIOT_API_REGION value in the .env file with valid region.

I will make sure that the project can be run without invalid variables. Thank you for reporting!

safakocamanoglu commented 4 years ago

In addition, When running scripts inside the controller

  1. Method )
use RiotAPI\LeagueAPI\LeagueAPI; 

$summoner = app('league-api')->getSummonerByName('__SOMEONE__');
$matchList = LeagueAPI::getMatchlistByAccount($summoner->accountId);

When we use it as above, we get an error saying "Non-static method RiotAPI\LeagueAPI\LeagueAPI::getMatchlistByAccount() should not be called statically".

  1. Method )
    
    use LeagueAPI;

$summoner = app('league-api')->getSummonerByName('SOMEONE'); $matchList = LeagueAPI::getMatchlistByAccount($summoner->accountId);


It works fine when used this way, but phpstorm does not show the hints of the code to be used after writing "LegueAPI ::". example: getMatchlistByAccount () function and parameters

3. Method )
As in the 2nd method, when used in this way, the api query works, but the suggestions do not appear.

use LeagueAPI;

$summoner = app('league-api')->getSummonerByName('SOMEONE'); $matchList = app('league-api')->getMatchlistByAccount($summoner->accountId);


You are tired of me, but what is your recommendation for correct use?
blood72 commented 4 years ago

My first language is not English, so please understand even if there is an error in context.


LeagueAPI and RiotAPI\LeagueAPI\LeagueAPI are definitely different classes. (for more information, see PSR-4) RiotAPI\LeagueAPI\LeagueAPI has not yet created an object. So, non-static methods cannot be used.

LeagueAPI used Laravel's Facades concept, app() and resolve() are Laravel's helper function. These call up objects defined by the service provider. It will be helpful if you refer to Architecture Concepts > Facades in the Laravel document. This requires an understanding of dependancy injection first.

Code analysis is performed dynamically and therefore may not be properly worked in IDE. Here is a useful package that solves this. https://github.com/barryvdh/laravel-ide-helper