Skip to content

Commit

Permalink
Introduce facades (#6)
Browse files Browse the repository at this point in the history
* ♻️ Optimize Card Model
* ✨ Introduce model facades
* ✨ Introduce alias methods for card model
* ✅ Add tests
* 📝 Add alias methods to README
  • Loading branch information
marcreichel authored Nov 3, 2021
1 parent adebaae commit 1a06e39
Show file tree
Hide file tree
Showing 13 changed files with 642 additions and 40 deletions.
88 changes: 83 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ $cards = Pokemontcg::cards();
Find a specific card by its id:
```php
$cards->find('Test-111');

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::find('Test-111');
```

###### Search by hp ($from, $to)
Expand All @@ -64,12 +70,26 @@ Find Pokémon's based on HP:
$from = "1";
$to = "100";
$cards->hp($from, $to);

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::hp($from, $to);
Card::whereHp($from, $to); // alias
```

###### Search by name
Find Pokémon's based on their name:
```php
$cards->name('Charizard');

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::name('Charizard');
Card::whereName('Charizard'); // alias
```

###### Search Pokémon by Pokédex entries ($from, $to)
Expand All @@ -78,19 +98,41 @@ Find Pokémon's based on their name:
$from = "1";
$to = "151";
$cards->pokedex($from, $to);

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::pokedex($from, $to);
Card::wherePokedex($from, $to); // alias
```

###### Search by supertypes
Find Pokémon's by `supertypes` and `types`:
```php
$cards->supertype('mega');
$cards->supertype('mega', 'water');

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::supertype('mega');
Card::supertype('mega', 'water');
Card::whereSupertype('mega'); // alias
Card::whereSupertype('mega', 'water'); // alias
```

###### Search query
Search Pokémon's based on a query string - for more details on how the query works check out: [Pokemontcg search cards](https://docs.pokemontcg.io/api-reference/cards/search-cards).
```php
$cards->search('name:Char*zard supertype:mega -type:fire');

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::search('name:Char*zard supertype:mega -type:fire');
```

#### Sets
Expand All @@ -102,13 +144,25 @@ $sets = Pokemontcg::sets();
###### Find by id
Find a specific set by its id:
```php
$sets->find('set-name')
$sets->find('set-name');

// or

use \Slatyo\LaravelPokemontcg\Facades\Set;

Set::find('set-name');
```

###### Search query
Search Pokémon sets based on a query string - for more details on how the query works check out: [Pokemontcg search sets](https://docs.pokemontcg.io/api-reference/sets/search-cards).
```php
$sets->search('legalities.standard:legal');

// or

use \Slatyo\LaravelPokemontcg\Facades\Set;

Set::search('legalities.standard:legal');
```

#### Supertypes
Expand All @@ -121,7 +175,13 @@ $supertypes = Pokemontcg::supertypes();
###### Get all
Return all `supertypes`:
```php
$supertypes->all()
$supertypes->all();

// or

use \Slatyo\LaravelPokemontcg\Facades\Supertype;

Supertype::all();
```

#### Subtypes
Expand All @@ -133,7 +193,13 @@ $subtypes = Pokemontcg::subtypes();
###### Get all
Return all `subtypes`:
```php
$subtypes->all()
$subtypes->all();

// or

use \Slatyo\LaravelPokemontcg\Facades\Subtype;

Subtype::all();
```

#### Types
Expand All @@ -145,7 +211,13 @@ $types = Pokemontcg::types();
###### Get all
Return all `types`:
```php
$types->all()
$types->all();

// or

use \Slatyo\LaravelPokemontcg\Facades\Type;

Type::all();
```

#### Rarities
Expand All @@ -157,7 +229,13 @@ $rarities = Pokemontcg::rarities();
###### Get all
Return all `rarities`:
```php
$rarities->all()
$rarities->all();

// or

use \Slatyo\LaravelPokemontcg\Facades\Rarity;

Rarity::all();
```

### Testing
Expand Down
22 changes: 0 additions & 22 deletions build/report.junit.xml

This file was deleted.

8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@
"Slatyo\\LaravelPokemontcg\\LaravelPokemontcgServiceProvider"
],
"aliases": {
"LaravelPokemontcg": "Slatyo\\LaravelPokemontcg\\LaravelPokemontcgFacade"
"LaravelPokemontcg": "Slatyo\\LaravelPokemontcg\\Facades\\Pokemontcg",
"PokemontcgCard": "Slatyo\\LaravelPokemontcg\\Facades\\Card",
"PokemontcgRarity": "Slatyo\\LaravelPokemontcg\\Facades\\Rarity",
"PokemontcgSet": "Slatyo\\LaravelPokemontcg\\Facades\\Set",
"PokemontcgSubtype": "Slatyo\\LaravelPokemontcg\\Facades\\Subtype",
"PokemontcgSupertype": "Slatyo\\LaravelPokemontcg\\Facades\\Supertype",
"PokemontcgType": "Slatyo\\LaravelPokemontcg\\Facades\\Type"
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/Facades/Card.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Slatyo\LaravelPokemontcg\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static mixed find(string $pokemonTcgId)
* @method static mixed search(string $query, int $page = 1, int|string $pageSize = \Slatyo\LaravelPokemontcg\Models\Card::MAXIMUM_PAGE_SIZE, string $orderBy = '')
* @method static mixed name(string $pokemon, bool $strict = false)
* @method static mixed whereName(string $pokemon, bool $strict = false)
* @method static mixed supertype(string $supertype, string $type = '')
* @method static mixed whereSupertype(string $supertype, string $type = '')
* @method static mixed pokedex(string $from, string $to)
* @method static mixed wherePokedex(string $from, string $to)
* @method static mixed hp(string $from, string $to)
* @method static mixed whereHp(string $from, string $to)
*/
class Card extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return 'pokemontcg-card';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Slatyo\LaravelPokemontcg;
namespace Slatyo\LaravelPokemontcg\Facades;

use Illuminate\Support\Facades\Facade;

class LaravelPokemontcgFacade extends Facade
class Pokemontcg extends Facade
{
/**
* Get the registered name of the component.
Expand Down
21 changes: 21 additions & 0 deletions src/Facades/Rarity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Slatyo\LaravelPokemontcg\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static mixed all()
*/
class Rarity extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return 'pokemontcg-rarity';
}
}
22 changes: 22 additions & 0 deletions src/Facades/Set.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Slatyo\LaravelPokemontcg\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static mixed find(string $set)
* @method static mixed search(string $query, int $page = 1, int|string $pageSize = \Slatyo\LaravelPokemontcg\Models\Set::MAXIMUM_PAGE_SIZE, string $orderBy = '')
*/
class Set extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return 'pokemontcg-set';
}
}
21 changes: 21 additions & 0 deletions src/Facades/Subtype.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Slatyo\LaravelPokemontcg\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static mixed all()
*/
class Subtype extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return 'pokemontcg-subtype';
}
}
21 changes: 21 additions & 0 deletions src/Facades/Supertype.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Slatyo\LaravelPokemontcg\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static mixed all()
*/
class Supertype extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return 'pokemontcg-supertype';
}
}
21 changes: 21 additions & 0 deletions src/Facades/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Slatyo\LaravelPokemontcg\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static mixed all()
*/
class Type extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return 'pokemontcg-type';
}
}
Loading

0 comments on commit 1a06e39

Please sign in to comment.