chore: update php dependencies to latest

This commit is contained in:
Yassine Doghri 2021-08-11 15:47:23 +00:00
parent f15f26240c
commit 3ff1364906
33 changed files with 3428 additions and 9673 deletions

View File

@ -34,7 +34,7 @@ class Analytics extends AnalyticsBase
*
* @param string|string[] $audioFilePath
*/
public function getAudioFileUrl($audioFilePath): string
public function getAudioFileUrl(string|array $audioFilePath): string
{
helper('media');

View File

@ -102,7 +102,7 @@ class Services extends BaseService
}
/**
* @return mixed
* @return mixed|$this
*/
public static function authorization(
Model $groupModel = null,
@ -122,12 +122,14 @@ class Services extends BaseService
$permissionModel = new PermissionModel();
}
/* @phpstan-ignore-next-line */
$instance = new FlatAuthorization($groupModel, $permissionModel);
if ($userModel === null) {
$userModel = new UserModel();
}
/* @phpstan-ignore-next-line */
return $instance->setUserModel($userModel);
}

View File

@ -27,7 +27,7 @@ class ContributorController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
throw PageNotFoundException::forPageNotFound();
}

View File

@ -21,7 +21,7 @@ class PageController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
return $this->{$method}();
}

View File

@ -22,7 +22,7 @@ class PersonController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
return $this->{$method}();
}

View File

@ -27,7 +27,7 @@ class PodcastController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
return $this->{$method}();
}

View File

@ -34,7 +34,7 @@ class PodcastImportController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
return $this->{$method}();
}

View File

@ -22,7 +22,7 @@ class PodcastPersonController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
throw PageNotFoundException::forPageNotFound();
}

View File

@ -23,7 +23,7 @@ class PodcastPlatformController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
return $this->{$method}();
}

View File

@ -23,7 +23,7 @@ class UserController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
return $this->{$method}();
}

View File

@ -20,7 +20,7 @@ class PageController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
throw PageNotFoundException::forPageNotFound();
}

View File

