Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality of Life Updates // v5 Preflight #542

Merged
merged 9 commits into from
Feb 1, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/archive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
archive:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/[email protected]
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code-quality-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
codeQuality:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
name: PHP
steps:
- name: Checkout changes
Expand All @@ -15,7 +15,7 @@ jobs:
- name: Setup PHP and linter
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.2'
tools: parallel-lint, phpunit, php-cs-fixer
- name: Run code quality checks
run: ./.github/workflows/utilities/lint-pr ${{ github.base_ref }}
4 changes: 2 additions & 2 deletions .github/workflows/code-quality-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
codeQuality:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
name: PHP
steps:
- name: Checkout changes
Expand All @@ -17,7 +17,7 @@ jobs:
- name: Setup PHP and linter
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.2'
tools: parallel-lint, phpunit, php-cs-fixer
- name: Run code quality checks
run: ./.github/workflows/utilities/lint-push
2 changes: 1 addition & 1 deletion .github/workflows/comment-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
comment-run:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
strategy:
max-parallel: 4
matrix:
operatingSystem: [ubuntu-20.04, windows-latest]
phpVersion: ['8.0', '8.1']
operatingSystem: [ubuntu-22.04, windows-latest]
phpVersion: ['8.2']
fail-fast: false
runs-on: ${{ matrix.operatingSystem }}
name: ${{ matrix.operatingSystem }} / PHP ${{ matrix.phpVersion }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/.php-cs-fixer.cache
composer.phar
.phpunit.result.cache
.phpdoc
.phive
4 changes: 3 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'@PSR12' => true,
'@PER-CS' => true,
'@PHP82Migration' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Jikan API
Copyright (c) 2018-2024 Jikan API

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 15 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"minimum-stability": "stable",
"authors": [
{
"name": "Irfan",
"name": "Nekomata",
"email": "[email protected]"
}
],
Expand All @@ -19,24 +19,25 @@
},
"autoload-dev": {
"psr-4": {
"JikanTest\\": [
"test/JikanTest"
]
"JikanTest\\": [
"test/unit"
]
}
},
"require": {
"php": "^8.0",
"php": "^8.2",
"ext-json": "*",
"fabpot/goutte": "^4.0"
"symfony/browser-kit": "^6.4",
"symfony/css-selector": "^6.4",
"symfony/http-client": "^6.4"
},
"require-dev": {
"brianium/paratest": "^6.4.1",
"brianium/paratest": "^7.3",
"doctrine/collections": "^1.5",
"friendsofphp/php-cs-fixer": "^3.8",
"php-parallel-lint/php-parallel-lint": "^1.3",
"jikan-me/jikan-fixtures": "dev-master",
"phpro/grumphp": "^1.7.0",
"phpunit/phpunit": "~9.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpro/grumphp": "^2.4",
"squizlabs/php_codesniffer": "^3.3"
},
"scripts": {
Expand All @@ -46,6 +47,10 @@
"composer config repositories.fixtures path ../jikan-fixtures",
"composer update jikan-me/jikan-fixtures",
"composer config repositories.fixtures --unset"
],
"generate-docs": [
"git clone https://github.com/jikan-me/jikan-docs.git ../jikan-docs || git -C ../jikan-docs reset --hard origin/master",
"phpDocumentor run -d src -t ../jikan-docs/docs"
]
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ grumphp:
- 'die'
paratest:
always_execute: true
phplint: ~
phplint: ~
27 changes: 18 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
cacheDirectory=".phpunit.cache"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
colors="true"
failOnEmptyTestSuite="true"
>
<testsuites>
<testsuite name="Unit">
<directory>./test/JikanTest</directory>
<testsuite name="unit">
<directory phpVersion="8.2" phpVersionOperator=">=">test/unit</directory>
</testsuite>
</testsuites>

<php>
<ini name="precision" value="14"/>
<ini name="serialize_precision" value="14"/>

<const name="PHPUNIT_TESTSUITE" value="true"/>
</php>
</phpunit>
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<phpunit colors="true">
<testsuites>
<testsuite name="Unit">
<directory>./test/JikanTest</directory>
<directory>./test/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
4 changes: 1 addition & 3 deletions src/Exception/BadResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
*
* @package Jikan\Exception
*/
class BadResponseException extends \Exception
{
}
class BadResponseException extends \Exception {}
10 changes: 5 additions & 5 deletions src/Helper/JString.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public static function cleanse(string $string): string
$string = preg_replace('~[[:cntrl:]]~', "", $string);

// strip any leftover tags
// $string = htmlspecialchars_decode(strip_tags($string));
// $string = htmlspecialchars_decode(strip_tags($string));
$string = strip_tags($string);

// trim Nbsp // causing serializer issues
// $string = self::UTF8NbspTrim($string);
// $string = self::UTF8NbspTrim($string);

// remove any newlines at the end
$string = str_replace('\\n', "\n", $string);
// $string = preg_replace('~([\n]+)~', '', $string);
// $string = preg_replace('~([\n]+)~', '', $string);

// trim
$string = trim($string);
Expand All @@ -52,14 +52,14 @@ public static function cleanse(string $string): string
*/
public static function UTF8NbspTrim(string $string): string
{
return trim($string, \chr(0xC2).\chr(0xA0));
return trim($string, \chr(0xC2) . \chr(0xA0));
}

