Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
max-parallel: 4
matrix:
operatingSystem: [ubuntu-22.04, windows-latest]
phpVersion: ['8.2']
phpVersion: ['8.3']
fail-fast: false
runs-on: ${{ matrix.operatingSystem }}
name: ${{ matrix.operatingSystem }} / PHP ${{ matrix.phpVersion }}
Expand All @@ -21,7 +21,7 @@ jobs:
key: jikan-cache-v1
steps:
- name: Checkout changes
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup extension cache
id: extcache
Expand All @@ -32,7 +32,7 @@ jobs:
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
Expand All @@ -47,10 +47,13 @@ jobs:

- name: Setup dependency cache
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
shell: bash
run: |
dir=$(composer config cache-files-dir | sed 's|\\|/|g')
echo "dir=$dir" >> "$GITHUB_OUTPUT"

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
id: cache
with:
path: ${{ steps.composercache.outputs.dir }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ composer.phar
.phpdoc
.phive
/.phpunit.cache
*.Identifier
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"doctrine/collections": "^1.5",
"friendsofphp/php-cs-fixer": "^3.8",
"jikan-me/jikan-fixtures": "dev-master",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpro/grumphp": "^2.4",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpro/grumphp": "^1",
"squizlabs/php_codesniffer": "^3.3"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
>
<testsuites>
<testsuite name="unit">
<directory phpVersion="8.2" phpVersionOperator=">=">test/unit</directory>
<directory phpVersion="8.3" phpVersionOperator=">=">test/unit</directory>
</testsuite>
</testsuites>

Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Jikan](https://i.imgur.com/ccx3pxo.png)](#jikan---unofficial-myanimelistnet-php-api)
[![Jikan](https://i.imgur.com/WY8KuOp.png)](#jikan---unofficial-myanimelistnet-php-api)

# Jikan - Unofficial MyAnimeList.net PHP API

Expand All @@ -16,7 +16,7 @@ The word _Jikan_ literally translates to _Time_ in Japanese (**時間**). And th

| Version | Support | PHP | Lumen/Laravel |
|-----------------------------------------------------------------------------------------|-------------------------------------|-----------------------------------------------------------------------------|---------------|
| [`^5` (master)]([https://github.com/jikan-me/jikan](https://github.com/jikan-me/jikan)) | 🚧 New features - WIP | [![8.3](https://img.shields.io/badge/PHP-^%208.3-blue.svg?style=flat)]() | `^11` |
| [`^5` (master)]([https://github.com/jikan-me/jikan](https://github.com/jikan-me/jikan)) | 🚧 New features - WIP | [![8.3](https://img.shields.io/badge/PHP-^%208.3-blue.svg?style=flat)]() | `^11`,`^12` |
| [`^4` (master)]([https://github.com/jikan-me/jikan](https://github.com/jikan-me/jikan)) | ✅ Maintenance only | [![8.1](https://img.shields.io/badge/PHP-^%208.1-blue.svg?style=flat)]() | `^9`,`^10` |
| [`^3`](https://github.com/jikan-me/jikan/releases/tag/v3.3.2) | ❌ No longer maintained or supported | [![8.0](https://img.shields.io/badge/PHP-^%208.0-blue.svg?style=flat)]() | `^8`, `^9` |
| [`^2`](https://github.com/jikan-me/jikan/tree/2.19.4) | ❌ No longer maintained or supported | [![stable](https://img.shields.io/badge/PHP-^%207.1-blue.svg?style=flat)]() | `^6`
Expand All @@ -41,11 +41,11 @@ A REST API service is available as well
| JavaScript | [JikanJS](https://github.com/zuritor/jikanjs) by Zuritor |
| Java | [Jikan4java](https://github.com/Doomsdayrs/Jikan4java) by Doomsdayrs<br>[reactive-jikan](https://github.com/SandroHc/reactive-jikan) by Sandro Marques<br>[Jaikan](https://github.com/ShindouMihou/Jaikan) by ShindouMihou |
| Python | [JikanPy](https://github.com/abhinavk99/jikanpy) by Abhinav Kasamsetty |
| Deno | [Jikan.js](https://github.com/RPDJF/Jikan.js) by RPDJF |
| Node.js | [jikan-node](https://github.com/xy137/jikan-node) by xy137<br>[jikan-nodejs](https://github.com/ribeirogab/jikan-nodejs) by ribeirogab |
| TypeScript | [jikants](https://github.com/Julien-Broyard/jikants) by Julien Broyard<br>[jikan-client](https://github.com/javi11/jikan-client) by Javier Blanco |
| PHP | [jikan-php](https://github.com/janvernieuwe/jikan-jikanPHP) by Jan Vernieuwe |
| .NET | [Jikan.net](https://github.com/Ervie/jikan.net) by Ervie |
| Elixir | [JikanEx](https://github.com/seanbreckenridge/jikan_ex) by Sean Breckenridge |
| Go | [jikan-go](https://github.com/darenliang/jikan-go) by Daren Liang<br>[jikan2go](https://github.com/nokusukun/jikan2go) by nokusukun |
| Ruby | [Jikan.rb](https://github.com/Zerocchi/jikan.rb) by Zerocchi |
| Dart | [jikan-dart](https://github.com/charafau/jikan-dart) by Rafal Wachol |
Expand Down
6 changes: 3 additions & 3 deletions src/Helper/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class Parser
* @return Crawler
* @throws \InvalidArgumentException
*/
public static function removeChildNodes(Crawler $crawler): Crawler
public static function removeChildNodes(Crawler $crawler, bool $removeAllNodes = false): Crawler
{
if (!$crawler->count()) {
return $crawler;
}
$crawler->children()->each(
function (Crawler $crawler) {
function (Crawler $crawler) use ($removeAllNodes) {
$node = $crawler->getNode(0);
if ($node === null || $node->nodeType === 3 || \in_array($node->nodeName, self::ALLOWED_NODES, true)) {
if ($node === null || $node->nodeType === 3 || \in_array($node->nodeName, $removeAllNodes ? [] : self::ALLOWED_NODES, true)) {
return;
}
$node->parentNode->removeChild($node);
Expand Down
71 changes: 71 additions & 0 deletions src/Model/Article/ArticleList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Jikan\Model\Article;

use Jikan\Model\Common\Collection\Pagination;
use Jikan\Model\Common\Collection\Results;
use Jikan\Parser;

/**
* Class ArticleList
*/
class ArticleList extends Results implements Pagination
{
/**
* @var bool
*/
private $hasNextPage = false;

/**
* @var int
*/
private $lastVisiblePage = 1;


/**
* @param Parser\Article\ArticleListParser $parser
* @return self
*/
public static function fromParser(Parser\Article\ArticleListParser $parser): self
{
$instance = new self();

$instance->results = $parser->getResults();
$instance->lastVisiblePage = $parser->getLastVisiblePage();
$instance->hasNextPage = $parser->getHasNextPage();

return $instance;
}

/**
* @return static
*/
public static function mock(): self
{
return new self();
}

/**
* @return array
*/
public function getResults(): array
{
return $this->results;
}

/**
* @return bool
*/
public function hasNextPage(): bool
{
return $this->hasNextPage;
}

/**
* @return int
*/
public function getLastVisiblePage(): int
{
return $this->lastVisiblePage;
}
}
154 changes: 154 additions & 0 deletions src/Model/Article/ArticleListItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php

namespace Jikan\Model\Article;

use Jikan\Model\Resource\NewsImageResource\NewsImageResource;
use Jikan\Model\Resource\WrapImageResource\WrapImageResource;
use Jikan\Parser\Article\ArticleListItemParser;

/**
* Class ArticleListItem
*
* @package Jikan\Model
*/
class ArticleListItem
{
/**
* @var int|null
*/
private int|null $malId;

/**
* @var string
*/
private string $url;

/**
* @var string
*/
private string $title;

/**
* @var string
*/
private string $authorUsername;

/**
* @var string
*/
private string $authorUrl;

/**
* @var WrapImageResource
*/
private WrapImageResource $images;

/**
* @var int
*/
private int $views;

/**
* @var string
*/
private string $excerpt;

/**
* @var array
*/
private array $tags;

/**
* @param ArticleListItemParser $parser
*
* @return ArticleListItem
* @throws \InvalidArgumentException
*/
public static function fromParser(ArticleListItemParser $parser): ArticleListItem
{
$instance = new self();
$instance->malId = $parser->getMalId();
$instance->url = $parser->getUrl();
$instance->title = $parser->getTitle();
$instance->views = $parser->getViews();
$instance->tags = $parser->getTags();
$instance->authorUsername = $parser->getAuthor()->getName();
$instance->authorUrl = $parser->getAuthor()->getUrl();
$instance->images = WrapImageResource::factory($parser->getImageUrl());
$instance->excerpt = $parser->getExcerpt();

return $instance;
}

/**
* @return int|null
*/
public function getMalId(): ?int
{
return $this->malId;
}

/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}

/**
* @return string
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @return string
*/
public function getAuthorUsername(): string
{
return $this->authorUsername;
}

/**
* @return string
*/
public function getAuthorUrl(): string
{
return $this->authorUrl;
}

/**
* @return WrapImageResource
*/
public function getImages(): WrapImageResource
{
return $this->images;
}

/**
* @return int
*/
public function getViews(): int
{
return $this->views;
}

/**
* @return string
*/
public function getExcerpt(): string
{
return $this->excerpt;
}

/**
* @return array
*/
public function getTags(): array
{
return $this->tags;
}
}
41 changes: 41 additions & 0 deletions src/Model/Article/PinnedArticleList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Jikan\Model\Article;

use Jikan\Model\Common\Collection\Results;
use Jikan\Parser;

/**
* Class PinnedArticleList
*/
class PinnedArticleList extends Results
{
/**
* @param Parser\Article\PinnedArticleListParser $parser
* @return self
*/
public static function fromParser(Parser\Article\PinnedArticleListParser $parser): self
{
$instance = new self();

$instance->results = $parser->getResults();

return $instance;
}

/**
* @return static
*/
public static function mock(): self
{
return new self();
}

/**
* @return array
*/
public function getResults(): array
{
return $this->results;
}
}
Loading