@ -30,7 +30,7 @@ class PodcastController extends BaseController
public function _remap(string $method, string ...$params): mixed
{
if (count($params) === 0) {
if ($params === []) {
throw PageNotFoundException::forPageNotFound();
}

View File

@ -35,7 +35,7 @@ class Actor extends ActivityPubActor
throw new RuntimeException('Podcast id must be set before getting associated podcast.');
}
if ($this->podcast === null) {
if (! $this->podcast instanceof Podcast) {
$this->podcast = (new PodcastModel())->getPodcastByActorId($this->id);
}

View File

@ -59,7 +59,7 @@ class Credit extends Entity
throw new RuntimeException('Credit must have person_id before getting person.');
}
if ($this->person === null) {
if (! $this->person instanceof Person) {
$this->person = (new PersonModel())->getPersonById($this->person_id);
}
@ -72,7 +72,7 @@ class Credit extends Entity
throw new RuntimeException('Credit must have podcast_id before getting podcast.');
}
if ($this->podcast === null) {
if (! $this->podcast instanceof Podcast) {
$this->podcast = (new PodcastModel())->getPodcastById($this->podcast_id);
}
@ -85,7 +85,7 @@ class Credit extends Entity
throw new RuntimeException('Credit must have episode_id before getting episode.');
}
if ($this->episode === null) {
if (! $this->episode instanceof Episode) {
$this->episode = (new EpisodeModel())->getPublishedEpisodeById($this->podcast_id, $this->episode_id);
}

View File

@ -261,7 +261,7 @@ class Podcast extends Entity
throw new RuntimeException('Podcast must be created before getting category.');
}
if ($this->category === null) {
if (! $this->category instanceof Category) {
$this->category = (new CategoryModel())->getCategoryById($this->category_id);
}

View File

@ -49,7 +49,7 @@ class Status extends ActivityPubStatus
throw new RuntimeException('Status must have an episode_id before getting episode.');
}
if ($this->episode === null) {
if (! $this->episode instanceof Episode) {
$this->episode = (new EpisodeModel())->getEpisodeById($this->episode_id);
}

View File

@ -50,7 +50,7 @@ class PermissionFilter implements FilterInterface
if (
(str_starts_with($permission, 'podcast-') ||
str_starts_with($permission, 'podcast_episodes-')) &&
count($routerParams) > 0
$routerParams !== []
) {
if (
($groupId = (new PodcastModel())->getContributorGroupId(

View File

@ -7,7 +7,6 @@ declare(strict_types=1);
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
use App\Entities\Location;
use App\Entities\Person;
use CodeIgniter\I18n\Time;
@ -111,9 +110,7 @@ if (! function_exists('button')) {
CODE_SAMPLE;
}
}
// ------------------------------------------------------------------------
if (! function_exists('icon_button')) {
/**
* Icon Button component
@ -147,9 +144,7 @@ if (! function_exists('icon_button')) {
return button(icon($icon), $uri, $options, $attributes);
}
}
// ------------------------------------------------------------------------
if (! function_exists('hint_tooltip')) {
/**
* Hint component
@ -172,9 +167,7 @@ if (! function_exists('hint_tooltip')) {
return $tooltip . '">' . icon('question') . '</span>';
}
}
// ------------------------------------------------------------------------
if (! function_exists('data_table')) {
/**
* Data table component
@ -230,9 +223,7 @@ if (! function_exists('data_table')) {
'</div>';
}
}
// ------------------------------------------------------------------------
if (! function_exists('publication_pill')) {
/**
* Publication pill component
@ -259,9 +250,7 @@ if (! function_exists('publication_pill')) {
'</span>';
}
}
// ------------------------------------------------------------------------
if (! function_exists('publication_button')) {
/**
* Publication button component
@ -304,9 +293,7 @@ if (! function_exists('publication_button')) {
]);
}
}
// ------------------------------------------------------------------------
if (! function_exists('episode_numbering')) {
/**
* Returns relevant translated episode numbering.
@ -358,7 +345,6 @@ if (! function_exists('episode_numbering')) {
'</span>';
}
}
if (! function_exists('location_link')) {
/**
* Returns link to display from location info
@ -382,9 +368,7 @@ if (! function_exists('location_link')) {
);
}
}
// ------------------------------------------------------------------------
if (! function_exists('person_list')) {
/**
* Returns list of persons images
@ -437,11 +421,7 @@ if (! function_exists('person_list')) {
return $personList . '</div>';
}
}
// ------------------------------------------------------------------------
if (! function_exists('play_episode_button')) {
/**
* Returns play episode button
@ -460,23 +440,20 @@ if (! function_exists('play_episode_button')) {
return <<<CODE_SAMPLE
<play-episode-button
class="${class}"
id="${episodeId}"
imageSrc=${episodeThumbnail}
title="${episodeTitle}"
podcast="${podcastTitle}"
src="${source}"
mediaType="${mediaType}"
playLabel="${playLabel}"
playingLabel="${playingLabel}"
class="{$class}"
id="{$episodeId}"
imageSrc={$episodeThumbnail}
title="{$episodeTitle}"
podcast="{$podcastTitle}"
src="{$source}"
mediaType="{$mediaType}"
playLabel="{$playLabel}"
playingLabel="{$playingLabel}"
></play-episode-button>
CODE_SAMPLE;
}
}
// ------------------------------------------------------------------------
if (! function_exists('audio_player')) {
/**
* Returns audio player
@ -490,13 +467,13 @@ if (! function_exists('audio_player')) {
<vm-player
id="castopod-vm-player"
theme="light"
language="${language}"
language="{$language}"
icons="castopod-icons"
class="${class}"
class="{$class}"
style="--vm-player-box-shadow:0; --vm-player-theme: #009486; --vm-control-spacing: 4px;"
>
<vm-audio preload="none">
<source src="${source}" type="${mediaType}" />
<source src="{$source}" type="{$mediaType}" />
</vm-audio>
<vm-ui>
<vm-icon-library name="castopod-icons"></vm-icon-library>
@ -514,9 +491,7 @@ if (! function_exists('audio_player')) {
CODE_SAMPLE;
}
}
// ------------------------------------------------------------------------
if (! function_exists('relative_time')) {
function relative_time(Time $time, string $class = ''): string
{
@ -524,18 +499,16 @@ if (! function_exists('relative_time')) {
$datetime = $time->toDateTimeString();
return <<<CODE_SAMPLE
<time-ago class="${class}" datetime="${datetime}">
<time-ago class="{$class}" datetime="{$datetime}">
<time
itemprop="published"
datetime="${datetime}"
title="${time}">${translatedDate}</time>
datetime="{$datetime}"
title="{$time}">{$translatedDate}</time>
</time-ago>
CODE_SAMPLE;
}
}
// ------------------------------------------------------------------------
if (! function_exists('xml_editor')) {
/**
* XML Editor field
@ -554,9 +527,8 @@ if (! function_exists('xml_editor')) {
$textarea = form_textarea($data, $value, $extra);
return <<<CODE_SAMPLE
<xml-editor>${textarea}</time-ago>
<xml-editor>{$textarea}</time-ago>
CODE_SAMPLE;
}
}
// ------------------------------------------------------------------------

View File

@ -17,10 +17,8 @@ use Config\Services;
if (! function_exists('save_media')) {
/**
* Saves a file to the corresponding podcast folder in `public/media`
*
* @param File|UploadedFile $file
*/
function save_media(File $file, string $folder = '', string $filename = ''): string
function save_media(File|UploadedFile $file, string $folder = '', string $filename = ''): string
{
if (($extension = $file->getExtension()) !== '') {
$filename = $filename . '.' . $extension;

View File

@ -182,10 +182,12 @@ if (! function_exists('get_rss_feed')) {
$channel->addChild('type', $podcast->type, $itunesNamespace);
$podcast->copyright &&
$channel->addChild('copyright', $podcast->copyright);
$podcast->is_blocked &&
if ($podcast->is_blocked) {
$channel->addChild('block', 'Yes', $itunesNamespace);
$podcast->is_completed &&
}
if ($podcast->is_completed) {
$channel->addChild('complete', 'Yes', $itunesNamespace);
}
$image = $channel->addChild('image');
$image->addChild('url', $podcast->image->feed_url);
@ -306,8 +308,9 @@ if (! function_exists('get_rss_feed')) {
}
}
$episode->is_blocked &&
if ($episode->is_blocked) {
$item->addChild('block', 'Yes', $itunesNamespace);
}
if ($episode->custom_rss !== null) {
array_to_rss([

View File

@ -319,121 +319,113 @@ if (! function_exists('linkify')) {
// Extract text links for each protocol
foreach ($protocols as $protocol) {
/** @phpstan-ignore-next-line */
switch ($protocol) {
case 'http':
case 'https':
$text = preg_replace_callback(
'~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
function (array $match) use ($protocol, &$links) {
if ($match[1]) {
$protocol = $match[1];
}
$link = $match[2] ?: $match[3];
$text = match ($protocol) {
'http', 'https' => preg_replace_callback(
'~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
function (array $match) use ($protocol, &$links) {
if ($match[1]) {
$protocol = $match[1];
}
$link = $match[2] ?: $match[3];
helper('text');
helper('text');
$link = preg_replace('~^www\.(.+\.)~i', '$1', $link);
$link = preg_replace('~^www\.(.+\.)~i', '$1', $link);
return '<' .
array_push(
$links,
anchor(
"{$protocol}://{$link}",
ellipsize(rtrim($link, '/'), 30),
[
return '<' .
array_push(
$links,
anchor(
"{$protocol}://{$link}",
ellipsize(rtrim($link, '/'), 30),
[
'target' => '_blank',
'rel' => 'noopener noreferrer',
],
),
) .
'>';
},
$text,
),
'handle' => preg_replace_callback(
'~(?<!\w)@(?<username>\w++)(?:@(?<domain>(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]))?~',
function ($match) use (&$links) {
// check if host is set and look for actor in database
if (isset($match['host'])) {
if (
$actor = model(
'ActorModel',
)->getActorByUsername($match['username'], $match['domain'])
) {
// TODO: check that host is local to remove target blank?
return '<' .
array_push(
$links,
anchor($actor->uri, $match[0], [
'target' => '_blank',
'rel' => 'noopener noreferrer',
],
),
) .
'>';
},
$text,
);
break;
case 'handle':
$text = preg_replace_callback(
'~(?<!\w)@(?<username>\w++)(?:@(?<domain>(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]))?~',
function ($match) use (&$links) {
// check if host is set and look for actor in database
if (isset($match['host'])) {
if (
$actor = model(
'ActorModel',
)->getActorByUsername($match['username'], $match['domain'])
) {
// TODO: check that host is local to remove target blank?
return '<' .
array_push(
$links,
anchor($actor->uri, $match[0], [
'target' => '_blank',
'rel' => 'noopener noreferrer',
]),
) .
'>';
}
try {
$actor = get_or_create_actor($match['username'], $match['domain']);
return '<' .
array_push(
$links,
anchor($actor->uri, $match[0], [
'target' => '_blank',
'rel' => 'noopener noreferrer',
]),
) .
'>';
} catch (\CodeIgniter\HTTP\Exceptions\HTTPException) {
// Couldn't retrieve actor, do not wrap the text in link
return '<' .
array_push($links, $match[0]) .
'>';
}
} else {
if (
$actor = model('ActorModel')
->getActorByUsername($match['username'])
) {
return '<' .
array_push($links, anchor($actor->uri, $match[0])) .
'>';
}
]),
) .
'>';
}
try {
$actor = get_or_create_actor($match['username'], $match['domain']);
return '<' .
array_push(
$links,
anchor($actor->uri, $match[0], [
'target' => '_blank',
'rel' => 'noopener noreferrer',
]),
) .
'>';
} catch (HTTPException) {
// Couldn't retrieve actor, do not wrap the text in link
return '<' .
array_push($links, $match[0]) .
'>';
}
},
$text,
);
break;
default:
$text = preg_replace_callback(
'~' .
preg_quote($protocol, '~') .
'://([^\s<]+?)(?<![\.,:])~i',
function (array $match) use ($protocol, &$links) {
} else {
if (
$actor = model('ActorModel')
->getActorByUsername($match['username'])
) {
return '<' .
array_push($links, anchor($actor->uri, $match[0])) .
'>';
}
return '<' .
array_push(
$links,
anchor(
"{$protocol}://{$match[1]}",
$match[1],
[
'target' => '_blank',
'rel' => 'noopener noreferrer',
],
),
) .
array_push($links, $match[0]) .
'>';
},
$text,
);
break;
}
}
},
$text,
),
default => preg_replace_callback(
'~' .
preg_quote($protocol, '~') .
'://([^\s<]+?)(?<![\.,:])~i',
function (array $match) use ($protocol, &$links) {
return '<' .
array_push(
$links,
anchor(
"{$protocol}://{$match[1]}",
$match[1],
[
'target' => '_blank',
'rel' => 'noopener noreferrer',
],
),
) .
'>';
},
$text,
),
};
}
// Insert all links

View File

@ -164,7 +164,7 @@ class StatusModel extends UuidModel
->get()
->getResultArray();
return count($result) !== 0
return $result !== []
? (int) $result[0]['timestamp_diff']
: false;
}

View File

@ -18,7 +18,7 @@ class NoteObject extends ActivityPubNoteObject
/**
* @param Status $status
*/
public function __construct($status)
public function __construct(\ActivityPub\Entities\Status $status)
{
parent::__construct($status);

View File

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace App\Libraries;
use DOMDocument;
use SimpleXMLElement;
class SimpleRSSElement extends SimpleXMLElement
@ -60,7 +61,7 @@ class SimpleRSSElement extends SimpleXMLElement
if ($node !== null) {
$no = $node->ownerDocument;
$value = $escape ? esc($value ?? '') : $value ?? '';
if ($no === null) {
if (! $no instanceof DOMDocument) {
return $newChild;
}
if (is_array($value)) {
@ -68,7 +69,6 @@ class SimpleRSSElement extends SimpleXMLElement
}
/** @noRector RecastingRemovalRector */
$node->appendChild($no->createTextNode((string) $value));
return $newChild;
}
}

View File

@ -255,7 +255,7 @@ class PodcastModel extends Model
->getResultObject();
}
return count($userPodcast) > 0
return $userPodcast !== []
? (int) $userPodcast[0]->group_id
: false;
}

View File

@ -28,7 +28,7 @@
],
[
'header' => lang('Contributor.list.role'),
'cell' => function ($contributor) {
'cell' => function ($contributor): string {
return lang('Contributor.roles.' . $contributor->podcast_role);
},
],

View File

@ -18,10 +18,12 @@
<?= $this->section('content') ?>
<p class="mb-4 text-sm italic text-gray-700"><?= lang('Common.pageInfo', [
'currentPage' => $pager->getDetails()['currentPage'],
'pageCount' => $pager->getDetails()['pageCount'],
]) ?></p>
<p class="mb-4 text-sm italic text-gray-700">
<?= lang('Common.pageInfo', [
'currentPage' => $pager->getDetails()['currentPage'],
'pageCount' => $pager->getDetails()['pageCount'],
]) ?>
</p>
<?= data_table(
[
@ -59,7 +61,7 @@
],
[
'header' => lang('Episode.list.visibility'),
'cell' => function ($episode) {
'cell' => function ($episode): string {
return publication_pill(
$episode->published_at,
$episode->publication_status,
@ -68,7 +70,7 @@
],
[
'header' => lang('Episode.list.comments'),
'cell' => function ($episode) {
'cell' => function ($episode): int {
return count($episode->comments);
},
],
@ -123,4 +125,4 @@
<?= $pager->links() ?>
<?= $this->endSection() ?>
<?= $this->endSection() ?>

View File

@ -1,7 +1,6 @@
<?php
use CodeIgniter\CLI\CLI;
// The main Exception
CLI::newLine();
CLI::write('[' . $exception::class . ']', 'light_gray', 'red');
@ -16,7 +15,6 @@ CLI::write(
),
);
CLI::newLine();
// The backtrace
if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) {
$backtraces = $exception->getTrace();
@ -56,16 +54,12 @@ if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) {
$args = implode(
', ',
array_map(function ($value) {
switch (true) {
case is_object($value):
return 'Object(' . $value::class . ')';
case is_array($value):
return count($value) > 0 ? '[...]' : '[]';
case is_null($value):
return 'null'; // return the lowercased version
default:
return var_export($value, true);
}
return match (true) {
is_object($value) => 'Object(' . $value::class . ')',
is_array($value) => $value !== [] ? '[...]' : '[]',
is_null($value) => 'null',
default => var_export($value, true),
};
}, array_values($error['args'] ?? [])),
);

View File

@ -91,7 +91,7 @@ $errorId = uniqid('error', true); ?>
<?php
$params = null;
// Reflection by name is not available for closure function
if (substr($row['function'], -1) !== '}') {
if (!str_ends_with($row['function'], '}')) {
$mirror = isset($row['class']) ? new ReflectionMethod($row['class'], $row['function']) : new ReflectionFunction($row['function']);
$params = $mirror->getParameters();
}

View File

@ -12,9 +12,9 @@
"geoip2/geoip2": "^v2.11.0",
"myth/auth": "dev-develop",
"codeigniter4/codeigniter4": "dev-develop",
"league/commonmark": "^1.6.2",
"league/commonmark": "^1.6.6",
"vlucas/phpdotenv": "^v5.3.0",
"league/html-to-markdown": "^4.10.0",
"league/html-to-markdown": "^5.0.0",
"opawg/user-agents-php": "^v1.0",
"podlibre/ipcat": "^v1.0",
"podlibre/podcast-namespace": "^v1.0.6",
@ -23,16 +23,16 @@
"essence/essence": "^3.5.4"
},
"require-dev": {
"mikey179/vfsstream": "^v1.6.8",
"phpunit/phpunit": "^9.5.4",
"rector/rector": "^0.11.5",
"captainhook/captainhook": "^5.10.0",
"phpstan/phpstan": "^0.12.85",
"mikey179/vfsstream": "^1.6.9",
"phpunit/phpunit": "^9.5.8",
"rector/rector": "^0.11.46",
"captainhook/captainhook": "^5.10.1",
"phpstan/phpstan": "^0.12.94",
"phpstan/extension-installer": "^1.1.0",
"rector/rector-phpstan-rules": "^0.2.9",
"symplify/phpstan-extensions": "^v9.3.12",
"symplify/easy-coding-standard": "^v9.3.12",
"symplify/coding-standard": "^v9.3.12"
"symplify/phpstan-extensions": "^9.4.27",
"symplify/easy-coding-standard": "^9.4.27",
"symplify/coding-standard": "^9.4.27",
"rector/phpstan-rules": "^0.3.4"
},
"autoload": {
"psr-4": {

1571
composer.lock generated

File diff suppressed because it is too large Load Diff

11148
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@ parameters:
- '#Access to an undefined property CodeIgniter\\Database\\BaseBuilder::\$pager#'
- '#Function \"preg_.*\(\)\" cannot be used/left in the code#'
- '#Function "property_exists\(\)" cannot be used/left in the code#'
- '#Instead of "instanceof/is_a\(\)" use ReflectionProvider service or "\(new ObjectType\(<desired_type\>\)\)\-\>isSuperTypeOf\(<element_type\>\)" for static reflection to work#'
-
message: '#Function "function_exists\(\)" cannot be used/left in the code#'
paths: