Skip to content

Commit

Permalink
Merge pull request #543 from jikan-me/feature/industry-news
Browse files Browse the repository at this point in the history
Industry News
  • Loading branch information
irfan-dahir committed May 31, 2024
2 parents 50eaee6 + 8c2e0b5 commit 65b89ea
Show file tree
Hide file tree
Showing 96 changed files with 2,864 additions and 1,330 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ composer.phar
.phpunit.result.cache
.phpdoc
.phive
.phpunit.cache
1 change: 1 addition & 0 deletions .phpunit.cache/test-results

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
failOnWarning="true"
colors="true"
failOnEmptyTestSuite="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="unit">
Expand Down
9 changes: 9 additions & 0 deletions src/Helper/JString.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@ public static function isStringFloat(string $string): bool
{
return is_numeric($string) && str_contains($string, '.');
}

public static function ifEmptyStringReturnNull(string $string): ?string
{
if (empty($string)) {
return null;
}

return $string;
}
}
13 changes: 13 additions & 0 deletions src/Helper/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ public static function idFromUrl(string $url): int
return (int) preg_replace('#https://myanimelist.net(/\w+/)(\d+).*#', '$2', $url);
}

/**
* Extract a string id from a mal url
*
* @param string $url
*
* @return string
*/
public static function stringIdFromUrl(string $url): string
{
$urlParts = explode("/", parse_url($url)['path']);
return $urlParts[array_key_last($urlParts)];
}

/**
* Extract club ID from MAL URl
*
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Common/MalUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class MalUrl
/**
* @var string
*/
private $name;
private string $name;

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

/**
* Genre constructor.
Expand Down
160 changes: 160 additions & 0 deletions src/Model/Common/NewsMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php

namespace Jikan\Model\Common;

use Jikan\Model\Resource\NewsImageResource\NewsImageResource;
use Jikan\Parser\Common\NewsMetaParser;

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

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

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

/**
* @var \DateTimeImmutable
*/
private \DateTimeImmutable $date;

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

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

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

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

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

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

$instance->malId = $parser->getMalId();
$instance->url = $parser->getUrl();
$instance->title = $parser->getTitle();
$instance->comments = $parser->getComments();
$instance->authorUsername = $parser->getAuthor()->getName();
$instance->authorUrl = $parser->getAuthor()->getUrl();
$instance->forumUrl = $parser->getDiscussionLink();
$instance->images = NewsImageResource::factory($parser->getImageUrl());
$instance->date = $parser->getDate();

return $instance;
}

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

/**
* @return int
*/
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 \DateTimeImmutable
*/
public function getDate(): \DateTimeImmutable
{
return $this->date;
}

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

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

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

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

/**
* @return int
*/
public function getComments(): int
{
return $this->comments;
}
}
92 changes: 92 additions & 0 deletions src/Model/Common/TagMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace Jikan\Model\Common;

use Jikan\Helper\Parser;
use Jikan\Parser\Common\TagUrlParser;

/**
* Class ItemMeta
*
* @package Jikan\Model
*/
class TagMeta
{
/**
* @var string
*/
private string $name;
/**
* @var string
*/
private string $malId;
/**
* @var string
*/
private string $url;
/**
* @var string
*/
private string $type;
/**
* @var string|null
*/
private ?string $description;


/**
* @param string $name
* @param string $url
* @param string $type
* @param string|null $description
*/
public function __construct(string $name, string $url, string $type, ?string $description)
{
$this->url = $url;
$this->name = $name;
$this->type = $type;
$this->description = $description;
$this->malId = Parser::stringIdFromUrl($this->url);
}

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

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

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

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

/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}

}
71 changes: 71 additions & 0 deletions src/Model/Common/TagUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Jikan\Model\Common;

/**
* Class Url
*
* @package Jikan\Model
*/
class TagUrl
{
/**
* @var string
*/
private string $malId;

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

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

/**
* Genre constructor.
*
* @param string $name
* @param string $url
*/
public function __construct(string $malId, string $name, string $url)
{
$this->malId = $malId;
$this->name = $name;
$this->url = $url;
}

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

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

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

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

0 comments on commit 65b89ea

Please sign in to comment.