diff --git a/.gitignore b/.gitignore
index e244eda0..5ede35ba 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
/vendor/
-/.idea/
\ No newline at end of file
+/.idea/
+/composer.lock
+/test.php
+/jikan-fixtures
diff --git a/.travis.yml b/.travis.yml
old mode 100755
new mode 100644
index 1ebde19a..4b4eb63e
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,30 @@
language: php
+
php:
- - '7.0'
- - '7.1'
- - '7.2'
+ - 7.1
+ - 7.2
+ - nightly
+
+env:
+ matrix:
+ -
+# - DEPENDENCIES=--prefer-lowest
+
+cache:
+ directories:
+ - .composer/cache
+
+matrix:
+ fast_finish: true
+ allow_failures:
+ - php: nightly
+
+before_install:
+ - alias composer=composer\ --no-interaction && composer selfupdate
+ - composer global require hirak/prestissimo
+
+install:
+ - travis_retry composer update --no-progress --profile --no-scripts --no-suggest $DEPENDENCIES
-before_script:
- - composer install
-script: php travis.php
\ No newline at end of file
+script:
+ - vendor/bin/grumphp run
\ No newline at end of file
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 00000000..23dd9305
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,51 @@
+build: false
+shallow_clone: false
+platform:
+ - x86
+ - x64
+clone_folder: c:\projects\jikan
+
+environment:
+ matrix:
+ - PHP_VERSION: 7.1
+ - PHP_VERSION: 7.2
+
+cache:
+ - '%APPDATA%\Composer'
+ - c:\tools\php -> appveyor.yml
+init:
+ - SET PATH=C:\Program Files\OpenSSL;c:\tools\php;%PATH%
+ - SET COMPOSER_NO_INTERACTION=1
+ - SET PHP=1
+ - SET ANSICON=121x90 (121x90)
+
+install:
+ - IF EXIST c:\tools\php (SET PHP=0)
+ - ps: Set-Service wuauserv -StartupType Manual
+
+ # Install PHP here
+ - ps: appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:PHP_VERSION | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
+ # - IF %PHP%==1 cinst -y OpenSSL.Light
+ # - IF %PHP%==1 cinst -y php -version %PHP_VERSION%
+ # - cd C:\tools\php71
+ - cd c:\tools\php
+ - IF %PHP%==1 copy php.ini-production php.ini
+ - IF %PHP%==1 echo date.timezone="UTC" >> php.ini
+ - IF %PHP%==1 echo memory_limit=1024M >> php.ini
+ - IF %PHP%==1 echo extension_dir=ext >> php.ini
+ - IF %PHP%==1 echo extension=php_curl.dll >> php.ini
+ - IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini
+ - IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
+ - IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
+
+ # Download
+ - cd C:\tools
+ - appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar
+
+before_test:
+ - cd C:\projects\jikan
+ - php C:\tools\composer.phar update --no-progress --profile --prefer-dist --no-scripts --no-interaction --no-suggest
+
+test_script:
+ - cd c:\projects\jikan
+ - vendor\bin\phpunit --colors=always
diff --git a/composer.json b/composer.json
index 51751385..92d5b019 100755
--- a/composer.json
+++ b/composer.json
@@ -9,8 +9,7 @@
"email": "irfan@jikan.moe"
}
],
- "minimum-stability": "dev",
- "require": {},
+ "minimum-stability": "stable",
"autoload": {
"psr-4": {
"Jikan\\": [
@@ -18,6 +17,25 @@
]
}
},
+ "autoload-dev": {
+ "psr-4": {
+ "Jikan\\": [
+ "test/JikanTest"
+ ]
+ }
+ },
+ "require": {
+ "fabpot/goutte": "^3.2",
+ "php": "^7.1"
+ },
"require-dev": {
+ "phpunit/phpunit": "^6.3",
+ "php-vcr/php-vcr": "~1.3.2",
+ "php-vcr/phpunit-testlistener-vcr": "^3.0",
+ "squizlabs/php_codesniffer": "^3.3",
+ "phpro/grumphp": "^0.14.1",
+ "jakub-onderka/php-parallel-lint": "^1.0",
+ "doctrine/collections": "^1.5",
+ "jikan-me/jikan-fixtures": "dev-master"
}
}
diff --git a/examples/anime.php b/examples/anime.php
deleted file mode 100755
index b71001af..00000000
--- a/examples/anime.php
+++ /dev/null
@@ -1,12 +0,0 @@
-Anime(21);
-//$jikan->Anime(1, [EPISODES, CHARACTERS_STAFF]); // get episodes + characters+staff
-//$jikan->Anime(21, [EPISODES=>2]); // get all the episodes from page 2 of the episode list
-
-var_dump($jikan->response);
-?>
\ No newline at end of file
diff --git a/examples/character.php b/examples/character.php
deleted file mode 100755
index 983a79a2..00000000
--- a/examples/character.php
+++ /dev/null
@@ -1,9 +0,0 @@
-Character(1);
-
-var_dump($jikan->response);
-?>
\ No newline at end of file
diff --git a/examples/manga.php b/examples/manga.php
deleted file mode 100755
index 14a9aa45..00000000
--- a/examples/manga.php
+++ /dev/null
@@ -1,11 +0,0 @@
-Manga(1);
-//$jikan->Manga(1, [CHARACTERS]); // get the characters too
-
-var_dump($jikan->response);
-?>
\ No newline at end of file
diff --git a/examples/person.php b/examples/person.php
deleted file mode 100755
index 7800c559..00000000
--- a/examples/person.php
+++ /dev/null
@@ -1,9 +0,0 @@
-Person(1);
-
-var_dump($jikan->response);
-?>
\ No newline at end of file
diff --git a/examples/schedule.php b/examples/schedule.php
deleted file mode 100755
index 55a24e45..00000000
--- a/examples/schedule.php
+++ /dev/null
@@ -1,15 +0,0 @@
-Schedule();
-
-$jikan->response['monday']; // anime airing on monday
-$jikan->response['tuesday']; // anime airing on tuesday
-//$jikan->response[$day];
-$jikan->response['sunday']; // all the way upto sunday
-
-var_dump($jikan->response);
-?>
\ No newline at end of file
diff --git a/examples/search.php b/examples/search.php
deleted file mode 100755
index ffbe76a9..00000000
--- a/examples/search.php
+++ /dev/null
@@ -1,110 +0,0 @@
-Search(query, type[, page, config])
- *
- * `query` : string (must be atleast 3 characters)
- * `type` : CONSTANT [ANIME, MANGA, PEOPLE, PERSON (alias), CHARACTER]
- * `page` : integer // search result page
- * `config` : Helper\SearchConfig OBJECT
- */
-
-// Basic Search
-$jikan->Search('Code Geass', ANIME);
-var_dump($jikan->response['result']); // Search results for 'Code Geass' that are Anime
-$pages = $jikan->response['result_last_page']; // Number of pages of search results. You can use this for pagination
-
-/*
- * NOTE: Response is stored in `$jikan->response`
- * Search results are in `$jikan->response['result']` (array)
- * No# of pages `$jikan->response['result_last_page']` (integer)
- */
-
-var_dump(
- $jikan->Search('Sword Art Online', MANGA)->response['result']; // All manga search results for 'Sword Art Online'
-);
-
-$jikan->Search('Makise', CHARACTER, 2); // 2nd page of the search results for 'Makise'
-$jikan->Search('Sawano', PEOPLE); // you get it by now
-
-
-/*
- * Advanced Search
- */
-
-// Call the SearchConfig Helper to build the config for the query.
-// Only Argument is the SearchConfig Type. Only Legal values are ANIME and MANGA
-// There are no advanced search options for CHARACTER or PEOPLE
-// ALL CONSTANTS ARE DEFINED IN `src/config.php`
-$config = new Jikan\Helper\SearchConfig(ANIME);
-
-// NOTE: If it isn't obvious, All these flags are optional.
-// NOTE2: These methods can be chained
-
-/* Types
- * CONSTANTS ARE DEFINED IN `src/config.php`
- */
-$config->setType(TYPE_MOVIE);
-
-/* Score (integer) 1-10
- * Minimum Score in results
- */
-$config->setScore(5);
-
-/* Status
- * e.g finished, airing, publishing, etc
- * CONSTANTS ARE DEFINED IN `src/config.php`
- */
-$config->setStatus(FINISHED_AIRING);
-
-/* Rated
- * PG, PG13, R17, etc
- * CONSTANTS ARE DEFINED IN `src/config.php`
- */
-$config->setRated(PG13);
-
-/* Start Date
- * setStartDate(day (int), month (int), year (int))
- */
-$config->setStartDate(5, 10, 2004);
-
-/* End Date
- * setEndDate(day (int), month (int), year (int))
- */
-$config->setStartDate(27, 3, 2012);
-
-/* Genre
- * CONSTANTS ARE DEFINED IN `src/config.php`
- */
-
-// You can set one by one
-$config->setGenre(ACTION);
-$config->setGenre(COMEDY);
-
-// or in bulk
-$config->setGenre([ACTION, COMEDY, SUPER_POWER, SUPERNATURAL, SHOUNEN]);
-// Don't worry about duplicates, they're removed automatically
-
-/* Genre Include Or Exclude
- * The genre that are defined above this
- * You have the option of having the results either
- * - Include anime/manga with them
- * - Exclude anime/manga with them
- *
- * NOTE: THIS IS `TRUE` BY DEFAULT
- */
-
-$config->setGenreInclude(true); // This will Include the results with these genre (default)
-
-$config->setGenreInclude(false); // Exclude
-
-// Pass the object as an argument
-$jikan->Search('Bleach', ANIME, 1, $config);
-
-var_dump($jikan->response);
-?>
\ No newline at end of file
diff --git a/examples/seasonal.php b/examples/seasonal.php
deleted file mode 100755
index d78254d4..00000000
--- a/examples/seasonal.php
+++ /dev/null
@@ -1,13 +0,0 @@
-Seasonal(season (constant), year (string));
-// season : WINTER, SPRING, SUMMER, FALL
-// CONSTANTS ARE DEFINED IN `src/config.php`
-$jikan->Seasonal(WINTER, 2017);
-
-var_dump($jikan->response);
-?>
\ No newline at end of file
diff --git a/examples/test.php b/examples/test.php
deleted file mode 100755
index 4b2b1523..00000000
--- a/examples/test.php
+++ /dev/null
@@ -1,43 +0,0 @@
-setGenre(1, 2);
-
-$jikan->Search(NULL, ANIME, 1, $config);
-
-$time_end = microtime(true);
-$execution_time = ($time_end - $time_start);
-
-//execution time of the script
-echo 'Total Execution Time: '.$execution_time.' s
';
-
-//var_dump();
-foreach ($jikan->response['result'] as $key => $value) {
- var_dump($value);
-}
-
-//$jikan->Anime(21);
-//sleep(5);
-//$jikan->Anime(21, [EPISODES]);
-//sleep(5);
-//$jikan->Anime(21, [EPISODES, CHARACTERS_STAFF]);
-//sleep(5);
-//$jikan->Manga(1);
-//sleep(5);
-//$jikan->Manga(1, [CHARACTERS]);
-//sleep(5);
-//$jikan->Person(1);
-//sleep(5);
-//$jikan->Character(1);
-//
\ No newline at end of file
diff --git a/grumphp.yml b/grumphp.yml
new file mode 100644
index 00000000..4f1bb9ff
--- /dev/null
+++ b/grumphp.yml
@@ -0,0 +1,20 @@
+parameters:
+ git_dir: .
+ bin_dir: ./vendor/bin
+ process_timeout: 180
+ tasks:
+ phpcs:
+ standard: 'PSR2'
+ ignore_patterns:
+ - 'test/*.php'
+ - 'src/Jikan.php'
+ git_blacklist:
+ keywords:
+ - 'var_dump'
+ - 'exit'
+ - 'else'
+ - 'ini_set'
+ - 'error_reporting'
+ - 'die'
+ phpunit: ~
+ phplint: ~
\ No newline at end of file
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 00000000..b344bddb
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,18 @@
+
', '
'], '\n', $string)
+ ),
+ ENT_QUOTES
+ )
+ );
+ }
+
+ /**
+ * @param string $string
+ *
+ * @return string
+ */
+ public static function UTF8NbspTrim(string $string): string
+ {
+ return trim($string, \chr(0xC2).\chr(0xA0));
+ }
+}
diff --git a/src/Helper/MalUrlExtractor.php b/src/Helper/MalUrlExtractor.php
new file mode 100644
index 00000000..e0fa74e1
--- /dev/null
+++ b/src/Helper/MalUrlExtractor.php
@@ -0,0 +1,75 @@
+crawler = clone $crawler;
+ $this->type = $type;
+ $this->imageLinks = $imageLinks;
+ }
+
+ /**
+ * Extract all mal urls that begin with BASE_URL/$type
+ *
+ * @return \Jikan\Model\Common\MalUrl[]
+ * @throws \InvalidArgumentException
+ */
+ public function getMalUrls(): array
+ {
+ if (!$this->imageLinks) {
+ $this->crawler->filterXPath('//a/img')->each(
+ function (Crawler $c) {
+ $node = $c->parents()->first()->getNode(0);
+ /** @noinspection NullPointerExceptionInspection */
+ $node->parentNode->removeChild($node);
+ }
+ );
+ }
+
+ $xpath = sprintf('//a[contains(@href, "%s/%s")]', Constants::BASE_URL, $this->type);
+
+ return $this->crawler
+ ->filterXPath($xpath)
+ ->each(
+ function (Crawler $c) {
+ return (new MalUrlParser($c))->getModel();
+ }
+ );
+ }
+}
diff --git a/src/Helper/Parser.php b/src/Helper/Parser.php
new file mode 100644
index 00000000..0d2ac4e0
--- /dev/null
+++ b/src/Helper/Parser.php
@@ -0,0 +1,138 @@
+count()) {
+ return $crawler;
+ }
+ $crawler->children()->each(
+ function (Crawler $crawler) {
+ $node = $crawler->getNode(0);
+ if ($node === null || $node->nodeType === 3 || \in_array($node->nodeName, self::ALLOWED_NODES, true)) {
+ return;
+ }
+ $node->parentNode->removeChild($node);
+ }
+ );
+
+ return $crawler;
+ }
+
+ /**
+ * Extract the id from a mal url
+ *
+ * @param string $url
+ *
+ * @return int
+ */
+ public static function idFromUrl(string $url): int
+ {
+ return (int)preg_replace('#https://myanimelist.net(/\w+/)(\d+).*#', '$2', $url);
+ }
+
+ /**
+ * @param string $date
+ *
+ * @return \DateTimeImmutable|null
+ */
+ public static function parseForumDate(string $date): ?\DateTimeImmutable
+ {
+ if (!preg_match('/\d{4}/', $date)) {
+ $date .= ', '.date('Y');
+ }
+
+ return self::parseDate($date);
+ }
+
+ /**
+ * @param string $date
+ *
+ * @return \DateTimeImmutable|null
+ */
+ public static function parseDate(string $date): ?\DateTimeImmutable
+ {
+ if (preg_match('/^\d{4}$/', $date)) {
+ return \DateTimeImmutable::createFromFormat('Y-m-d', $date.'-01-01', new \DateTimeZone('UTC'));
+ }
+ try {
+ return new \DateTimeImmutable($date, new \DateTimeZone('UTC'));
+ } catch (\Exception $e) {
+ return null;
+ }
+ }
+
+ /**
+ * @param string $date
+ *
+ * @return \DateTimeImmutable|null
+ */
+ public static function parseDateMDY(string $date): ?\DateTimeImmutable
+ {
+ if ($date === '-') {
+ return null;
+ }
+
+ $dateArray = explode('-', $date);
+
+ if ($dateArray[0] === '??' && $dateArray[1] === '??' && $dateArray[2] === date('y')) {
+ return null;
+ }
+
+ $date = str_replace('??', '01', $date);
+
+ return \DateTimeImmutable::createFromFormat('!m-d-y', $date, new \DateTimeZone('UTC')) ?: null;
+ }
+
+ /**
+ * @param string $date
+ *
+ * @return \DateTimeImmutable|null
+ * @throws \Exception
+ */
+ public static function parseDateMDYReadable(string $date): ?\DateTimeImmutable
+ {
+ $date = str_replace(' ', ' ', $date);
+
+ if (preg_match('~[a-zA-z]+ \d+, \d{4}~', $date)) {
+ return new \DateTimeImmutable($date, new \DateTimeZone('UTC'));
+ }
+
+ return null;
+ }
+
+ /**
+ * @param Crawler $crawler
+ *
+ * @return null|string
+ * @throws \InvalidArgumentException
+ */
+ public static function textOrNull(Crawler $crawler): ?string
+ {
+ if (!$crawler->count()) {
+ return null;
+ }
+
+ return $crawler->text();
+ }
+}
diff --git a/src/Helper/SearchConfig.php b/src/Helper/SearchConfig.php
deleted file mode 100755
index 208bacf3..00000000
--- a/src/Helper/SearchConfig.php
+++ /dev/null
@@ -1,123 +0,0 @@
-type = $type;
-
- return $this;
- }
-
- public function build() {
- $query = "";
- // Type
- $query .= "type=".$this->subType;
- // Score
- $query .= "&score=".$this->score;
- // Status
- $query .= "&status=".$this->status;
- // Rated
- $query .= "&r=".$this->rated;
- // Start Date ISO8601
- $query .= "&sd=".$this->startDate[0];
- $query .= "&sm=".$this->startDate[1];
- $query .= "&sy=".$this->startDate[2];
- // End Date ISO8601
- $query .= "&ed=".$this->endDate[0];
- $query .= "&em=".$this->endDate[1];
- $query .= "&ey=".$this->endDate[2];
- // Genre Include
- $query .= "&gx=".($this->genreInclude ? "0" : "1");
- // Genre
- if (!empty($this->genre)) {
- foreach ($this->genre as $key => $genre) {
- $query .= "&genre[]=".$genre;
- }
- }
-
- return $query;
- }
-
- public function setType($subType) {
- $this->subType = in_array($subType, self::VALID_SUB_TYPES) ? $subType : 0;
-
- return $this;
- }
-
- public function setScore($score) {
- $this->score = $score;
-
- return $this;
- }
-
- public function setStatus($status) {
- $this->status = in_array($status, self::VALID_STATUS) ? $status : 0;
-
- return $this;
- }
-
- public function setRated($rated) {
- $this->rated = in_array($rated, self::VALID_RATING) ? $rated : 0;
-
- return $this;
- }
-
- public function setStartDate($day, $month, $year) {
- $this->startDate = [
- ltrim((string)$year, '0'),
- ltrim((string)$month, '0'),
- ltrim((string)$day, '0')
- ];
-
- return $this;
- }
-
- public function setEndDate($day, $month, $year) {
- $this->endDate = [
- ltrim((string)$year, '0'),
- ltrim((string)$month, '0'),
- ltrim((string)$day, '0')
- ];
-
- return $this;
- }
-
- public function setGenreInclude(Bool $bool) {
- $this->genreInclude = $bool;
-
- return $this;
- }
-
- public function setGenre(...$genre) {
- if (is_array($genre)) {
- $this->genre = !empty($genre) ? array_unique(array_merge($this->genre, $genre)) : [];
- } else {
- $this->genre[] = $genre;
- $this->genre = array_unique($this->genre);
- }
-
- return $this;
- }
-
-}
\ No newline at end of file
diff --git a/src/Helper/Utils.php b/src/Helper/Utils.php
deleted file mode 100755
index 491d52ab..00000000
--- a/src/Helper/Utils.php
+++ /dev/null
@@ -1,24 +0,0 @@
-filePath, FILTER_VALIDATE_URL) ? true : false);
- return preg_match('`^http(s)?://`', $url) ? true : false;
- }
-
- static public function existsURL($status) {
- return ($status == 200 || $status == 303) ? true : false;
- }
-
- static public function getStatus($url) {
- return substr(get_headers($url)[0], 9, 3);
- }
-
- static public function trim(&$item, $key) { $item = trim($item); }
-
-}
diff --git a/src/Jikan.php b/src/Jikan.php
index a76296fc..d2051c6a 100755
--- a/src/Jikan.php
+++ b/src/Jikan.php
@@ -1,128 +1,581 @@
myanimelist = new MalClient($guzzle);
+ }
+
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Anime\Anime
+ * @throws ParserException
+ */
+ public function Anime(int $id): Model\Anime\Anime
+ {
+ return $this->myanimelist->getAnime(
+ new Request\Anime\AnimeRequest($id)
+ );
+ }
+
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Anime\AnimeCharactersAndStaff
+ * @throws ParserException
+ */
+ public function AnimeCharactersAndStaff(int $id): Model\Anime\AnimeCharactersAndStaff
+ {
+ return $this->myanimelist->getAnimeCharactersAndStaff(
+ new Request\Anime\AnimeCharactersAndStaffRequest($id)
+ );
+ }
+
+ /**
+ * @param int $id
+ * @param int $page
+ *
+ * @return \Jikan\Model\Anime\Episodes
+ * @throws ParserException
+ */
+ public function AnimeEpisodes(int $id, int $page = 1): Model\Anime\Episodes
+ {
+ return $this->myanimelist->getAnimeEpisodes(
+ new Request\Anime\AnimeEpisodesRequest($id, $page)
+ );
+ }
+
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Anime\AnimeVideos
+ * @throws ParserException
+ */
+ public function AnimeVideos(int $id): Model\Anime\AnimeVideos
+ {
+ return $this->myanimelist->getAnimeVideos(
+ new Request\Anime\AnimeVideosRequest($id)
+ );
+ }
+
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Common\Picture[]
+ * @throws ParserException
+ */
+ public function AnimePictures(int $id): array
+ {
+ return $this->myanimelist->getAnimePictures(
+ new Request\Anime\AnimePicturesRequest($id)
+ );
+ }
- public function __construct() {
- return $this;
- }
- private function setStatus() {
- $this->status = $this->response['code'];
- unset($this->response['code']);
+ /**
+ * @param int $id
+ *
+ * @return Model\News\NewsListItem[]
+ * @throws ParserException
+ */
+ public function AnimeNews(int $id): array
+ {
+ return $this->myanimelist->getNewsList(
+ new Request\Anime\AnimeNewsRequest($id)
+ );
}
- /*
- * Anime
- */
- public function Anime($id = null, Array $extend = []) {
- $this->response = (array) (new Get\Anime($id, $extend))->response;
- $this->setStatus();
+ /**
+ * @param int $id
+ *
+ * @return Model\Forum\ForumTopic[]
+ * @throws ParserException
+ */
+ public function AnimeForum(int $id): array
+ {
+ return $this->myanimelist->getAnimeForum(
+ new Request\Anime\AnimeForumRequest($id)
+ );
+ }
- return $this;
+ /**
+ * @param int $id
+ *
+ * @return Model\Anime\AnimeStats
+ * @throws ParserException
+ */
+ public function AnimeStats(int $id): Model\Anime\AnimeStats
+ {
+ return $this->myanimelist->getAnimeStats(
+ new Request\Anime\AnimeStatsRequest($id)
+ );
}
- /*
- * Manga
+ /**
+ * @param int $id
+ *
+ * @return string|null
+ * @throws ParserException
*/
- public function Manga($id = null, Array $extend = []) {
- $this->response = (array) (new Get\Manga($id, $extend))->response;
- $this->setStatus();
+ public function AnimeMoreInfo(int $id): ?string
+ {
+ return $this->myanimelist->getAnimeMoreInfo(
+ new Request\Anime\AnimeMoreInfoRequest($id)
+ );
+ }
- return $this;
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Manga\Manga
+ * @throws ParserException
+ */
+ public function Manga(int $id): Model\Manga\Manga
+ {
+ return $this->myanimelist->getManga(
+ new Request\Manga\MangaRequest($id)
+ );
}
- /*
- * Character
+ /**
+ * @param int $id
+ *
+ * @return Model\Manga\CharacterListItem[]
+ * @throws ParserException
*/
- public function Character($id = null, Array $extend = []) {
- $this->response = (array) (new Get\Character($id, $extend))->response;
- $this->setStatus();
+ public function MangaCharacters(int $id): array
+ {
+ return $this->myanimelist->getMangaCharacters(
+ new Request\Manga\MangaCharactersRequest($id)
+ );
+ }
- return $this;
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Common\Picture[]
+ * @throws ParserException
+ */
+ public function MangaPictures(int $id): array
+ {
+ return $this->myanimelist->getMangaPictures(
+ new Request\Manga\MangaPicturesRequest($id)
+ );
}
- /*
- * Person
+ /**
+ * @param int $id
+ *
+ * @return Model\News\NewsListItem[]
+ * @throws ParserException
*/
- public function Person($id = null, Array $extend = []) {
- $this->response = (array) (new Get\Person($id, $extend))->response;
- $this->setStatus();
+ public function MangaNews(int $id): array
+ {
+ return $this->myanimelist->getNewsList(
+ new Request\Manga\MangaNewsRequest($id)
+ );
+ }
- return $this;
+ /**
+ * @param int $id
+ *
+ * @return Model\Forum\ForumTopic[]
+ * @throws ParserException
+ */
+ public function MangaForum(int $id): array
+ {
+ return $this->myanimelist->getMangaForum(
+ new Request\Manga\MangaForumRequest($id)
+ );
}
- /*
- * Search
+ /**
+ * @param int $id
+ *
+ * @return Model\Manga\MangaStats
+ * @throws ParserException
*/
- public function Search(string $query = null, string $type = ANIME, int $page = 1, SearchConfig $config = null) {
- $this->response = (array) (new Get\Search($query, $type, $page, $config))->response;
- $this->setStatus();
+ public function MangaStats(int $id): Model\Manga\MangaStats
+ {
+ return $this->myanimelist->getMangaStats(
+ new Request\Manga\MangaStatsRequest($id)
+ );
+ }
- return $this;
+ /**
+ * @param int $id
+ *
+ * @return string|null
+ * @throws ParserException
+ */
+ public function MangaMoreInfo(int $id): ?string
+ {
+ return $this->myanimelist->getMangaMoreInfo(
+ new Request\Manga\MangaMoreInfoRequest($id)
+ );
}
- /*
- * Seasonal Anime
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Character\Character
+ * @throws ParserException
*/
- public function Seasonal(string $season = null, int $year = null) {
- $this->response = (array) (new Get\Seasonal($season, $year))->response;
- $this->setStatus();
+ public function Character(int $id): Model\Character\Character
+ {
+ return $this->myanimelist->getCharacter(
+ new Request\Character\CharacterRequest($id)
+ );
+ }
- return $this;
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Common\Picture[]
+ * @throws ParserException
+ */
+ public function CharacterPictures(int $id): array
+ {
+ return $this->myanimelist->getCharacterPictures(
+ new Request\Character\CharacterPicturesRequest($id)
+ );
}
- /*
- * Anime Schedule For Current Season
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Person\Person
+ * @throws ParserException
*/
- public function Schedule() {
- $this->response = (array) (new Get\Schedule())->response;
- $this->setStatus();
+ public function Person(int $id): Model\Person\Person
+ {
+ return $this->myanimelist->getPerson(
+ new Request\Person\PersonRequest($id)
+ );
+ }
- return $this;
+ /**
+ * @param int $id
+ *
+ * @return \Jikan\Model\Common\Picture[]
+ * @throws ParserException
+ */
+ public function PersonPictures(int $id): array
+ {
+ return $this->myanimelist->getPersonPictures(
+ new Request\Person\PersonPicturesRequest($id)
+ );
}
- /*
- * Top Anime/Manga
+ /**
+ * @param int $year
+ * @param string $season
+ *
+ * @return \Jikan\Model\Seasonal\Seasonal
+ * @throws ParserException
*/
- public function Top(string $type, int $page, string $subtype = null) {
- $this->response = (array) (new Get\Top($type, $page, $subtype))->response;
- $this->setStatus();
+ public function Seasonal(int $year, string $season): Model\Seasonal\Seasonal
+ {
+ return $this->myanimelist->getSeasonal(
+ new Request\Seasonal\SeasonalRequest($year, $season)
+ );
+ }
- return $this;
+ /**
+ *
+ * @return array
+ * @throws ParserException
+ */
+ public function SeasonList(): array
+ {
+ return $this->myanimelist->getSeasonList(
+ new Request\SeasonList\SeasonListRequest()
+ );
}
- /*
- * User List
- *
+ /**
+ *
+ * @return \Jikan\Model\Shedule\Schedule
+ * @throws ParserException
*/
-/* public function UserList(string $username, string $type, int $status = null) {
- $this->response = (array) (new Get\User($username, $type, $status))->response;
- $this->setStatus();
+ public function Schedule(): Model\Shedule\Schedule
+ {
+ return $this->myanimelist->getSchedule(
+ new Request\Schedule\ScheduleRequest()
+ );
+ }
- return $this;
- }*/
+ /**
+ * @param int $id
+ * @param int $page
+ *
+ * @return \Jikan\Model\Producer\Producer
+ * @throws ParserException
+ */
+ public function Producer(int $id, int $page): Model\Producer\Producer
+ {
+ return $this->myanimelist->getProducer(
+ new Request\Producer\ProducerRequest($id, $page)
+ );
+ }
-}
\ No newline at end of file
+ /**
+ * @param int $id
+ * @param int $page
+ *
+ * @return \Jikan\Model\Magazine\Magazine
+ * @throws ParserException
+ */
+ public function Magazine(int $id, int $page): Model\Magazine\Magazine
+ {
+ return $this->myanimelist->getMagazine(
+ new Request\Magazine\MagazineRequest($id, $page)
+ );
+ }
+
+ /**
+ * @param int $id
+ * @param int $page
+ *
+ * @return \Jikan\Model\Genre\AnimeGenre
+ * @throws ParserException
+ */
+ public function AnimeGenre(int $id, int $page): Model\Genre\AnimeGenre
+ {
+ return $this->myanimelist->getAnimeGenre(
+ new Request\Genre\AnimeGenreRequest($id, $page)
+ );
+ }
+
+ /**
+ * @param int $id
+ * @param int $page
+ *
+ * @return \Jikan\Model\Genre\MangaGenre
+ * @throws ParserException
+ */
+ public function MangaGenre(int $id, int $page): Model\Genre\MangaGenre
+ {
+ return $this->myanimelist->getMangaGenre(
+ new Request\Genre\MangaGenreRequest($id, $page)
+ );
+ }
+
+ /**
+ * @param int $page
+ * @param string|null $type
+ *
+ * @return Model\Top\TopAnime[]
+ * @throws ParserException
+ */
+ public function TopAnime(int $page, ?string $type = null): array
+ {
+ return $this->myanimelist->getTopAnime(
+ new Request\Top\TopAnimeRequest($page, $type)
+ );
+ }
+
+ /**
+ * @param int $page
+ * @param string|null $type
+ *
+ * @return Model\Top\TopManga[]
+ * @throws ParserException
+ */
+ public function TopManga(int $page, ?string $type = null): array
+ {
+ return $this->myanimelist->getTopManga(
+ new Request\Top\TopMangaRequest($page, $type)
+ );
+ }
+
+ /**
+ * @param int $page
+ *
+ * @return Model\Top\TopCharacter[]
+ * @throws ParserException
+ */
+ public function TopCharacters(int $page = 1): array
+ {
+ return $this->myanimelist->getTopCharacters(
+ new Request\Top\TopCharactersRequest($page)
+ );
+ }
+
+ /**
+ * @param int $page
+ *
+ * @return Model\Top\TopPerson[]
+ * @throws ParserException
+ */
+ public function TopPeople(int $page = 1): array
+ {
+ return $this->myanimelist->getTopPeople(
+ new Request\Top\TopPeopleRequest($page)
+ );
+ }
+
+ /**
+ * @param string|null $query
+ * @param int $page
+ * @param null|Request\Search\AnimeSearchRequest $request
+ *
+ * @return Model\Search\AnimeSearch
+ * @throws ParserException
+ */
+ public function AnimeSearch(
+ ?string $query,
+ int $page = 1,
+ ?Request\Search\AnimeSearchRequest $request = null
+ ): Model\Search\AnimeSearch {
+ return $this->myanimelist->getAnimeSearch(
+ null !== $request
+ ? $request
+ ->setQuery($query)
+ ->setPage($page)
+ : new Request\Search\AnimeSearchRequest($query, $page)
+ );
+ }
+
+ /**
+ * @param string|null $query
+ * @param int $page
+ * @param null|Request\Search\MangaSearchRequest $request
+ *
+ * @return Model\Search\MangaSearch
+ * @throws ParserException
+ */
+ public function MangaSearch(
+ ?string $query,
+ int $page = 1,
+ ?Request\Search\MangaSearchRequest $request = null
+ ): Model\Search\MangaSearch {
+ return $this->myanimelist->getMangaSearch(
+ null !== $request
+ ? $request
+ ->setQuery($query)
+ ->setPage($page)
+ : new Request\Search\MangaSearchRequest($query, $page)
+ );
+ }
+
+ /**
+ * @param string|null $query
+ * @param int $page
+ * @param null|Request\Search\CharacterSearchRequest $request
+ *
+ * @return Model\Search\CharacterSearch
+ * @throws ParserException
+ */
+ public function CharacterSearch(
+ ?string $query,
+ int $page = 1,
+ ?Request\Search\CharacterSearchRequest $request = null
+ ): Model\Search\CharacterSearch {
+ return $this->myanimelist->getCharacterSearch(
+ null !== $request
+ ? $request
+ ->setQuery($query)
+ ->setPage($page)
+ : new Request\Search\CharacterSearchRequest($query, $page)
+ );
+ }
+
+ /**
+ * @param string|null $query
+ * @param int $page
+ * @param Request\Search\CharacterSearchRequest|Request\Search\PersonSearchRequest|null $request
+ *
+ * @return Model\Search\PersonSearch
+ */
+ public function PersonSearch(
+ ?string $query,
+ int $page = 1,
+ ?Request\Search\CharacterSearchRequest $request = null
+ ): Model\Search\PersonSearch {
+ return $this->myanimelist->getPersonSearch(
+ null !== $request
+ ? $request
+ ->setQuery($query)
+ ->setPage($page)
+ : new Request\Search\PersonSearchRequest($query, $page)
+ );
+ }
+
+ /**
+ * @param string $username
+ *
+ * @return \Jikan\Model\User\Profile
+ * @throws ParserException
+ */
+ public function UserProfile(string $username): Model\User\Profile
+ {
+ return $this->myanimelist->getUserProfile(
+ new Request\User\UserProfileRequest($username)
+ );
+ }
+
+ /**
+ * @param string $username
+ * @param int $page
+ *
+ * @return Model\User\Friend[]
+ * @throws ParserException
+ */
+ public function UserFriends(string $username, int $page = 1): array
+ {
+ return $this->myanimelist->getUserFriends(
+ new Request\User\UserFriendsRequest($username, $page)
+ );
+ }
+
+ /**
+ * @param string $username
+ * @param null|string $type
+ *
+ * @return array
+ * @throws ParserException
+ */
+ public function UserHistory(string $username, ?string $type = null): array
+ {
+ return $this->myanimelist->getUserHistory(
+ new Request\User\UserHistoryRequest($username, $type)
+ );
+ }
+}
diff --git a/src/Lib/Parser/AnimeCharacterStaffParse.php b/src/Lib/Parser/AnimeCharacterStaffParse.php
deleted file mode 100755
index 266a4a86..00000000
--- a/src/Lib/Parser/AnimeCharacterStaffParse.php
+++ /dev/null
@@ -1,147 +0,0 @@
-match as TemplateParse provides that option now
-
-namespace Jikan\Lib\Parser;
-
-use Jikan\Model\AnimeCharacterStaff as AnimeCharacterStaffModel;
-
-class AnimeCharacterStaffParse extends TemplateParse
-{
-
- private $return = [];
-
- public function parse() : Array
- {
-
-
-
- $this->model = new AnimeCharacterStaffModel();
-
- /*
- * Rules
- */
-
- $this->addRule('character', '~Characters & Voice Actors~', function() {
- $running = true;
- $i = 0;
- $characters = [];
- while ($running) {
- if (preg_match('~~', $this->file[$this->lineNo + $i])) {
- $running = false;
- }
-
- $character = [];
-
- if (preg_match('~
(.*) by (.*) \| Discuss \((.*) comments\)
(.*) by (.*) \| Discuss \((.*) comments\)
file[$this->lineNo + $i])) { - break; - } - - $synopsis .= $this->file[$this->lineNo + $i]; - - $i++; - } - - - $anime['synopsis'] = trim(htmlspecialchars_decode(strip_tags($synopsis))); - } - - if (preg_match('~
~', $this->file[$this->lineNo + $i], $this->matches)) { - $licensors = explode(',', $this->matches[1]); - foreach ($licensors as $key => $value) { - $value = trim($value); - - if (!empty($value)) { - $anime['licensor'][] = $value; - } - } - } - - while (!preg_match('~~', $this->file[$this->lineNo + $i])){$i++;} // haxing MAL's inconsistencies - - $i++; - $anime['airing_start'] = trim(strip_tags($this->file[$this->lineNo + $i])); - - while (!preg_match('~~', $this->file[$this->lineNo + $i])){$i++;} // haxing MAL's inconsistencies - $i++; - $anime['members'] = (int) trim(str_replace(',', '', $this->file[$this->lineNo + $i])); - - while (!preg_match('~~', $this->file[$this->lineNo + $i])){$i++;} // haxing MAL's inconsistencies - $i++; - $anime['score'] = trim($this->file[$this->lineNo + $i]) == 'N/A' ? null : (float) trim($this->file[$this->lineNo + $i]); - - $seasonal[] = $anime; - - } - - $i++; - } - return $seasonal; - } -} diff --git a/src/Lib/Parser/SearchParse.php b/src/Lib/Parser/SearchParse.php deleted file mode 100755 index 010885d1..00000000 --- a/src/Lib/Parser/SearchParse.php +++ /dev/null @@ -1,334 +0,0 @@ -type = $type; - $this->model = new SearchModel(); - - - /* - * Rules - */ - - switch ($type) { - case ANIME: - case MANGA: - - $this->addRule('title', '~~', function() { - $results = []; - $result = [ - 'mal_id' => null, - 'url' => null, - 'image_url' => null, - 'title' => null, - 'description' => null, - 'type' => null, - 'score' => null - ]; - - $i = 0; - while(true) { - $line = $this->file[$this->lineNo + $i]; - if (preg_match('~file[$this->lineNo + $i])) { - break; - } - - $synopsis .= $this->file[$this->lineNo + $i]; - - $i++; - } - - - $anime['synopsis'] = trim(htmlspecialchars_decode(strip_tags($synopsis))); - } - - if (preg_match('~
~', $this->file[$this->lineNo + $i], $this->matches)) { - $licensors = explode(',', $this->matches[1]); - foreach ($licensors as $key => $value) { - $value = trim($value); - - if (!empty($value)) { - $anime['licensor'][] = $value; - } - } - } - - while (!preg_match('~