diff --git a/README.md b/README.md index a43e5faa..4bf489cf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Hummingbird Anime Client -Update your anime/manga list on Kitsu.io and MyAnimeList.net +Update your anime/manga list on Kitsu.io and Anilist -[![Build Status](https://travis-ci.org/timw4mail/HummingBirdAnimeClient.svg?branch=master)](https://travis-ci.org/timw4mail/HummingBirdAnimeClient) +[![Build Status](https://travis-ci.com/timw4mail/HummingBirdAnimeClient.svg?branch=master)](https://travis-ci.com/github/timw4mail/HummingBirdAnimeClient) [![Build Status](https://jenkins.timshomepage.net/buildStatus/icon?job=timw4mail/HummingBirdAnimeClient/develop)](https://jenkins.timshomepage.net/job/timw4mail/HummingBirdAnimeClient/develop) [[Hosted Example](https://list.timshomepage.net)] @@ -31,7 +31,7 @@ Update your anime/manga list on Kitsu.io and MyAnimeList.net ### Requirements -* PHP 7.3+ +* PHP 7.4+ * PDO SQLite or PDO PostgreSQL (For collection tab) * GD extension for caching images diff --git a/composer.json b/composer.json index b166b893..875ff6cd 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "laminas/laminas-httphandlerrunner": "^1.0", "maximebf/consolekit": "^1.0", "monolog/monolog": "^2.0.1", - "php": "^7.4 || ^8", + "php": ">=7.4", "psr/container": "~1.0", "psr/http-message": "~1.0", "psr/log": "~1.0", diff --git a/src/AnimeClient/API/APIRequestBuilder.php b/src/AnimeClient/API/APIRequestBuilder.php index 1e145f5d..24ca4df4 100644 --- a/src/AnimeClient/API/APIRequestBuilder.php +++ b/src/AnimeClient/API/APIRequestBuilder.php @@ -38,31 +38,31 @@ abstract class APIRequestBuilder { * Url prefix for making url requests * @var string */ - protected $baseUrl = ''; + protected string $baseUrl = ''; /** * Url path of the request * @var string */ - protected $path = ''; + protected string $path = ''; /** * Query string for the request * @var string */ - protected $query = ''; + protected string $query = ''; /** * Default request headers * @var array */ - protected $defaultHeaders = []; + protected array $defaultHeaders = []; /** * Valid HTTP request methods * @var array */ - protected $validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']; + protected array $validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']; /** * The current request diff --git a/src/AnimeClient/API/Anilist/AnilistRequestBuilder.php b/src/AnimeClient/API/Anilist/AnilistRequestBuilder.php index 5504c13c..d2398f91 100644 --- a/src/AnimeClient/API/Anilist/AnilistRequestBuilder.php +++ b/src/AnimeClient/API/Anilist/AnilistRequestBuilder.php @@ -26,20 +26,20 @@ final class AnilistRequestBuilder extends APIRequestBuilder { * The base url for api requests * @var string $base_url */ - protected $baseUrl = 'https://graphql.anilist.co'; + protected string $baseUrl = 'https://graphql.anilist.co'; /** * Valid HTTP request methods * @var array */ - protected $validMethods = ['POST']; + protected array $validMethods = ['POST']; /** * HTTP headers to send with every request * * @var array */ - protected $defaultHeaders = [ + protected array $defaultHeaders = [ 'User-Agent' => USER_AGENT, 'Accept' => 'application/json', 'Content-Type' => 'application/json', diff --git a/src/AnimeClient/API/Kitsu/KitsuRequestBuilder.php b/src/AnimeClient/API/Kitsu/KitsuRequestBuilder.php index b933328c..aa105062 100644 --- a/src/AnimeClient/API/Kitsu/KitsuRequestBuilder.php +++ b/src/AnimeClient/API/Kitsu/KitsuRequestBuilder.php @@ -25,14 +25,14 @@ final class KitsuRequestBuilder extends APIRequestBuilder { * The base url for api requests * @var string $base_url */ - protected $baseUrl = 'https://kitsu.io/api/edge/'; + protected string $baseUrl = 'https://kitsu.io/api/edge/'; /** * HTTP headers to send with every request * * @var array */ - protected $defaultHeaders = [ + protected array $defaultHeaders = [ 'User-Agent' => USER_AGENT, 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json', diff --git a/src/AnimeClient/API/Kitsu/Transformer/AnimeListTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/AnimeListTransformer.php index e4942909..5c0d8ff8 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/AnimeListTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/AnimeListTransformer.php @@ -22,6 +22,7 @@ use Aviat\AnimeClient\Types\{ AnimeListItem }; use Aviat\Ion\Transformer\AbstractTransformer; +use Aviat\Ion\Type\StringType; /** * Transformer for anime list @@ -100,7 +101,7 @@ final class AnimeListTransformer extends AbstractTransformer { 'title' => $title, 'titles' => $titles, 'slug' => $anime['slug'], - 'show_type' => (string)$this->string($anime['subtype'])->upperCaseFirst(), + 'show_type' => (string)StringType::from($anime['subtype'])->upperCaseFirst(), 'cover_image' => $anime['posterImage']['small'], 'genres' => $genres, 'streaming_links' => $streamingLinks, diff --git a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php index fc93827c..5a339567 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php @@ -19,6 +19,7 @@ namespace Aviat\AnimeClient\API\Kitsu\Transformer; use Aviat\AnimeClient\API\{JsonAPI, Kitsu}; use Aviat\AnimeClient\Types\AnimePage; use Aviat\Ion\Transformer\AbstractTransformer; +use Aviat\Ion\Type\StringType; /** * Transformer for anime description page @@ -114,7 +115,7 @@ final class AnimeTransformer extends AbstractTransformer { 'genres' => $item['genres'], 'id' => $item['id'], 'included' => $item['included'], - 'show_type' => (string)$this->string($item['showType'])->upperCaseFirst(), + 'show_type' => (string)StringType::from($item['showType'])->upperCaseFirst(), 'slug' => $item['slug'], 'staff' => $staff, 'status' => Kitsu::getAiringStatus($item['startDate'], $item['endDate']), diff --git a/src/AnimeClient/API/Kitsu/Transformer/MangaListTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/MangaListTransformer.php index 83cc7d0a..e8b5570f 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/MangaListTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/MangaListTransformer.php @@ -21,16 +21,13 @@ use Aviat\AnimeClient\Types\{ FormItem, FormItemData, MangaListItem, MangaListItemDetail }; -use Aviat\Ion\StringWrapper; use Aviat\Ion\Transformer\AbstractTransformer; +use Aviat\Ion\Type\StringType; /** * Data transformation class for zippered Hummingbird manga */ final class MangaListTransformer extends AbstractTransformer { - - use StringWrapper; - /** * Remap zipped anime data to a more logical form * @@ -103,7 +100,7 @@ final class MangaListTransformer extends AbstractTransformer { 'slug' => $manga['slug'], 'title' => $title, 'titles' => $titles, - 'type' => (string)$this->string($manga['subtype'])->upperCaseFirst(), + 'type' => (string)StringType::from($manga['subtype'])->upperCaseFirst(), 'url' => 'https://kitsu.io/manga/' . $manga['slug'], ]), 'reading_status' => $item['attributes']['status'], diff --git a/src/AnimeClient/Dispatcher.php b/src/AnimeClient/Dispatcher.php index 3178744d..f2eda039 100644 --- a/src/AnimeClient/Dispatcher.php +++ b/src/AnimeClient/Dispatcher.php @@ -23,8 +23,7 @@ use Aura\Router\{Matcher, Route, Rule}; use Aviat\AnimeClient\API\FailedResponseException; use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Friend; -use Aviat\Ion\StringWrapper; - +use Aviat\Ion\Type\StringType; use LogicException; use ReflectionException; @@ -33,8 +32,6 @@ use ReflectionException; */ final class Dispatcher extends RoutingBase { - use StringWrapper; - /** * The route-matching object * @var object $router @@ -45,19 +42,19 @@ final class Dispatcher extends RoutingBase { * The route matcher * @var Matcher $matcher */ - protected $matcher; + protected Matcher $matcher; /** * Routing array * @var array */ - protected $routes; + protected array $routes; /** * Routes added to router * @var array $outputRoutes */ - protected $outputRoutes; + protected array $outputRoutes; /** * Constructor @@ -254,7 +251,7 @@ final class Dispatcher extends RoutingBase { foreach ($classFiles as $file) { $rawClassName = basename(str_replace('.php', '', $file)); - $path = (string)$this->string($rawClassName)->dasherize(); + $path = (string)StringType::from($rawClassName)->dasherize(); $className = trim($defaultNamespace . '\\' . $rawClassName, '\\'); $controllers[$path] = $className; diff --git a/src/AnimeClient/MenuGenerator.php b/src/AnimeClient/MenuGenerator.php index 3696f230..1839e29c 100644 --- a/src/AnimeClient/MenuGenerator.php +++ b/src/AnimeClient/MenuGenerator.php @@ -16,11 +16,12 @@ namespace Aviat\AnimeClient; -use Aviat\Ion\{ArrayWrapper, StringWrapper}; use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException}; use Aura\Html\HelperLocator; use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Exception\ConfigException; +use Aviat\Ion\Type\ArrayType; +use Aviat\Ion\Type\StringType; use Psr\Http\Message\RequestInterface; /** @@ -28,9 +29,6 @@ use Psr\Http\Message\RequestInterface; */ final class MenuGenerator extends UrlGenerator { - use ArrayWrapper; - use StringWrapper; - /** * Html generation helper * @@ -74,8 +72,8 @@ final class MenuGenerator extends UrlGenerator { $parsed[$name] = []; foreach ($menu['items'] as $pathName => $partialPath) { - $title = (string)$this->string($pathName)->humanize()->titleize(); - $parsed[$name][$title] = (string)$this->string($menu['route_prefix'])->append($partialPath); + $title = (string)StringType::from($pathName)->humanize()->titleize(); + $parsed[$name][$title] = (string)StringType::from($menu['route_prefix'])->append($partialPath); } } @@ -95,7 +93,7 @@ final class MenuGenerator extends UrlGenerator { $parsedConfig = $this->parseConfig($menus); // Bail out early on invalid menu - if ( ! $this->arr($parsedConfig)->hasKey($menu)) + if ( ! ArrayType::from($parsedConfig)->hasKey($menu)) { return ''; } @@ -104,7 +102,7 @@ final class MenuGenerator extends UrlGenerator { foreach ($menuConfig as $title => $path) { - $has = $this->string($this->path())->contains($path); + $has = StringType::from($this->path())->contains($path); $selected = ($has && mb_strlen($this->path()) >= mb_strlen($path)); $link = $this->helper->a($this->url($path), $title); diff --git a/src/AnimeClient/Model/Settings.php b/src/AnimeClient/Model/Settings.php index a1beec2c..d9f76ce8 100644 --- a/src/AnimeClient/Model/Settings.php +++ b/src/AnimeClient/Model/Settings.php @@ -25,16 +25,14 @@ use Aviat\AnimeClient\Types\{Config, UndefinedPropertyException}; use Aviat\Ion\ConfigInterface; use Aviat\Ion\Di\ContainerAware; -use Aviat\Ion\StringWrapper; /** * Model for handling settings control panel */ final class Settings { use ContainerAware; - use StringWrapper; - private $config; + private ConfigInterface $config; public function __construct(ConfigInterface $config) { diff --git a/src/AnimeClient/RoutingBase.php b/src/AnimeClient/RoutingBase.php index ea55207e..e8a17290 100644 --- a/src/AnimeClient/RoutingBase.php +++ b/src/AnimeClient/RoutingBase.php @@ -21,7 +21,7 @@ use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Di\Exception\ContainerException; use Aviat\Ion\Di\Exception\NotFoundException; use Aviat\Ion\Exception\ConfigException; -use Aviat\Ion\StringWrapper; +use Aviat\Ion\Type\StringType; use Psr\Http\Message\ServerRequestInterface; /** @@ -29,13 +29,11 @@ use Psr\Http\Message\ServerRequestInterface; */ class RoutingBase { - use StringWrapper; - /** * Injection Container * @var ContainerInterface $container */ - protected $container; + protected ContainerInterface $container; /** * Config Object @@ -73,7 +71,7 @@ class RoutingBase { public function path(): string { $path = $this->request->getUri()->getPath(); - $cleanedPath = $this->string($path) + $cleanedPath = StringType::from($path) ->replace('%20', '') ->trim() ->trimRight('/') diff --git a/src/Ion/ArrayWrapper.php b/src/Ion/ArrayWrapper.php deleted file mode 100644 index 86288895..00000000 --- a/src/Ion/ArrayWrapper.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @copyright 2015 - 2020 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 5 - * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\Ion; - -use Aviat\Ion\Type\ArrayType; - -/** - * Wrapper to shortcut creating ArrayType objects - */ -trait ArrayWrapper { - - /** - * Convenience method for wrapping an array - * with the array type class - * - * @param array $arr - * @return ArrayType - */ - public function arr(array $arr): ArrayType - { - return new ArrayType($arr); - } -} -// End of ArrayWrapper.php \ No newline at end of file diff --git a/src/Ion/Config.php b/src/Ion/Config.php index 0efa4cf1..7e2f6b8e 100644 --- a/src/Ion/Config.php +++ b/src/Ion/Config.php @@ -25,14 +25,12 @@ use InvalidArgumentException; */ class Config implements ConfigInterface { - use ArrayWrapper; - /** * Config object * * @var ArrayType */ - protected $map; + protected ArrayType $map; /** * Constructor @@ -41,7 +39,7 @@ class Config implements ConfigInterface { */ public function __construct(array $configArray = []) { - $this->map = $this->arr($configArray); + $this->map = ArrayType::from($configArray); } /** diff --git a/src/Ion/Model.php b/src/Ion/Model.php index 7ae03591..ab586b88 100644 --- a/src/Ion/Model.php +++ b/src/Ion/Model.php @@ -20,6 +20,5 @@ namespace Aviat\Ion; * Common base for all Models */ class Model { - use StringWrapper; } // End of Model.php diff --git a/src/Ion/StringWrapper.php b/src/Ion/StringWrapper.php deleted file mode 100644 index 092c5666..00000000 --- a/src/Ion/StringWrapper.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @copyright 2015 - 2020 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 5 - * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\Ion; - -use Aviat\Ion\Type\StringType; - -/** - * Trait to add convenience method for creating StringType objects - */ -trait StringWrapper { - - /** - * Wrap the String in the Stringy class - * - * @param string $str - * @throws \InvalidArgumentException - * @return StringType - */ - public function string($str): StringType - { - return StringType::create($str); - } -} -// End of StringWrapper.php \ No newline at end of file diff --git a/src/Ion/Transformer/AbstractTransformer.php b/src/Ion/Transformer/AbstractTransformer.php index ea331b56..19076914 100644 --- a/src/Ion/Transformer/AbstractTransformer.php +++ b/src/Ion/Transformer/AbstractTransformer.php @@ -16,17 +16,12 @@ namespace Aviat\Ion\Transformer; -use Aviat\Ion\StringWrapper; - use BadMethodCallException; /** * Base class for data transformation */ abstract class AbstractTransformer implements TransformerInterface { - - use StringWrapper; - /** * Mutate the data structure * diff --git a/src/Ion/Type/ArrayType.php b/src/Ion/Type/ArrayType.php index bab03c61..21bc849c 100644 --- a/src/Ion/Type/ArrayType.php +++ b/src/Ion/Type/ArrayType.php @@ -32,14 +32,14 @@ class ArrayType { * * @var array */ - protected $arr; + protected array $arr; /** * Map generated methods to their native implementations * * @var array */ - protected $nativeMethods = [ + protected array $nativeMethods = [ 'chunk' => 'array_chunk', 'diff' => 'array_diff', 'filter' => 'array_filter', @@ -64,7 +64,7 @@ class ArrayType { * * @var array */ - protected $nativeInPlaceMethods = [ + protected array $nativeInPlaceMethods = [ 'shuffle' => 'shuffle', 'shift' => 'array_shift', 'unshift' => 'array_unshift', @@ -72,12 +72,23 @@ class ArrayType { 'pop' => 'array_pop', ]; + /** + * Create an ArrayType wrapper class from an array + * + * @param array $arr + * @return ArrayType + */ + public static function from(array $arr): ArrayType + { + return new ArrayType($arr); + } + /** * Create an ArrayType wrapper class * * @param array $arr */ - public function __construct(array &$arr) + private function __construct(array &$arr) { $this->arr =& $arr; } @@ -227,7 +238,7 @@ class ArrayType { /** * Return a reference to the value of an arbitrary key on the array * - * @example $arr = new ArrayType([0 => ['data' => ['foo' => 'bar']]]); + * @example $arr = ArrayType::from([0 => ['data' => ['foo' => 'bar']]]); * $val = $arr->getDeepKey([0, 'data', 'foo']); * // returns 'bar' * @param array $key An array of keys of the array diff --git a/src/Ion/Type/StringType.php b/src/Ion/Type/StringType.php index a7ade2d4..9e280cd3 100644 --- a/src/Ion/Type/StringType.php +++ b/src/Ion/Type/StringType.php @@ -23,6 +23,17 @@ use Stringy\Stringy; */ class StringType extends Stringy { + /** + * Alias for `create` static constructor + * + * @param string $str + * @return $this + */ + public static function from(string $str): self + { + return self::create($str); + } + /** * See if two strings match, despite being delimited differently, * such as camelCase, PascalCase, kebab-case, or snake_case. diff --git a/src/Ion/View.php b/src/Ion/View.php index f98c16ce..796f0663 100644 --- a/src/Ion/View.php +++ b/src/Ion/View.php @@ -29,14 +29,13 @@ abstract class View implements ViewInterface { use Di\ContainerAware; - use StringWrapper; /** * HTTP response Object * * @var ResponseInterface */ - public $response; + public ResponseInterface $response; /** * If the view has sent output via @@ -44,7 +43,7 @@ abstract class View * * @var boolean */ - protected $hasRendered = FALSE; + protected bool $hasRendered = FALSE; /** * Constructor diff --git a/tests/AnimeClient/API/APIRequestBuilderTest.php b/tests/AnimeClient/API/APIRequestBuilderTest.php index a73dff08..a271f236 100644 --- a/tests/AnimeClient/API/APIRequestBuilderTest.php +++ b/tests/AnimeClient/API/APIRequestBuilderTest.php @@ -30,9 +30,9 @@ class APIRequestBuilderTest extends TestCase { public function setUp(): void { $this->builder = new class extends APIRequestBuilder { - protected $baseUrl = 'https://httpbin.org/'; + protected string $baseUrl = 'https://httpbin.org/'; - protected $defaultHeaders = ['User-Agent' => "Tim's Anime Client Testsuite / 4.0"]; + protected array $defaultHeaders = ['User-Agent' => "Tim's Anime Client Testsuite / 4.0"]; }; $this->builder->setLogger(new NullLogger); diff --git a/tests/Ion/Di/ContainerAwareTest.php b/tests/Ion/Di/ContainerAwareTest.php index a8d752f4..ad51de10 100644 --- a/tests/Ion/Di/ContainerAwareTest.php +++ b/tests/Ion/Di/ContainerAwareTest.php @@ -31,7 +31,7 @@ class Aware { class ContainerAwareTest extends IonTestCase { - protected $aware; + protected Aware $aware; public function setUp(): void { diff --git a/tests/Ion/IonTestCase.php b/tests/Ion/IonTestCase.php index 6d30b374..e05fd553 100644 --- a/tests/Ion/IonTestCase.php +++ b/tests/Ion/IonTestCase.php @@ -18,6 +18,7 @@ namespace Aviat\Ion\Tests; use function Aviat\Ion\_dir; +use Aviat\Ion\Di\ContainerInterface; use PHPUnit\Framework\TestCase; use Laminas\Diactoros\ServerRequestFactory; @@ -31,7 +32,7 @@ class IonTestCase extends TestCase { public const TEST_DATA_DIR = __DIR__ . '/test_data'; public const TEST_VIEW_DIR = __DIR__ . '/test_views'; - protected $container; + protected ContainerInterface $container; protected static $staticContainer; protected static $session_handler; diff --git a/tests/Ion/StringWrapperTest.php b/tests/Ion/StringWrapperTest.php deleted file mode 100644 index fd9743ec..00000000 --- a/tests/Ion/StringWrapperTest.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @copyright 2015 - 2020 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 5 - * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\Ion\Tests; - -use Aviat\Ion\StringWrapper; -use Aviat\Ion\Type\StringType; -use PHPUnit\Framework\TestCase; - -class StringWrapperTest extends TestCase { - - protected $wrapper; - - public function setUp(): void { - $this->wrapper = new class { - use StringWrapper; - }; - } - - public function testString() - { - $str = $this->wrapper->string('foo'); - $this->assertInstanceOf(StringType::class, $str); - } - -} \ No newline at end of file diff --git a/tests/Ion/Type/ArrayTypeTest.php b/tests/Ion/Type/ArrayTypeTest.php index e91dd6cb..7c127e34 100644 --- a/tests/Ion/Type/ArrayTypeTest.php +++ b/tests/Ion/Type/ArrayTypeTest.php @@ -16,16 +16,10 @@ namespace Aviat\Ion\Tests\Type; -use Aviat\Ion\ArrayWrapper; +use Aviat\Ion\Type\ArrayType; use Aviat\Ion\Tests\IonTestCase; class ArrayTypeTest extends IonTestCase { - use ArrayWrapper; - - public function setUp(): void { - parent::setUp(); - } - public function dataCall() { $method_map = [ @@ -88,33 +82,37 @@ class ArrayTypeTest extends IonTestCase { * Test the array methods defined for the __Call method * * @dataProvider dataCall + * @param string $method + * @param array $array + * @param array $args + * @param $expected */ - public function testCall($method, $array, $args, $expected) + public function testCall(string $method, array $array, array $args, $expected): void { - $obj = $this->arr($array); + $obj = ArrayType::from($array); $actual = $obj->__call($method, $args); $this->assertEquals($expected, $actual); } - public function testSet() + public function testSet(): void { - $obj = $this->arr([]); + $obj = ArrayType::from([]); $arraytype = $obj->set('foo', 'bar'); - $this->assertInstanceOf('Aviat\Ion\Type\ArrayType', $arraytype); + $this->assertInstanceOf(ArrayType::class, $arraytype); $this->assertEquals('bar', $obj->get('foo')); } - public function testGet() + public function testGet(): void { $array = [1, 2, 3, 4, 5]; - $obj = $this->arr($array); + $obj = ArrayType::from($array); $this->assertEquals($array, $obj->get()); $this->assertEquals(1, $obj->get(0)); $this->assertEquals(5, $obj->get(4)); } - public function testGetDeepKey() + public function testGetDeepKey(): void { $arr = [ 'foo' => 'bar', @@ -122,14 +120,14 @@ class ArrayTypeTest extends IonTestCase { 'bar' => 'foobar' ] ]; - $obj = $this->arr($arr); + $obj = ArrayType::from($arr); $this->assertEquals('foobar', $obj->getDeepKey(['baz', 'bar'])); $this->assertNull($obj->getDeepKey(['foo', 'bar', 'baz'])); } - public function testMap() + public function testMap(): void { - $obj = $this->arr([1, 2, 3]); + $obj = ArrayType::from([1, 2, 3]); $actual = $obj->map(function($item) { return $item * 2; }); @@ -137,9 +135,9 @@ class ArrayTypeTest extends IonTestCase { $this->assertEquals([2, 4, 6], $actual); } - public function testBadCall() + public function testBadCall(): void { - $obj = $this->arr([]); + $obj = ArrayType::from([]); $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Method 'foo' does not exist"); @@ -147,20 +145,20 @@ class ArrayTypeTest extends IonTestCase { $obj->foo(); } - public function testShuffle() + public function testShuffle(): void { $original = [1, 2, 3, 4]; $test = [1, 2, 3, 4]; - $obj = $this->arr($test); + $obj = ArrayType::from($test); $actual = $obj->shuffle(); //$this->assertNotEquals($actual, $original); $this->assertTrue(is_array($actual)); } - public function testHasKey() + public function testHasKey(): void { - $obj = $this->arr([ + $obj = ArrayType::from([ 'a' => 'b', 'z' => 'y' ]); @@ -168,9 +166,9 @@ class ArrayTypeTest extends IonTestCase { $this->assertFalse($obj->hasKey('b')); } - public function testHasKeyArray() + public function testHasKeyArray(): void { - $obj = $this->arr([ + $obj = ArrayType::from([ 'foo' => [ 'bar' => [ 'baz' => [ @@ -191,23 +189,23 @@ class ArrayTypeTest extends IonTestCase { $this->assertFalse($obj->hasKey(['bar', 'baz'])); } - public function testHas() + public function testHas(): void { - $obj = $this->arr([1, 2, 6, 8, 11]); + $obj = ArrayType::from([1, 2, 6, 8, 11]); $this->assertTrue($obj->has(8)); $this->assertFalse($obj->has(8745)); } - public function testSearch() + public function testSearch(): void { - $obj = $this->arr([1, 2, 5, 7, 47]); + $obj = ArrayType::from([1, 2, 5, 7, 47]); $actual = $obj->search(47); $this->assertEquals(4, $actual); } - public function testFill() + public function testFill(): void { - $obj = $this->arr([]); + $obj = ArrayType::from([]); $expected = ['?', '?', '?']; $actual = $obj->fill(0, 3, '?'); $this->assertEquals($actual, $expected); diff --git a/tests/Ion/Type/StringTypeTest.php b/tests/Ion/Type/StringTypeTest.php index f12bc45e..44d4f2f9 100644 --- a/tests/Ion/Type/StringTypeTest.php +++ b/tests/Ion/Type/StringTypeTest.php @@ -16,14 +16,12 @@ namespace Aviat\Ion\Tests\Type; -use Aviat\Ion\StringWrapper; +use Aviat\Ion\Type\StringType; use Aviat\Ion\Tests\IonTestCase; class StringTypeTest extends IonTestCase { - use StringWrapper; - - public function dataFuzzyCaseMatch() + public function dataFuzzyCaseMatch(): array { return [ 'space separated' => [ @@ -56,10 +54,13 @@ class StringTypeTest extends IonTestCase { /** * @dataProvider dataFuzzyCaseMatch + * @param string $str1 + * @param string $str2 + * @param bool $expected */ - public function testFuzzyCaseMatch($str1, $str2, $expected) + public function testFuzzyCaseMatch(string $str1, string $str2, bool $expected): void { - $actual = $this->string($str1)->fuzzyCaseMatch($str2); + $actual = StringType::from($str1)->fuzzyCaseMatch($str2); $this->assertEquals($expected, $actual); }