diff --git a/index.php b/index.php index 2edf4b35..dc8cdcb4 100644 --- a/index.php +++ b/index.php @@ -5,8 +5,6 @@ use Whoops\Handler\PrettyPageHandler; use Whoops\Handler\JsonResponseHandler; -use Aviat\AnimeClient\Config; - // Work around the silly timezone error $timezone = ini_get('date.timezone'); if ($timezone === '' || $timezone === FALSE) @@ -49,7 +47,6 @@ spl_autoload_register(function($class) { } }); -// Dependency setup require _dir(ROOT_DIR, '/vendor/autoload.php'); require _dir(SRC_DIR, '/functions.php'); @@ -67,7 +64,8 @@ $jsonHandler = new JsonResponseHandler(); $jsonHandler->onlyForAjaxRequests(TRUE); $whoops->pushHandler($jsonHandler); -//$whoops->register(); +// Register as the error handler +$whoops->register(); // ----------------------------------------------------------------------------- // Dependency Injection setup diff --git a/src/Aviat/AnimeClient/Config.php b/src/Aviat/AnimeClient/Config.php index 10d35ee6..2b2f6177 100644 --- a/src/Aviat/AnimeClient/Config.php +++ b/src/Aviat/AnimeClient/Config.php @@ -20,7 +20,7 @@ class Config { /** * Constructor * - * @param array $config_files + * @param array $config_array */ public function __construct(array $config_array = []) { diff --git a/src/Aviat/AnimeClient/Controller/Anime.php b/src/Aviat/AnimeClient/Controller/Anime.php index 0fe9afe5..163c8788 100644 --- a/src/Aviat/AnimeClient/Controller/Anime.php +++ b/src/Aviat/AnimeClient/Controller/Anime.php @@ -7,7 +7,7 @@ namespace Aviat\AnimeClient\Controller; use Aviat\Ion\Di\ContainerInterface; use Aviat\AnimeClient\Controller as BaseController; -use Aviat\AnimeClient\Enum\Hummingbird\AnimeWatchingStatus; +use Aviat\AnimeClient\Hummingbird\Enum\AnimeWatchingStatus; use Aviat\AnimeClient\Model\Anime as AnimeModel; use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel; diff --git a/src/Aviat/AnimeClient/Controller/Collection.php b/src/Aviat/AnimeClient/Controller/Collection.php index a57cb33c..66829711 100644 --- a/src/Aviat/AnimeClient/Controller/Collection.php +++ b/src/Aviat/AnimeClient/Controller/Collection.php @@ -45,7 +45,7 @@ class Collection extends BaseController { parent::__construct($container); $this->urlGenerator = $container->get('url-generator'); - $this->anime_anime_collection_model = new AnimeCollectionModel($container); + $this->anime_collection_model = new AnimeCollectionModel($container); $this->base_data = array_merge($this->base_data, [ 'menu_name' => 'collection', 'message' => '', diff --git a/src/Aviat/AnimeClient/Enum/Hummingbird/AnimeAgeRating.php b/src/Aviat/AnimeClient/Enum/Hummingbird/AnimeAgeRating.php deleted file mode 100644 index 8124a8da..00000000 --- a/src/Aviat/AnimeClient/Enum/Hummingbird/AnimeAgeRating.php +++ /dev/null @@ -1,14 +0,0 @@ -zipper_lists($api_data); - $transformer = new Hummingbird\MangaListTransformer(); + $transformer = new Transformer\MangaListTransformer(); $transformed_data = $transformer->transform_collection($zippered_data); file_put_contents($transformed_cache_file, json_encode($transformed_data)); return $transformed_data; @@ -172,7 +172,7 @@ class Manga extends API { */ private function zipper_lists($raw_data) { - $zipper = new Hummingbird\MangaListsZipper($raw_data); + $zipper = new Transformer\MangaListsZipper($raw_data); return $zipper->transform(); } diff --git a/src/Aviat/Ion/Di/ContainerInterface.php b/src/Aviat/Ion/Di/ContainerInterface.php index 07e4cafc..b902c923 100644 --- a/src/Aviat/Ion/Di/ContainerInterface.php +++ b/src/Aviat/Ion/Di/ContainerInterface.php @@ -2,6 +2,9 @@ namespace Aviat\Ion\Di; +/** + * Interface for the Dependency Injection Container + */ interface ContainerInterface extends \Interop\Container\ContainerInterface { /** diff --git a/src/Aviat/Ion/Enum.php b/src/Aviat/Ion/Enum.php index 70473f22..194f04d8 100644 --- a/src/Aviat/Ion/Enum.php +++ b/src/Aviat/Ion/Enum.php @@ -4,6 +4,12 @@ namespace Aviat\Ion; use ReflectionClass; +/** + * Class emulating an enumeration type + * + * @method bool isValid(mixed $key) + * @method array getConstList() + */ abstract class Enum { use StaticInstance; diff --git a/src/Aviat/Ion/StringWrapper.php b/src/Aviat/Ion/StringWrapper.php index 4c25e9e9..babd6cde 100644 --- a/src/Aviat/Ion/StringWrapper.php +++ b/src/Aviat/Ion/StringWrapper.php @@ -4,6 +4,9 @@ namespace Aviat\Ion; use Aviat\Ion\Type\StringType; +/** + * Trait to add convenience method for creating StringType objects + */ trait StringWrapper { /** diff --git a/src/Aviat/Ion/Transformer/AbstractTransformer.php b/src/Aviat/Ion/Transformer/AbstractTransformer.php index d3972998..4d762b9a 100644 --- a/src/Aviat/Ion/Transformer/AbstractTransformer.php +++ b/src/Aviat/Ion/Transformer/AbstractTransformer.php @@ -2,6 +2,9 @@ namespace Aviat\Ion\Transformer; +/** + * Base class for data trasformation + */ abstract class AbstractTransformer implements TransformerInterface { use \Aviat\Ion\StringWrapper; diff --git a/src/Aviat/Ion/Transformer/TransformerInterface.php b/src/Aviat/Ion/Transformer/TransformerInterface.php index 4f028ce5..8414ac08 100644 --- a/src/Aviat/Ion/Transformer/TransformerInterface.php +++ b/src/Aviat/Ion/Transformer/TransformerInterface.php @@ -2,6 +2,9 @@ namespace Aviat\Ion\Transformer; +/** + * Interface for data transformation classes + */ interface TransformerInterface { /** diff --git a/src/Aviat/Ion/Type/ArrayType.php b/src/Aviat/Ion/Type/ArrayType.php index f918b6bd..5dbe1438 100644 --- a/src/Aviat/Ion/Type/ArrayType.php +++ b/src/Aviat/Ion/Type/ArrayType.php @@ -4,6 +4,10 @@ namespace Aviat\Ion\Type; /** * Wrapper class for native array methods for convenience + * + * @method array chunk(int $size, bool $preserve_keys = FALSE) + * @method array pluck(mixed $column_key, mixed $index_key = NULL) + * @method array filter(callable $callback = NULL, int $flag = 0) */ class ArrayType { @@ -22,7 +26,6 @@ class ArrayType { protected $native_methods = [ 'chunk' => 'array_chunk', 'pluck' => 'array_column', - 'assoc_diff' => 'array_diff_assoc', 'key_diff' => 'array_diff_key', 'diff' => 'array_diff', 'filter' => 'array_filter', @@ -31,16 +34,12 @@ class ArrayType { 'keys' => 'array_keys', 'merge' => 'array_merge', 'pad' => 'array_pad', - 'pop' => 'array_pop', 'product' => 'array_product', - 'push' => 'array_push', 'random' => 'array_rand', 'reduce' => 'array_reduce', 'reverse' => 'array_reverse', - 'shift' => 'array_shift', 'sum' => 'array_sum', 'unique' => 'array_unique', - 'unshift' => 'array_unshift', 'values' => 'array_values', ]; @@ -51,6 +50,10 @@ class ArrayType { */ protected $native_in_place_methods = [ 'shuffle' => 'shuffle', + 'shift' => 'array_shift', + 'unshift' => 'array_unshift', + 'push' => 'array_push', + 'pop' => 'array_pop', ]; /** @@ -69,6 +72,7 @@ class ArrayType { * @param string $method * @param array $args * @return mixed + * @throws \InvalidArgumentException */ public function __call($method, $args) { @@ -88,8 +92,10 @@ class ArrayType { $func($this->arr); return $this->arr; } + + throw new \InvalidArgumentException("Method '{$method}' does not exist"); } - + /** * Does the passed key exist in the current array? * diff --git a/src/Aviat/Ion/View.php b/src/Aviat/Ion/View.php index 2e598745..cc9f8ff3 100644 --- a/src/Aviat/Ion/View.php +++ b/src/Aviat/Ion/View.php @@ -4,6 +4,9 @@ namespace Aviat\Ion; use Aviat\Ion\Di\ContainerInterface; +/** + * Base view response class + */ abstract class View { use Di\ContainerAware; diff --git a/src/Aviat/Ion/View/HtmlView.php b/src/Aviat/Ion/View/HtmlView.php index a7d972fe..1a960c26 100644 --- a/src/Aviat/Ion/View/HtmlView.php +++ b/src/Aviat/Ion/View/HtmlView.php @@ -5,6 +5,9 @@ namespace Aviat\Ion\View; use Aviat\Ion\View\HttpView; use Aviat\Ion\Di\ContainerInterface; +/** + * View class for outputting HTML + */ class HtmlView extends HttpView { /** diff --git a/src/Aviat/Ion/View/HttpView.php b/src/Aviat/Ion/View/HttpView.php index 0fee05a8..680e6329 100644 --- a/src/Aviat/Ion/View/HttpView.php +++ b/src/Aviat/Ion/View/HttpView.php @@ -6,11 +6,14 @@ use Aura\Web\ResponseSender; use Aviat\Ion\View as BaseView; +/** + * Base view class for Http output + */ class HttpView extends BaseView { - + /** * Do a redirect - * + * * @param string $url * @param int $code * @return void @@ -19,7 +22,7 @@ class HttpView extends BaseView { { $this->response->redirect->to($url, $code); } - + /** * Send the appropriate response * @@ -32,5 +35,5 @@ class HttpView extends BaseView { $sender = new ResponseSender($this->response); $sender->__invoke(); } - + } \ No newline at end of file diff --git a/src/Aviat/Ion/View/JsonView.php b/src/Aviat/Ion/View/JsonView.php index 75ce87a9..332b4a9b 100644 --- a/src/Aviat/Ion/View/JsonView.php +++ b/src/Aviat/Ion/View/JsonView.php @@ -4,6 +4,9 @@ namespace Aviat\Ion\View; use Aviat\Ion\View\HttpView; +/** + * View class to serialize Json + */ class JsonView extends HttpView { /** diff --git a/tests/AnimeClient/Transformer/Hummingbird/AnimeListTransformerTest.php b/tests/AnimeClient/Hummingbird/Transformer/AnimeListTransformerTest.php similarity index 95% rename from tests/AnimeClient/Transformer/Hummingbird/AnimeListTransformerTest.php rename to tests/AnimeClient/Hummingbird/Transformer/AnimeListTransformerTest.php index a6206e63..0ef7783b 100644 --- a/tests/AnimeClient/Transformer/Hummingbird/AnimeListTransformerTest.php +++ b/tests/AnimeClient/Hummingbird/Transformer/AnimeListTransformerTest.php @@ -1,7 +1,7 @@ 'array_chunk', + 'pluck' => 'array_column', + 'assoc_diff' => 'array_diff_assoc', + 'key_diff' => 'array_diff_key', + 'diff' => 'array_diff', + 'filter' => 'array_filter', + 'flip' => 'array_flip', + 'intersect' => 'array_intersect', + 'keys' => 'array_keys', + 'merge' => 'array_merge', + 'pad' => 'array_pad', + 'product' => 'array_product', + 'random' => 'array_rand', + 'reduce' => 'array_reduce', + 'reverse' => 'array_reverse', + ]; + + return [ + 'array_sum' => [ + 'method' => 'sum', + 'array' => [1, 2, 3, 4, 5, 6], + 'args' => [], + 'expected' => 21 + ], + 'array_unique' => [ + 'method' => 'unique', + 'array' => [1, 1, 3, 2, 2, 2, 3, 3, 5], + 'args' => [SORT_REGULAR], + 'expected' => [0=>1, 2=>3, 3=>2, 8=>5] + ], + 'array_values' => [ + 'method' => 'values', + 'array' => ['foo' => 'bar', 'baz' => 'foobar'], + 'args' => [], + 'expected' => ['bar', 'foobar'] + ] + ]; + } + + /** + * Test the array methods defined for the __Call method + * + * @dataProvider dataCall + */ + public function testCall($method, $array, $args, $expected) + { + $obj = $this->arr($array); + $actual = $obj->__call($method, $args); + $this->assertEquals($expected, $actual); + } + + public function testBadCall() + { + $obj = $this->arr([]); + + $this->setExpectedException('InvalidArgumentException', "Method 'foo' does not exist"); + $obj->foo(); + } + public function testMerge() { $obj = $this->arr([1, 3, 5, 7]); @@ -30,6 +92,16 @@ class ArrayTypeTest extends AnimeClient_TestCase { $this->assertTrue(is_array($actual)); } + public function testHasKey() + { + $obj = $this->arr([ + 'a' => 'b', + 'z' => 'y' + ]); + $this->assertTrue($obj->has_key('a')); + $this->assertFalse($obj->has_key('b')); + } + public function testHas() { $obj = $this->arr([1, 2, 6, 8, 11]);