/**
* @param string $string
* @return string
*/
public static function strToCanonical(string $string) : string
public static function strToCanonical(string $string): string
{
return str_replace(
[' ', '/'],
Expand Down
6 changes: 3 additions & 3 deletions src/Helper/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Media
* @param string|null $url
* @return string
*/
public static function youtubeIdFromUrl(?string $url) : ?string
public static function youtubeIdFromUrl(?string $url): ?string
{
/**
* https://stackoverflow.com/a/17030234
Expand All @@ -38,7 +38,7 @@ public static function youtubeIdFromUrl(?string $url) : ?string
* @param string $id
* @return string
*/
public static function generateYoutubeUrlFromId(?string $id) : ?string
public static function generateYoutubeUrlFromId(?string $id): ?string
{
if ($id === null) {
return null;
Expand All @@ -51,7 +51,7 @@ public static function generateYoutubeUrlFromId(?string $id) : ?string
* @param string $id
* @return YoutubeImageResource
*/
public static function generateYoutubeImageResource(?string $id) : YoutubeImageResource
public static function generateYoutubeImageResource(?string $id): YoutubeImageResource
{
return YoutubeImageResource::factory($id);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Helper/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function (Crawler $crawler) {
*/
public static function idFromUrl(string $url): int
{
return (int)preg_replace('#https://myanimelist.net(/\w+/)(\d+).*#', '$2', $url);
return (int) preg_replace('#https://myanimelist.net(/\w+/)(\d+).*#', '$2', $url);
}

/**
Expand All @@ -57,7 +57,7 @@ public static function idFromUrl(string $url): int
* @param string $url
* @return int
*/
public static function clubIdFromUrl(string $url) : int
public static function clubIdFromUrl(string $url): int
{
return (int) preg_replace('~.*\.php\?cid=([\d]+)$~', '$1', $url);
}
Expand All @@ -82,7 +82,7 @@ public static function suffixIdFromUrl(string $url): int
public static function parseForumDate(string $date): ?\DateTimeImmutable
{
if (!preg_match('/\d{4}/', $date)) {
$date .= ', '.date('Y');
$date .= ', ' . date('Y');
}

return self::parseDate($date);
Expand All @@ -96,7 +96,7 @@ public static function parseForumDate(string $date): ?\DateTimeImmutable
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'));
return \DateTimeImmutable::createFromFormat('!Y-m-d', $date . '-01-01', new \DateTimeZone('UTC'));
}

if (preg_match('/(\w{3}), (\d{4})/', $date, $matches)) {
Expand Down Expand Up @@ -185,7 +185,7 @@ public static function parseDateMDYReadable(string $date): ?\DateTimeImmutable
* @param string $dateTime
* @return \DateTimeImmutable|null
*/
public static function parseDateTimePST(string $dateTime) : ?\DateTimeImmutable
public static function parseDateTimePST(string $dateTime): ?\DateTimeImmutable
{
try {
$malTimeZone = new \DateTimeZone('America/Los_Angeles'); //
Expand Down Expand Up @@ -217,7 +217,7 @@ public static function textOrNull(Crawler $crawler): ?string
* @return string
* @throws \InvalidArgumentException
*/
public static function parseImageQuality(string $imageUrl) : string
public static function parseImageQuality(string $imageUrl): string
{
// adding `v` prefix returns a very small thumbnail, as opposed to adding `l`
$imageUrl = str_replace(['v.jpg', 't.jpg', 'l.jpg'], '.jpg', $imageUrl);
Expand All @@ -230,7 +230,7 @@ public static function parseImageQuality(string $imageUrl) : string
* @return string
* @throws \InvalidArgumentException
*/
public static function parseImageThumbToHQ(string $imageUrl) : string
public static function parseImageThumbToHQ(string $imageUrl): string
{
return str_replace(['thumbs/', '_thumb'], '', $imageUrl);
}
Expand All @@ -250,6 +250,6 @@ public static function parseDurationToSeconds(string $duration): ?int
$minutes = $match[2] ?? 0;
$seconds = $match[3] ?? 0;

return ($hours*60*60) + ($minutes*60) + $seconds;
return ($hours * 60 * 60) + ($minutes * 60) + $seconds;
}
}
14 changes: 7 additions & 7 deletions src/Goutte/GoutteWrapper.php → src/Http/HttpClientWrapper.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

namespace Jikan\Goutte;
namespace Jikan\Http;

use Goutte\Client;
use Jikan\Exception\BadResponseException;
use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\DomCrawler\Crawler;

/**
* Class GoutteWrapper
* Class HttpClientWrapper
*
* @package Jikan\Goutte
* @package Jikan\Http
*/
class GoutteWrapper extends Client
class HttpClientWrapper extends HttpBrowser
{
/**
* @inheritdoc
Expand All @@ -33,7 +33,7 @@ public function request(
array $server = [],
string $content = null,
bool $changeHistory = true
) : Crawler {
): Crawler {
$response = parent::request(
$method,
$uri,
Expand All @@ -47,7 +47,7 @@ public function request(
$internalResponse = $this->getInternalResponse();
if ($internalResponse->getStatusCode() >= 400) {
throw new BadResponseException(
$internalResponse->getStatusCode().' on '.$response->getUri(),
$internalResponse->getStatusCode() . ' on ' . $response->getUri(),
$internalResponse->getStatusCode()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Anime/AnimeReviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function fromParser(Parser\Anime\AnimeReviewsParser $parser): self
/**
* @return static
*/
public static function mock() : self
public static function mock(): self
{
return new self();
}
Expand Down
Loading
Loading