refactor: add modules folder to phpstan paths + fix errors

This commit is contained in:
Yassine Doghri 2024-04-28 16:39:01 +00:00
commit bb628f355f
166 changed files with 452 additions and 526 deletions

View file

@ -15,7 +15,8 @@ $routes->add('scheduled-video-clips', 'SchedulerController::generateVideoClips',
// Admin area routes
$routes->group(
config(Admin::class)->gateway,
config('Admin')
->gateway,
[
'namespace' => 'Modules\Admin\Controllers',
],

View file

@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Modules\Admin\Controllers;
use CodeIgniter\HTTP\RedirectResponse;
use Config\App;
use Config\Services;
class AboutController extends BaseController
@ -23,7 +22,7 @@ class AboutController extends BaseController
'version' => CP_VERSION,
'php_version' => PHP_VERSION,
'os' => PHP_OS,
'languages' => implode(', ', config(App::class)->supportedLocales),
'languages' => implode(', ', config('App')->supportedLocales),
];
return view('settings/about', [

View file

@ -13,7 +13,6 @@ namespace Modules\Admin\Controllers;
use App\Models\EpisodeModel;
use App\Models\PodcastModel;
use CodeIgniter\I18n\Time;
use Config\App;
use Modules\Media\Models\MediaModel;
class DashboardController extends BaseController
@ -51,7 +50,7 @@ class DashboardController extends BaseController
->get()
->getResultArray()[0];
$appStorageLimit = config(App::class)
$appStorageLimit = config('App')
->storageLimit;
if ($appStorageLimit === null || $appStorageLimit < 0) {
$storageLimitBytes = disk_total_space('./');
@ -71,7 +70,7 @@ class DashboardController extends BaseController
->id;
}
$bandwidthLimit = config(App::class)
$bandwidthLimit = config('App')
->bandwidthLimit;
$data = [

View file

@ -855,7 +855,7 @@ class EpisodeController extends BaseController
// set podcast is_published_on_hubs to false to trigger websub push
(new PodcastModel())->update($this->episode->podcast->id, [
'is_published_on_hubs' => false,
'is_published_on_hubs' => 0,
]);
$db->transComplete();

View file

@ -32,7 +32,6 @@ use Modules\Analytics\Models\AnalyticsPodcastModel;
use Modules\Analytics\Models\AnalyticsWebsiteByBrowserModel;
use Modules\Analytics\Models\AnalyticsWebsiteByEntryPageModel;
use Modules\Analytics\Models\AnalyticsWebsiteByRefererModel;
use Modules\Auth\Config\AuthGroups;
use Modules\Media\Entities\Image;
use Modules\Media\FileManagers\FileManagerInterface;
use Modules\Media\Models\MediaModel;
@ -244,7 +243,7 @@ class PodcastController extends BaseController
// generate podcast roles and permissions
// before setting current user as podcast admin
config(AuthGroups::class)
config('AuthGroups')
->generatePodcastAuthorizations($newPodcastId);
add_podcast_group(auth()->user(), (int) $newPodcastId, setting('AuthGroups.mostPowerfulPodcastGroup'));

View file

@ -18,10 +18,8 @@ use App\Models\EpisodeModel;
use App\Models\PodcastModel;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse;
use Config\Colors;
use Modules\Media\Entities\Transcript;
use Modules\Media\Models\MediaModel;
use Modules\MediaClipper\Config\MediaClipper;
class VideoClipsController extends BaseController
{
@ -91,7 +89,7 @@ class VideoClipsController extends BaseController
return view('episode/video_clips_list', $data);
}
public function view($videoClipId): string
public function view(string $videoClipId): string
{
$videoClip = (new ClipModel())->getVideoClipById((int) $videoClipId);
@ -146,8 +144,8 @@ class VideoClipsController extends BaseController
'title' => 'required',
'start_time' => 'required|greater_than_equal_to[0]',
'duration' => 'required|greater_than[0]',
'format' => 'required|in_list[' . implode(',', array_keys(config(MediaClipper::class)->formats)) . ']',
'theme' => 'required|in_list[' . implode(',', array_keys(config(Colors::class)->themes)) . ']',
'format' => 'required|in_list[' . implode(',', array_keys(config('MediaClipper')->formats)) . ']',
'theme' => 'required|in_list[' . implode(',', array_keys(config('Colors')->themes)) . ']',
];
if (! $this->validate($rules)) {
@ -160,7 +158,7 @@ class VideoClipsController extends BaseController
$validData = $this->validator->getValidated();
$themeName = $validData['theme'];
$themeColors = config(MediaClipper::class)
$themeColors = config('MediaClipper')
->themes[$themeName];
$theme = [
'name' => $themeName,

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'الرئيسية',
'podcasts' => 'بودكاستات',
'episodes' => 'حلقات',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'roll-istor',
config(Admin::class)
config('Admin')
->gateway => 'Degemer',
'podcasts' => 'podkastoù',
'episodes' => 'rannoù',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'Ruta de navegació',
config(Admin::class)
config('Admin')
->gateway => 'Inici',
'podcasts' => 'podcasts',
'episodes' => 'episodis',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'brødkrumme',
config(Admin::class)
config('Admin')
->gateway => 'Hjem',
'podcasts' => 'podcasts',
'episodes' => 'episoder',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'Pfad',
config(Admin::class)
config('Admin')
->gateway => 'Startseite',
'podcasts' => 'Podcasts',
'episodes' => 'Folgen',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'διαδρομή (Breadcrumb)',
config(Admin::class)
config('Admin')
->gateway => 'Αρχική σελίδα',
'podcasts' => 'podcasts',
'episodes' => 'επεισόδια',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'ruta de navegación',
config(Admin::class)
config('Admin')
->gateway => 'Inicio',
'podcasts' => 'podcasts',
'episodes' => 'episodios',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'Fil dAriane',
config(Admin::class)
config('Admin')
->gateway => 'Accueil',
'podcasts' => 'podcasts',
'episodes' => 'épisodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'fil dAriane',
config(Admin::class)
config('Admin')
->gateway => 'Accueil',
'podcasts' => 'podcasts',
'episodes' => 'épisodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'menú',
config(Admin::class)
config('Admin')
->gateway => 'Inicio',
'podcasts' => 'podcasts',
'episodes' => 'episodios',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodi',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'kruimelpad',
config(Admin::class)
config('Admin')
->gateway => 'Hoofdpagina',
'podcasts' => 'podcasts',
'episodes' => 'afleveringen',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'navigeringslenke',
config(Admin::class)
config('Admin')
->gateway => 'Heim',
'podcasts' => 'podkastar',
'episodes' => 'episodar',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'okruszki',
config(Admin::class)
config('Admin')
->gateway => 'Początek',
'podcasts' => 'podcasty',
'episodes' => 'odcinki',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Início',
'podcasts' => 'podcasts',
'episodes' => 'episódios',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'навигационная цепочка',
config(Admin::class)
config('Admin')
->gateway => 'Главная',
'podcasts' => 'подкасты',
'episodes' => 'выпуски',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'omrvinky',
config(Admin::class)
config('Admin')
->gateway => 'Úvod',
'podcasts' => 'podcasty',
'episodes' => 'časti',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb polja',
config(Admin::class)
config('Admin')
->gateway => 'Početna',
'podcasts' => 'podkasti',
'episodes' => 'epizode',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Hem',
'podcasts' => 'podcasts',
'episodes' => 'avsnitt',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => '面包屑导航',
config(Admin::class)
config('Admin')
->gateway => '主页',
'podcasts' => '播客',
'episodes' => '剧集',

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
use Modules\Admin\Config\Admin;
/**
* @copyright 2020 Ad Aures
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
@ -12,7 +10,7 @@ use Modules\Admin\Config\Admin;
return [
'label' => 'breadcrumb',
config(Admin::class)
config('Admin')
->gateway => 'Home',
'podcasts' => 'podcasts',
'episodes' => 'episodes',

View file

@ -2,7 +2,7 @@
declare(strict_types=1);
use Modules\Analytics\Config\Analytics;
use CodeIgniter\Router\RouteCollection;
/**
* @copyright 2021 Ad Aures
@ -27,17 +27,17 @@ $routes->addPlaceholder(
$routes->group('', [
'namespace' => 'Modules\Analytics\Controllers',
], static function ($routes): void {
$routes->group(config(Analytics::class)->gateway . '/(:num)/(:class)', static function ($routes): void {
$routes->group(config('Analytics')->gateway . '/(:num)/(:class)', static function ($routes): void {
$routes->get('/', 'AnalyticsController::getData/$1/$2', [
'as' => 'analytics-full-data',
'filter' => config(Analytics::class)
'filter' => config('Analytics')
->routeFilters[
'analytics-full-data'
],
]);
$routes->get('(:filter)', 'AnalyticsController::getData/$1/$2/$3', [
'as' => 'analytics-data',
'filter' => config(Analytics::class)
'filter' => config('Analytics')
->routeFilters['analytics-data'],
]);
$routes->get(
@ -45,14 +45,14 @@ $routes->group('', [
'AnalyticsController::getData/$1/$2/$3/$4',
[
'as' => 'analytics-filtered-data',
'filter' => config(Analytics::class)
'filter' => config('Analytics')
->routeFilters[
'analytics-filtered-data'
],
],
);
});
$routes->get(config(Analytics::class)->gateway . '/(:class)/(:filter)', 'AnalyticsController::getData/$1/$2', [
$routes->get(config('Analytics')->gateway . '/(:class)/(:filter)', 'AnalyticsController::getData/$1/$2', [
'as' => 'analytics-data-instance',
]);

View file

@ -31,11 +31,13 @@ class AnalyticsController extends Controller
}
if (! is_numeric($params[0])) {
// @phpstan-ignore-next-line
$this->analyticsModel = model('Analytics' . $params[0] . 'Model');
$this->methodName = 'getData' . $params[1];
return $this->{$method}();
}
// @phpstan-ignore-next-line
$this->analyticsModel = model('Analytics' . $params[1] . 'Model');
$this->methodName = 'getData' . (count($params) >= 3 ? $params[2] : '');

View file

@ -27,7 +27,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsPodcasts extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -26,7 +26,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsPodcastsByCountry extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -25,7 +25,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsPodcastsByEpisode extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -25,7 +25,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsPodcastsByHour extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -28,7 +28,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsPodcastsByPlayer extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -28,7 +28,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsPodcastsByRegion extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -30,7 +30,7 @@ use Opawg\UserAgentsV2Php\UserAgentsRSS;
class AnalyticsPodcastsByService extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -24,7 +24,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsPodcastsBySubscription extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -24,7 +24,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsUnknownUserAgent extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['created_at', 'updated_at'];

View file

@ -25,7 +25,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsWebsiteByBrowser extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -25,7 +25,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsWebsiteByEntryPage extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -25,7 +25,7 @@ use CodeIgniter\Entity\Entity;
class AnalyticsWebsiteByReferer extends Entity
{
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['date', 'created_at', 'updated_at'];

View file

@ -11,7 +11,6 @@ declare(strict_types=1);
use AdAures\Ipcat\IpDb;
use Config\Services;
use GeoIp2\Database\Reader;
use Modules\Analytics\Config\Analytics;
use Opawg\UserAgentsV2Php\UserAgents;
use WhichBrowser\Parser;
@ -41,11 +40,12 @@ if (! function_exists('client_ip')) {
*/
function client_ip(): string
{
if (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
$superglobals = service('superglobals');
if (! empty($superglobals->server('HTTP_X_FORWARDED_FOR'))) {
return $superglobals->server('HTTP_X_FORWARDED_FOR');
}
return $_SERVER['REMOTE_ADDR'];
return $superglobals->server('REMOTE_ADDR');
}
}
@ -109,7 +109,8 @@ if (! function_exists('set_user_session_player')) {
if (! $session->has('player')) {
$playerFound = null;
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$userAgent = service('superglobals')
->server('HTTP_USER_AGENT');
try {
$playerFound = UserAgents::find($userAgent);
@ -175,7 +176,8 @@ if (! function_exists('set_user_session_referer')) {
{
$session = Services::session();
$newreferer = $_SERVER['HTTP_REFERER'] ?? '- Direct -';
$newreferer = service('superglobals')
->server('HTTP_REFERER') ?? '- Direct -';
$newreferer =
parse_url((string) $newreferer, PHP_URL_HOST) ===
parse_url(current_url(false), PHP_URL_HOST)
@ -195,7 +197,8 @@ if (! function_exists('set_user_session_entry_page')) {
{
$session = Services::session();
$entryPage = $_SERVER['REQUEST_URI'];
$entryPage = service('superglobals')
->server('REQUEST_URI');
if (! $session->has('entryPage')) {
$session->set('entryPage', $entryPage);
}
@ -243,10 +246,11 @@ if (! function_exists('podcast_hit')) {
$session->get('player')['bot'] = true;
}
$superglobals = service('superglobals');
//We get the HTTP header field `Range`:
$httpRange = $_SERVER['HTTP_RANGE'] ?? null;
$httpRange = $superglobals->server('HTTP_RANGE') ?? null;
$salt = config(Analytics::class)
$salt = config('Analytics')
->salt;
// We create a sha1 hash for this Salt+Current_Date+IP_Address+User_Agent+Episode_ID (used to count only once multiple episode downloads):
$episodeListenerHashId =
@ -254,11 +258,14 @@ if (! function_exists('podcast_hit')) {
sha1(
$salt . '_' . date(
'Y-m-d'
) . '_' . $clientIp . '_' . $_SERVER['HTTP_USER_AGENT'] . '_' . $episodeId
) . '_' . $clientIp . '_' . $superglobals->server('HTTP_USER_AGENT') . '_' . $episodeId
);
// The cache expires at midnight:
$secondsToMidnight = strtotime('tomorrow') - time();
/** @var int|null $downloadedBytes */
$downloadedBytes = cache($episodeListenerHashId);
if ($downloadedBytes === null) {
// If it was never downloaded that means that zero bytes were downloaded:
$downloadedBytes = 0;
@ -301,13 +308,16 @@ if (! function_exists('podcast_hit')) {
sha1(
$salt . '_' . date(
'Y-m-d'
) . '_' . $clientIp . '_' . $_SERVER['HTTP_USER_AGENT'] . '_' . $podcastId
) . '_' . $clientIp . '_' . $superglobals->server('HTTP_USER_AGENT') . '_' . $podcastId
);
$newListener = 1;
// Has this listener already downloaded an episode today:
/** @var int|null $downloadsByUser */
$downloadsByUser = cache($podcastListenerHashId);
// We add one download
if ($downloadsByUser) {
if ($downloadsByUser === null) {
$newListener = 0;
++$downloadsByUser;
} else {

View file

@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Modules\Analytics\Models;
use App\Entities\Media\BaseMedia;
use CodeIgniter\Model;
use Modules\Analytics\Entities\AnalyticsPodcasts;
use Modules\Media\Models\MediaModel;
@ -263,7 +262,7 @@ class AnalyticsPodcastModel extends Model
/**
* Get total storage
*
* @return BaseMedia[]
* @return AnalyticsPodcasts[]
*/
public function getDataTotalStorageByMonth(): array
{

View file

@ -15,7 +15,7 @@ namespace Modules\Analytics\Models;
use CodeIgniter\Model;
use Modules\Analytics\Entities\AnalyticsUnknownUserAgent;
class AnalyticsUnknownUserAgentModel extends Model
class AnalyticsUnknownUserAgentsModel extends Model
{
/**
* @var string

View file

@ -8,6 +8,9 @@ use Modules\Api\Rest\V1\Filters\ApiFilter;
class Registrar
{
/**
* @return array<string, mixed>
*/
public static function Filters(): array
{
return [

View file

@ -9,7 +9,7 @@ use CodeIgniter\Router\RouteCollection;
/** @var RouteCollection $routes */
$routes->group(
config(RestApi::class)
config('RestApi')
->gateway . 'podcasts',
[
'namespace' => 'Modules\Api\Rest\V1\Controllers',
@ -23,7 +23,7 @@ $routes->group(
);
$routes->group(
config(RestApi::class)
config('RestApi')
->gateway . 'episodes',
[
'namespace' => 'Modules\Api\Rest\V1\Controllers',

View file

@ -5,17 +5,16 @@ declare(strict_types=1);
namespace Modules\Api\Rest\V1\Config;
use CodeIgniter\Config\BaseService;
use Config\Exceptions as ExceptionsConfig;
use Modules\Api\Rest\V1\Core\Exceptions;
use Modules\Api\Rest\V1\Core\RestApiExceptions;
class Services extends BaseService
{
public static function restApiExceptions(bool $getShared = true)
public static function restApiExceptions(bool $getShared = true): RestApiExceptions
{
if ($getShared) {
return static::getSharedInstance('restApiExceptions');
}
return new Exceptions(config(ExceptionsConfig::class), static::request(), static::response());
return new RestApiExceptions(config('Exceptions'));
}
}

View file

@ -8,8 +8,7 @@ use App\Entities\Episode;
use App\Models\EpisodeModel;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\Response;
use Modules\Api\Rest\V1\Config\RestApi;
use CodeIgniter\HTTP\ResponseInterface;
use Modules\Api\Rest\V1\Config\Services;
class EpisodeController extends Controller
@ -21,7 +20,7 @@ class EpisodeController extends Controller
Services::restApiExceptions()->initialize();
}
public function list(): Response
public function list(): ResponseInterface
{
$query = $this->request->getGet('query');
$order = $this->request->getGet('order') ?? 'newest';
@ -46,7 +45,7 @@ class EpisodeController extends Controller
}
$data = $builder->findAll(
(int) ($this->request->getGet('limit') ?? config(RestApi::class)->limit),
(int) ($this->request->getGet('limit') ?? config('RestApi')->limit),
(int) $this->request->getGet('offset')
);
@ -57,7 +56,7 @@ class EpisodeController extends Controller
return $this->respond($data);
}
public function view(int $id): Response
public function view(int $id): ResponseInterface
{
$episode = (new EpisodeModel())->getEpisodeById($id);
@ -65,6 +64,7 @@ class EpisodeController extends Controller
return $this->failNotFound('Episode not found');
}
// @phpstan-ignore-next-line
return $this->respond(static::mapEpisode($episode));
}

View file

@ -6,13 +6,13 @@ namespace Modules\Api\Rest\V1\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
class ExceptionController extends Controller
{
use ResponseTrait;
public function notFound(): Response
public function notFound(): ResponseInterface
{
return $this->failNotFound('Podcast not found');
}

View file

@ -8,7 +8,7 @@ use App\Entities\Podcast;
use App\Models\PodcastModel;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use Modules\Api\Rest\V1\Config\Services;
class PodcastController extends Controller
@ -20,7 +20,7 @@ class PodcastController extends Controller
Services::restApiExceptions()->initialize();
}
public function list(): Response
public function list(): ResponseInterface
{
$data = (new PodcastModel())->findAll();
array_map(static function ($podcast): void {
@ -29,13 +29,14 @@ class PodcastController extends Controller
return $this->respond($data);
}
public function view(int $id): Response
public function view(int $id): ResponseInterface
{
$podcast = (new PodcastModel())->getPodcastById($id);
if (! $podcast instanceof Podcast) {
return $this->failNotFound('Podcast not found');
}
// @phpstan-ignore-next-line
return $this->respond(self::mapPodcast($podcast));
}
@ -50,7 +51,7 @@ class PodcastController extends Controller
$categories = [$podcast->getCategory(), ...$podcast->getOtherCategories()];
foreach ($categories as $category) {
$category->translated = lang('Podcast.category_options.' . $category->code, [], null, false);
$category->translated = lang('Podcast.category_options.' . $category->code);
}
$podcast->categories = $categories;

View file

@ -4,9 +4,10 @@ declare(strict_types=1);
namespace Modules\Api\Rest\V1\Core;
use CodeIgniter\Debug\Exceptions;
use Throwable;
class Exceptions extends \CodeIgniter\Debug\Exceptions
class RestApiExceptions extends Exceptions
{
protected function render(Throwable $exception, int $statusCode): void
{

View file

@ -21,7 +21,7 @@ class ApiFilter implements FilterInterface
public function before(RequestInterface $request, $arguments = null)
{
/** @var RestApi $restApiConfig */
$restApiConfig = config(RestApi::class);
$restApiConfig = config('RestApi');
if (! $restApiConfig->enabled) {
throw PageNotFoundException::forPageNotFound();

View file

@ -6,8 +6,6 @@ namespace Modules\Auth;
use CodeIgniter\Router\RouteCollection;
use CodeIgniter\Shield\Auth as ShieldAuth;
use Modules\Auth\Config\Auth as AuthConfig;
use Modules\Auth\Config\AuthRoutes;
class Auth extends ShieldAuth
{
@ -18,13 +16,15 @@ class Auth extends ShieldAuth
* Usage (in Config/Routes.php):
* - auth()->routes($routes);
* - auth()->routes($routes, ['except' => ['login', 'register']])
*
* @param array{except?:list<string>} $config
*/
public function routes(RouteCollection &$routes, array $config = []): void
{
$authRoutes = config(AuthRoutes::class)
$authRoutes = config('AuthRoutes')
->routes;
$routes->group(config(AuthConfig::class)->gateway, [
$routes->group(config('Auth')->gateway, [
'namespace' => 'Modules\Auth\Controllers',
], static function (RouteCollection $routes) use ($authRoutes, $config): void {
foreach ($authRoutes as $name => $row) {

View file

@ -44,7 +44,12 @@ class RolesDoc extends BaseCommand
{
// loop over all files in path
$defaultFile = glob(ROOTPATH . 'docs/src/getting-started/auth.md');
$localizedFiles = glob(ROOTPATH . 'docs/src/**/getting-started/auth.md') ?? [];
$localizedFiles = glob(ROOTPATH . 'docs/src/**/getting-started/auth.md');
if (! $localizedFiles) {
$localizedFiles = [];
}
$files = array_merge($defaultFile, $localizedFiles);
CLI::write(implode(', ', $files));
@ -74,7 +79,7 @@ class RolesDoc extends BaseCommand
}
}
protected function handleInstanceRoles($authGroups, string $fileContents, string $pattern): string
protected function handleInstanceRoles(AuthGroups $authGroups, string $fileContents, string $pattern): string
{
$instanceMatrix = $authGroups->matrix;
return $this->renderCommentBlock(
@ -88,7 +93,7 @@ class RolesDoc extends BaseCommand
);
}
protected function handleInstancePermissions($authGroups, string $fileContents, string $pattern): string
protected function handleInstancePermissions(AuthGroups $authGroups, string $fileContents, string $pattern): string
{
return $this->renderCommentBlock(
$fileContents,
@ -101,7 +106,7 @@ class RolesDoc extends BaseCommand
);
}
protected function handlePodcastRoles($authGroups, string $fileContents, string $pattern): string
protected function handlePodcastRoles(AuthGroups $authGroups, string $fileContents, string $pattern): string
{
$podcastMatrix = $authGroups->podcastMatrix;
return $this->renderCommentBlock(
@ -115,7 +120,7 @@ class RolesDoc extends BaseCommand
);
}
protected function handlePodcastPermissions($authGroups, string $fileContents, string $pattern): string
protected function handlePodcastPermissions(AuthGroups $authGroups, string $fileContents, string $pattern): string
{
return $this->renderCommentBlock(
$fileContents,
@ -128,6 +133,10 @@ class RolesDoc extends BaseCommand
);
}
/**
* @param array<string> $tableHeading
* @param array<string, string>|array<string, array<string, string>> $data
*/
private function renderCommentBlock(
string $fileContents,
string $pattern,
@ -171,13 +180,9 @@ class RolesDoc extends BaseCommand
return $newFileContents;
}
private function detectLocaleFromPath($fileKey): string
private function detectLocaleFromPath(string $fileKey): string
{
preg_match(
'~docs\/src\/(?:([a-z]{2}(?:-[A-Za-z]{2,})?)\/)getting-started\/auth\.md~',
(string) $fileKey,
$match
);
preg_match('~docs\/src\/(?:([a-z]{2}(?:-[A-Za-z]{2,})?)\/)getting-started\/auth\.md~', $fileKey, $match);
if ($match === []) {
return 'en';

View file

@ -6,8 +6,9 @@ namespace Modules\Auth\Config;
use CodeIgniter\Shield\Authentication\Actions\ActionInterface;
use CodeIgniter\Shield\Authentication\Actions\Email2FA;
use CodeIgniter\Shield\Authentication\AuthenticatorInterface;
use CodeIgniter\Shield\Config\Auth as ShieldAuth;
use Modules\Admin\Config\Admin;
use CodeIgniter\Shield\Entities\User;
use Modules\Auth\Models\UserModel;
class Auth extends ShieldAuth
@ -123,7 +124,7 @@ class Auth extends ShieldAuth
{
parent::__construct();
$adminGateway = config(Admin::class)
$adminGateway = config('Admin')
->gateway;
$this->redirects = [
@ -155,14 +156,16 @@ class Auth extends ShieldAuth
// activate user upon magic-link login as it is done via email
if (! auth()->user()->active) {
/** @var Session $authenticator */
/** @var AuthenticatorInterface $authenticator */
$authenticator = auth('session')
->getAuthenticator();
$user = $authenticator->getUser();
// Set the user active now
$user->activate();
if ($user instanceof User) {
// Set the user active now
$user->activate();
}
}
// prompt user to change their password

View file

@ -200,7 +200,7 @@ class AuthGroups extends ShieldAuthGroups
/**
* Fill groups, permissions and matrix based on
*/
public function __construct($locale = null)
public function __construct()
{
parent::__construct();
@ -228,7 +228,7 @@ class AuthGroups extends ShieldAuthGroups
*/
$podcasts = (new PodcastModel())->findAll();
foreach ($podcasts as $podcast) {
$this->generatePodcastAuthorizations($podcast->id, $locale);
$this->generatePodcastAuthorizations($podcast->id);
}
}

View file

@ -8,6 +8,9 @@ use CodeIgniter\Shield\Config\AuthRoutes as ShieldAuthRoutes;
class AuthRoutes extends ShieldAuthRoutes
{
/**
* @var array<string, array<array<string>>>
*/
public array $routes = [
'register' => [
['get', 'register', 'RegisterController::registerView', 'register'],

View file

@ -31,6 +31,8 @@ class AuthToken extends ShieldAuthToken
* The name of Header that the Authorization token should be found.
* According to the specs, this should be `Authorization`, but rare
* circumstances might need a different header.
*
* @var array<string, string>
*/
public array $authenticatorHeader = [
'tokens' => 'Authorization',

View file

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Modules\Auth\Config;
use CodeIgniter\Router\RouteCollection;
use Modules\Admin\Config\Admin;
/**
* @var RouteCollection $routes
@ -16,7 +15,7 @@ service('auth')
// Admin routes for users and podcast contributors
$routes->group(
config(Admin::class)
config('Admin')
->gateway,
[
'namespace' => 'Modules\Auth\Controllers',

View file

@ -6,7 +6,6 @@ namespace Modules\Auth\Config;
use Config\Services as BaseService;
use Modules\Auth\Auth;
use Modules\Auth\Config\Auth as AuthConfig;
class Services extends BaseService
{
@ -20,7 +19,7 @@ class Services extends BaseService
return self::getSharedInstance('auth');
}
$config = config(AuthConfig::class);
$config = config('Auth');
return new Auth($config);
}

View file

@ -115,6 +115,7 @@ class ContributorController extends BaseController
public function attemptCreate(): RedirectResponse
{
/** @var User $user */
$user = (new UserModel())->find((int) $this->request->getPost('user'));
if (get_podcast_group($user, $this->podcast->id)) {

View file

@ -8,8 +8,7 @@ use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Shield\Controllers\MagicLinkController as ShieldMagicLinkController;
use Modules\Auth\Config\Auth;
use Modules\Auth\Models\UserModel;
use CodeIgniter\Shield\Entities\User;
use Psr\Log\LoggerInterface;
use ViewThemes\Theme;
@ -33,7 +32,7 @@ class MagicLinkController extends ShieldMagicLinkController
public function setPasswordView(): string | RedirectResponse
{
if (! session('magicLogin')) {
return redirect()->to(config(Auth::class)->loginRedirect());
return redirect()->to(config('Auth')->loginRedirect());
}
return view(setting('Auth.views')['magic-link-set-password']);
@ -54,17 +53,16 @@ class MagicLinkController extends ShieldMagicLinkController
$validData = $this->validator->getValidated();
// set new password to user
auth()
->user()
->password = $validData['new_password'];
$user = auth()
->user();
$userModel = new UserModel();
if (! $userModel->update(auth()->user()->id, auth()->user())) {
return redirect()
->back()
->withInput()
->with('errors', $userModel->errors());
if ($user instanceof User) {
// set new password to user
$user->password = $validData['new_password'];
$userModel = auth()
->getProvider();
$userModel->save($user);
}
// remove magic login session to reinstate normal check
@ -73,7 +71,7 @@ class MagicLinkController extends ShieldMagicLinkController
}
// Success!
return redirect()->to(config(Auth::class)->loginRedirect())
return redirect()->to(config('Auth')->loginRedirect())
->with('message', lang('MyAccount.messages.passwordChangeSuccess'));
}
}

View file

@ -11,8 +11,8 @@ declare(strict_types=1);
namespace Modules\Auth\Controllers;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\Shield\Entities\User;
use Modules\Admin\Controllers\BaseController;
use Modules\Auth\Models\UserModel;
class MyAccountController extends BaseController
{
@ -60,17 +60,16 @@ class MyAccountController extends BaseController
->with('error', lang('MyAccount.messages.wrongPasswordError'));
}
// set new password to user
auth()
->user()
->password = $validData['new_password'];
$user = auth()
->user();
$userModel = new UserModel();
if (! $userModel->update(auth()->user()->id, auth()->user())) {
return redirect()
->back()
->withInput()
->with('errors', $userModel->errors());
if ($user instanceof User) {
// set new password to user
$user->password = $validData['new_password'];
$userModel = auth()
->getProvider();
$userModel->save($user);
}
// Success!

View file

@ -16,7 +16,6 @@ use CodeIgniter\I18n\Time;
use CodeIgniter\Shield\Authentication\Authenticators\Session;
use CodeIgniter\Shield\Entities\User;
use CodeIgniter\Shield\Exceptions\ValidationException;
use CodeIgniter\Shield\Models\UserIdentityModel;
use Modules\Admin\Controllers\BaseController;
use Modules\Auth\Models\UserModel;
@ -115,8 +114,7 @@ class UserController extends BaseController
// **** SEND WELCOME LINK FOR FIRST LOGIN ****
/** @var UserIdentityModel $identityModel */
$identityModel = model(UserIdentityModel::class);
$identityModel = model('UserIdentityModel');
// Delete any previous magic-link identities
$identityModel->deleteIdentitiesByType($user, Session::ID_TYPE_MAGIC_LINK);
@ -137,7 +135,7 @@ class UserController extends BaseController
$email->setTo($user->email);
$email->setSubject(lang('Auth.welcomeSubject', [
'siteName' => setting('App.siteName'),
], null, false));
]));
$email->setMessage(view(setting('Auth.views')['welcome-email'], [
'token' => $token,
], [

View file

@ -16,7 +16,7 @@ use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
class UserModel extends ShieldUserModel
{
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = [
'username',

View file

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Modules\Fediverse\Commands;
use CodeIgniter\CLI\BaseCommand;
use Modules\Fediverse\Models\ActivityModel;
class Broadcast extends BaseCommand
{
@ -20,7 +19,7 @@ class Broadcast extends BaseCommand
helper('fediverse');
// retrieve scheduled activities from database
$scheduledActivities = model(ActivityModel::class, false)
$scheduledActivities = model('ActivityModel', false)
->getScheduledActivities();
// Send activity to all followers
@ -43,7 +42,7 @@ class Broadcast extends BaseCommand
}
// set activity post to delivered
model(ActivityModel::class, false)
model('ActivityModel', false)
->update($scheduledActivity->id, [
'status' => 'delivered',
]);

View file

@ -8,6 +8,9 @@ use Modules\Fediverse\Filters\FediverseFilter;
class Registrar
{
/**
* @return array<string, mixed>
*/
public static function Filters(): array
{
return [

View file

@ -11,11 +11,11 @@ declare(strict_types=1);
namespace Modules\Fediverse\Controllers;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
class ActivityPubController extends Controller
{
public function preflight(): Response
public function preflight(): ResponseInterface
{
return $this->response->setHeader('Access-Control-Allow-Origin', '*') // for allowing any domain, insecure
->setHeader('Access-Control-Allow-Headers', '*') // for allowing any headers, insecure

View file

@ -26,7 +26,7 @@ use Modules\Fediverse\Objects\OrderedCollectionPage;
class ActorController extends Controller
{
/**
* @var string[]
* @var list<string>
*/
protected $helpers = ['fediverse'];
@ -36,7 +36,7 @@ class ActorController extends Controller
public function __construct()
{
$this->config = config(Fediverse::class);
$this->config = config('Fediverse');
}
public function _remap(string $method, string ...$params): mixed
@ -89,7 +89,6 @@ class ActorController extends Controller
);
// switch/case on activity type
/** @phpstan-ignore-next-line */
switch ($payload->type) {
case 'Create':
if ($payload->object->type === 'Note') {
@ -192,7 +191,6 @@ class ActorController extends Controller
->setJSON([]);
case 'Undo':
// switch/case on the type of activity to undo
/** @phpstan-ignore-next-line */
switch ($payload->object->type) {
case 'Follow':
// revert side-effect by removing follow from database

View file

@ -17,7 +17,7 @@ use Exception;
class BlockController extends Controller
{
/**
* @var string[]
* @var list<string>
*/
protected $helpers = ['fediverse'];

View file

@ -12,7 +12,6 @@ namespace Modules\Fediverse\Controllers;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\ResponseInterface;
use Modules\Auth\Config\Auth;
class NodeInfo2Controller extends Controller
{
@ -36,7 +35,7 @@ class NodeInfo2Controller extends Controller
'version' => CP_VERSION,
],
'protocols' => ['activitypub'],
'openRegistrations' => config(Auth::class)
'openRegistrations' => config('Auth')
->allowRegistration,
'usage' => [
'users' => [

View file

@ -14,7 +14,6 @@ use CodeIgniter\Controller;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\I18n\Time;
use Modules\Fediverse\Config\Fediverse;
@ -32,7 +31,7 @@ class PostController extends Controller
protected $request;
/**
* @var string[]
* @var list<string>
*/
protected $helpers = ['fediverse'];
@ -45,7 +44,7 @@ class PostController extends Controller
public function __construct()
{
$this->config = config(Fediverse::class);
$this->config = config('Fediverse');
}
public function _remap(string $method, string ...$params): mixed
@ -65,7 +64,7 @@ class PostController extends Controller
return $this->{$method}(...$params);
}
public function index(): Response
public function index(): ResponseInterface
{
$noteObjectClass = $this->config->noteObject;
$noteObject = new $noteObjectClass($this->post);
@ -75,7 +74,7 @@ class PostController extends Controller
->setBody($noteObject->toJSON());
}
public function replies(): Response
public function replies(): ResponseInterface
{
/**
* get post replies
@ -167,7 +166,7 @@ class PostController extends Controller
->getActorById($validData['actor_id']);
model('FavouriteModel', false)
->toggleFavourite($actor, $this->post->id);
->toggleFavourite($actor, $this->post);
return redirect()->back();
}

View file

@ -24,7 +24,7 @@ abstract class AbstractObject
}
/**
* @return array<string, string|int|bool|array>
* @return array<string, mixed>
*/
public function toArray(): array
{

View file

@ -41,7 +41,7 @@ class Activity extends UuidEntity
protected $uuids = ['id', 'post_id'];
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['scheduled_at', 'created_at'];

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace Modules\Fediverse\Entities;
use CodeIgniter\I18n\Time;
use Michalsn\Uuid\UuidEntity;
use Modules\Fediverse\Models\ActorModel;
use Modules\Fediverse\Models\PostModel;
@ -46,7 +47,7 @@ class Notification extends UuidEntity
protected $uuids = ['post_id', 'activity_id'];
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['read_at', 'created_at', 'updated_at'];

View file

@ -65,7 +65,7 @@ class Post extends UuidEntity
protected $uuids = ['id', 'in_reply_to_id', 'reblog_of_id'];
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['published_at', 'created_at'];

View file

@ -44,6 +44,7 @@ class FediverseFilter implements FilterInterface
}
if (in_array('verify-blocks', $params, true)) {
// @phpstan-ignore-next-line
$payload = $request->getJSON();
$actorUri = $payload->actor;

View file

@ -17,7 +17,6 @@ use Modules\Fediverse\ActivityRequest;
use Modules\Fediverse\Core\ObjectType;
use Modules\Fediverse\Entities\Actor;
use Modules\Fediverse\Entities\PreviewCard;
use Modules\Fediverse\Models\ActivityModel;
if (! function_exists('get_webfinger_data')) {
/**
@ -79,7 +78,7 @@ if (! function_exists('accept_follow')) {
$db = db_connect();
$db->transStart();
$activityModel = model(ActivityModel::class, false);
$activityModel = model('ActivityModel', false);
$activityId = $activityModel->newActivity(
'Accept',
$actor->id,
@ -488,7 +487,7 @@ if (! function_exists('linkify')) {
return preg_replace_callback(
'~<(\d+)>~',
static function (array $match) use (&$links): string {
return $links[$match[1] - 1];
return $links[(int) $match[1] - 1];
},
(string) $text,
);

View file

@ -142,9 +142,10 @@ class HttpSignature
$strings[] = sprintf(
'(request-target): %s %s%s',
$this->request->getMethod(),
'/' . $this->request->uri->getPath(),
$this->request->uri->getQuery() !== ''
? '?' . $this->request->uri->getQuery()
'/' . $this->request->getUri()->getPath(),
$this->request->getUri()
->getQuery() !== ''
? '?' . $this->request->getUri()->getQuery()
: '',
);

View file

@ -14,7 +14,6 @@ use CodeIgniter\Database\BaseResult;
use CodeIgniter\I18n\Time;
use DateTimeInterface;
use Michalsn\Uuid\UuidModel;
use Modules\Fediverse\Config\Fediverse;
use Modules\Fediverse\Entities\Activity;
class ActivityModel extends UuidModel
@ -35,17 +34,17 @@ class ActivityModel extends UuidModel
protected $uuidFields = ['id', 'post_id'];
/**
* @var string[]
* @var list<string>
*/
protected $afterInsert = ['notify'];
/**
* @var string[]
* @var list<string>
*/
protected $afterUpdate = ['notify'];
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = [
'id',
@ -78,7 +77,7 @@ class ActivityModel extends UuidModel
public function getActivityById(string $activityId): ?Activity
{
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix . "activity#{$activityId}";
if (! ($found = cache($cacheName))) {
$found = $this->find($activityId);
@ -133,11 +132,12 @@ class ActivityModel extends UuidModel
}
/**
* @param array<string, array<string|int, mixed>> $data
* @param array<mixed> $data
* @return array<string, array<string|int, mixed>>
*/
protected function notify(array $data): array
{
/** @var ?Activity $activity */
$activity = (new self())->find(is_array($data['id']) ? $data['id'][0] : $data['id']);
if (! $activity instanceof Activity) {

View file

@ -12,7 +12,6 @@ namespace Modules\Fediverse\Models;
use CodeIgniter\Events\Events;
use CodeIgniter\Model;
use Modules\Fediverse\Config\Fediverse;
use Modules\Fediverse\Entities\Actor;
class ActorModel extends Model
@ -23,7 +22,7 @@ class ActorModel extends Model
protected $table = 'fediverse_actors';
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = [
'id',
@ -99,7 +98,7 @@ class ActorModel extends Model
{
$hashedActorUri = md5($actorUri);
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix . "actor-{$hashedActorUri}";
if (! ($found = cache($cacheName))) {
$found = $this->where('uri', $actorUri)
@ -118,7 +117,7 @@ class ActorModel extends Model
public function getFollowers(int $actorId): array
{
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix . "actor#{$actorId}_followers";
if (! ($found = cache($cacheName))) {
$found = $this->join('fediverse_follows', 'fediverse_follows.actor_id = id', 'inner')
@ -151,7 +150,7 @@ class ActorModel extends Model
*/
public function getBlockedActors(): array
{
$cacheName = config(Fediverse::class)
$cacheName = config('Fediverse')
->cachePrefix . 'blocked_actors';
if (! ($found = cache($cacheName))) {
$found = $this->where('is_blocked', 1)
@ -166,7 +165,7 @@ class ActorModel extends Model
public function blockActor(int $actorId): void
{
$prefix = config(Fediverse::class)
$prefix = config('Fediverse')
->cachePrefix;
cache()
->delete($prefix . 'blocked_actors');
@ -182,7 +181,7 @@ class ActorModel extends Model
public function unblockActor(int $actorId): void
{
$prefix = config(Fediverse::class)
$prefix = config('Fediverse')
->cachePrefix;
cache()
->delete($prefix . 'blocked_actors');
@ -200,10 +199,11 @@ class ActorModel extends Model
{
helper('fediverse');
$cacheName = config(Fediverse::class)
$cacheName = config('Fediverse')
->cachePrefix . 'blocked_actors';
if (! ($found = cache($cacheName))) {
$result = $this->select('COUNT(*) as total_local_actors')
$result = $this->builder()
->select('COUNT(*) as total_local_actors')
->where('domain', get_current_domain())
->get()
->getResultArray();
@ -221,15 +221,13 @@ class ActorModel extends Model
{
helper('fediverse');
$cacheName = config(Fediverse::class)
$cacheName = config('Fediverse')
->cachePrefix . 'blocked_actors';
if (! ($found = cache($cacheName))) {
$tablePrefix = config(Database::class)
$tablePrefix = config('Database')
->default['DBPrefix'];
$result = $this->select(
'COUNT(DISTINCT `' . $tablePrefix . 'fediverse_actors`.`id`) as `total_active_actors`',
false
)
$result = $this->builder()
->select('COUNT(DISTINCT `' . $tablePrefix . 'fediverse_actors`.`id`) as `total_active_actors`', false)
->join(
$tablePrefix . 'fediverse_posts',
$tablePrefix . 'fediverse_actors.id = ' . $tablePrefix . 'fediverse_posts.actor_id',
@ -300,7 +298,7 @@ class ActorModel extends Model
public function clearCache(Actor $actor): void
{
$cachePrefix = config(Fediverse::class)
$cachePrefix = config('Fediverse')
->cachePrefix;
$hashedActorUri = md5($actor->uri);
$cacheDomain = str_replace(':', '', $actor->domain);

View file

@ -13,7 +13,6 @@ namespace Modules\Fediverse\Models;
use CodeIgniter\Database\BaseResult;
use CodeIgniter\Events\Events;
use CodeIgniter\Model;
use Modules\Fediverse\Config\Fediverse;
use Modules\Fediverse\Entities\BlockedDomain;
class BlockedDomainModel extends Model
@ -29,7 +28,7 @@ class BlockedDomainModel extends Model
protected $primaryKey = 'name';
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = ['name'];
@ -57,7 +56,7 @@ class BlockedDomainModel extends Model
*/
public function getBlockedDomains(): array
{
$cacheName = config(Fediverse::class)
$cacheName = config('Fediverse')
->cachePrefix . 'blocked_domains';
if (! ($found = cache($cacheName))) {
$found = $this->findAll();
@ -73,7 +72,7 @@ class BlockedDomainModel extends Model
{
$hashedDomainName = md5($name);
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix .
"domain#{$hashedDomainName}_isBlocked";
if (! ($found = cache($cacheName))) {
@ -89,7 +88,7 @@ class BlockedDomainModel extends Model
public function blockDomain(string $name): int | bool
{
$hashedDomain = md5($name);
$prefix = config(Fediverse::class)
$prefix = config('Fediverse')
->cachePrefix;
cache()
->delete($prefix . "domain#{$hashedDomain}_isBlocked");
@ -121,7 +120,7 @@ class BlockedDomainModel extends Model
public function unblockDomain(string $name): BaseResult | bool
{
$hashedDomain = md5($name);
$prefix = config(Fediverse::class)
$prefix = config('Fediverse')
->cachePrefix;
cache()
->delete($prefix . "domain#{$hashedDomain}_isBlocked");

View file

@ -31,7 +31,7 @@ class FavouriteModel extends UuidModel
protected $uuidFields = ['post_id'];
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = ['actor_id', 'post_id'];
@ -57,6 +57,7 @@ class FavouriteModel extends UuidModel
]);
model('PostModel', false)
->builder()
->where('id', service('uuid') ->fromString($post->id) ->getBytes())
->increment('favourites_count');
@ -97,6 +98,7 @@ class FavouriteModel extends UuidModel
$this->db->transStart();
model('PostModel', false)
->builder()
->where('id', service('uuid') ->fromString($post->id) ->getBytes())
->decrement('favourites_count');

View file

@ -27,7 +27,7 @@ class FollowModel extends Model
protected $table = 'fediverse_follows';
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = ['actor_id', 'target_actor_id'];
@ -59,6 +59,7 @@ class FollowModel extends Model
// increment followers_count for target actor
model('ActorModel', false)
->builder()
->where('id', $targetActor->id)
->increment('followers_count');
@ -114,6 +115,7 @@ class FollowModel extends Model
// decrement followers_count for target actor
model('ActorModel', false)
->builder()
->where('id', $targetActor->id)
->decrement('followers_count');

View file

@ -41,7 +41,7 @@ class NotificationModel extends UuidModel
protected $uuidFields = ['post_id', 'activity_id'];
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = [
'actor_id',

View file

@ -20,7 +20,6 @@ use Modules\Fediverse\Activities\AnnounceActivity;
use Modules\Fediverse\Activities\CreateActivity;
use Modules\Fediverse\Activities\DeleteActivity;
use Modules\Fediverse\Activities\UndoActivity;
use Modules\Fediverse\Config\Fediverse;
use Modules\Fediverse\Entities\Actor;
use Modules\Fediverse\Entities\Post;
use Modules\Fediverse\Objects\TombstoneObject;
@ -43,7 +42,7 @@ class PostModel extends UuidModel
protected $uuidFields = ['id', 'in_reply_to_id', 'reblog_of_id'];
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = [
'id',
@ -85,7 +84,7 @@ class PostModel extends UuidModel
];
/**
* @var string[]
* @var list<string>
*/
protected $beforeInsert = ['setPostId'];
@ -98,7 +97,7 @@ class PostModel extends UuidModel
{
$hashedPostUri = md5($postUri);
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix . "post-{$hashedPostUri}";
if (! ($found = cache($cacheName))) {
$found = $this->where('uri', $postUri)
@ -119,7 +118,7 @@ class PostModel extends UuidModel
public function getActorPublishedPosts(int $actorId): array
{
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix .
"actor#{$actorId}_published_posts";
if (! ($found = cache($cacheName))) {
@ -146,7 +145,8 @@ class PostModel extends UuidModel
*/
public function getSecondsToNextUnpublishedPosts(int $actorId): int | false
{
$result = $this->select('TIMESTAMPDIFF(SECOND, UTC_TIMESTAMP(), `published_at`) as timestamp_diff')
$result = $this->builder()
->select('TIMESTAMPDIFF(SECOND, UTC_TIMESTAMP(), `published_at`) as timestamp_diff')
->where([
'actor_id' => $actorId,
])
@ -168,7 +168,7 @@ class PostModel extends UuidModel
public function getPostReplies(string $postId, bool $withBlocked = false): array
{
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix .
"post#{$postId}_replies" .
($withBlocked ? '_withBlocked' : '');
@ -200,7 +200,7 @@ class PostModel extends UuidModel
public function getPostReblogs(string $postId): array
{
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix . "post#{$postId}_reblogs";
if (! ($found = cache($cacheName))) {
@ -265,6 +265,7 @@ class PostModel extends UuidModel
if ($post->in_reply_to_id === null) {
// post is not a reply
model('ActorModel', false)
->builder()
->where('id', $post->actor_id)
->increment('posts_count');
@ -277,7 +278,7 @@ class PostModel extends UuidModel
$post->uri = url_to('post', esc($post->actor->username), $newPostId);
$createActivity = new CreateActivity();
$noteObjectClass = config(Fediverse::class)
$noteObjectClass = config('Fediverse')
->noteObject;
$createActivity
->set('actor', $post->actor->uri)
@ -402,6 +403,7 @@ class PostModel extends UuidModel
if ($post->in_reply_to_id === null && $post->reblog_of_id === null) {
model('ActorModel', false)
->builder()
->where('id', $post->actor_id)
->decrement('posts_count');
@ -409,6 +411,7 @@ class PostModel extends UuidModel
} elseif ($post->in_reply_to_id !== null) {
// Post to remove is a reply
model('PostModel', false)
->builder()
->where('id', $this->uuid->fromString($post->in_reply_to_id) ->getBytes())
->decrement('replies_count');
@ -439,6 +442,7 @@ class PostModel extends UuidModel
$postId = $this->addPost($reply, $createPreviewCard, $registerActivity);
model('PostModel', false)
->builder()
->where('id', $this->uuid->fromString($reply->in_reply_to_id) ->getBytes())
->increment('replies_count');
@ -471,10 +475,12 @@ class PostModel extends UuidModel
$reblogId = $this->insert($reblog);
model('ActorModel', false)
->builder()
->where('id', $actor->id)
->increment('posts_count');
model('PostModel', false)
->builder()
->where('id', $this->uuid->fromString($post->id)->getBytes())
->increment('reblogs_count');
@ -514,10 +520,12 @@ class PostModel extends UuidModel
$this->db->transStart();
model('ActorModel', false)
->builder()
->where('id', $reblogPost->actor_id)
->decrement('posts_count');
model('PostModel', false)
->builder()
->where('id', $this->uuid->fromString($reblogPost->reblog_of_id) ->getBytes())
->decrement('reblogs_count');
@ -592,10 +600,11 @@ class PostModel extends UuidModel
{
helper('fediverse');
$cacheName = config(Fediverse::class)
$cacheName = config('Fediverse')
->cachePrefix . 'blocked_actors';
if (! ($found = cache($cacheName))) {
$result = $this->select('COUNT(*) as total_local_posts')
$result = $this->builder()
->select('COUNT(*) as total_local_posts')
->join('fediverse_actors', 'fediverse_actors.id = fediverse_posts.actor_id')
->where('fediverse_actors.domain', get_current_domain())
->where('`published_at` <= UTC_TIMESTAMP()', null, false)
@ -629,7 +638,8 @@ class PostModel extends UuidModel
public function resetReblogsCount(): int | false
{
$postsReblogsCount = $this->select('fediverse_posts.id, COUNT(*) as `replies_count`')
$postsReblogsCount = $this->builder()
->select('fediverse_posts.id, COUNT(*) as `replies_count`')
->join('fediverse_posts as p2', 'fediverse_posts.id = p2.reblog_of_id')
->groupBy('fediverse_posts.id')
->get()
@ -645,7 +655,8 @@ class PostModel extends UuidModel
public function resetRepliesCount(): int | false
{
$postsRepliesCount = $this->select('fediverse_posts.id, COUNT(*) as `replies_count`')
$postsRepliesCount = $this->builder()
->select('fediverse_posts.id, COUNT(*) as `replies_count`')
->join('fediverse_posts as p2', 'fediverse_posts.id = p2.in_reply_to_id')
->groupBy('fediverse_posts.id')
->get()
@ -661,7 +672,7 @@ class PostModel extends UuidModel
public function clearCache(Post $post): void
{
$cachePrefix = config(Fediverse::class)
$cachePrefix = config('Fediverse')
->cachePrefix;
$hashedPostUri = md5($post->uri);

View file

@ -12,7 +12,6 @@ namespace Modules\Fediverse\Models;
use CodeIgniter\Database\BaseResult;
use CodeIgniter\Model;
use Modules\Fediverse\Config\Fediverse;
use Modules\Fediverse\Entities\PreviewCard;
class PreviewCardModel extends Model
@ -23,7 +22,7 @@ class PreviewCardModel extends Model
protected $table = 'fediverse_preview_cards';
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = [
'id',
@ -58,7 +57,7 @@ class PreviewCardModel extends Model
{
$hashedPreviewCardUrl = md5($url);
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix .
"preview_card-{$hashedPreviewCardUrl}";
if (! ($found = cache($cacheName))) {
@ -74,7 +73,7 @@ class PreviewCardModel extends Model
public function getPostPreviewCard(string $postId): ?PreviewCard
{
$cacheName =
config(Fediverse::class)
config('Fediverse')
->cachePrefix . "post#{$postId}_preview_card";
if (! ($found = cache($cacheName))) {
$found = $this->join(
@ -96,7 +95,7 @@ class PreviewCardModel extends Model
{
$hashedPreviewCardUrl = md5($url);
cache()
->delete(config(Fediverse::class) ->cachePrefix . "preview_card-{$hashedPreviewCardUrl}");
->delete(config('Fediverse') ->cachePrefix . "preview_card-{$hashedPreviewCardUrl}");
return $this->delete($id);
}

View file

@ -68,7 +68,7 @@ class WebFinger
throw new Exception('Could not find actor');
}
$this->aliases = [$actor->id];
$this->aliases = [$actor->uri];
$this->links = [
[
'rel' => 'self',

View file

@ -127,7 +127,6 @@ class CreateSuperadmin extends BaseCommand
unset($passwordRules[$key]);
}
/** @var Auth $config */
$config = config('Auth');
// Add `min_length`

View file

@ -10,7 +10,7 @@ use CodeIgniter\Router\RouteCollection;
// Install Wizard routes
$routes->group(
config(Install::class)
config('Install')
->gateway,
[
'namespace' => 'Modules\Install\Controllers',

View file

@ -17,13 +17,12 @@ use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Shield\Entities\User;
use Config\App;
use CodeIgniter\Shield\Exceptions\ValidationException as ShieldValidationException;
use Config\Database;
use Config\Services;
use Dotenv\Dotenv;
use Dotenv\Exception\ValidationException;
use Modules\Auth\Models\UserModel;
use Modules\Install\Config\Install;
use Psr\Log\LoggerInterface;
use Throwable;
use ViewThemes\Theme;
@ -31,7 +30,7 @@ use ViewThemes\Theme;
class InstallController extends Controller
{
/**
* @var string[]
* @var list<string>
*/
protected $helpers = ['form', 'components', 'svg', 'misc', 'setting'];
@ -160,7 +159,7 @@ class InstallController extends Controller
if (! $this->validate($rules)) {
return redirect()
->to((host_url() ?? config(App::class) ->baseURL) . config(Install::class)->gateway)
->to((host_url() ?? config('App') ->baseURL) . config('Install')->gateway)
->withInput()
->with('errors', $this->validator->getErrors());
}
@ -180,7 +179,7 @@ class InstallController extends Controller
helper('text');
// redirect to full install url with new baseUrl input
return redirect()->to(reduce_double_slashes($baseUrl . '/' . config(Install::class)->gateway));
return redirect()->to(reduce_double_slashes($baseUrl . '/' . config('Install')->gateway));
}
public function databaseConfig(): string
@ -308,7 +307,7 @@ class InstallController extends Controller
$userModel = new UserModel();
try {
$userModel->save($user);
} catch (ValidationException) {
} catch (ShieldValidationException) {
return redirect()->back()
->withInput()
->with('errors', $userModel->errors());

View file

@ -6,7 +6,6 @@ namespace Modules\Media\Config;
use CodeIgniter\Config\BaseService;
use Exception;
use Modules\Media\Config\Media as MediaConfig;
use Modules\Media\FileManagers\FileManagerInterface;
/**
@ -27,7 +26,7 @@ class Services extends BaseService
return self::getSharedInstance('file_manager');
}
$config = config(MediaConfig::class);
$config = config('Media');
$fileManagerClass = $config->fileManagers[$config->fileManager];
$fileManager = new $fileManagerClass($config);

View file

@ -36,7 +36,7 @@ class BaseMedia extends Entity
protected File $file;
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['uploaded_at', 'updated_at'];

View file

@ -32,7 +32,11 @@ class Chapters extends BaseMedia
{
parent::setFile($file);
$metadata = lstat((string) $file) ?? [];
$metadata = lstat((string) $file);
if (! $metadata) {
$metadata = [];
}
helper('filesystem');

View file

@ -12,6 +12,7 @@ namespace Modules\Media\Entities;
use CodeIgniter\Files\File;
use Config\Services;
use GdImage;
/**
* @property array $sizes
@ -137,6 +138,7 @@ class Image extends BaseMedia
->withFile($this->attributes['file']->getRealPath())
->resize($size['width'], $size['height']);
/** @var GdImage $resizedImageResource */
$resizedImageResource = $resizedImage->getResource();
// set resolution to 72 by 72 for all sizes

View file

@ -39,7 +39,11 @@ class Transcript extends BaseMedia
{
parent::setFile($file);
$metadata = lstat((string) $file) ?? [];
$metadata = lstat((string) $file);
if (! $metadata) {
$metadata = [];
}
helper('filesystem');

View file

@ -144,6 +144,6 @@ class FS implements FileManagerInterface
$uri = trim($uri, '/');
return config(MediaConfig::class)->storage . '/' . config(MediaConfig::class)->root . '/' . $uri;
return config('Media')->storage . '/' . config('Media')->root . '/' . $uri;
}
}

View file

@ -3,22 +3,21 @@
declare(strict_types=1);
use CodeIgniter\HTTP\URI;
use Modules\Media\Config\Media;
if (! function_exists('media_url')) {
/**
* Returns a media URL as defined by the Media config.
*
* @param array|string $relativePath URI string or array of URI segments
* @param array<string>|string $relativePath URI string or array of URI segments
*/
function media_url($relativePath = '', ?string $scheme = null): string
function media_url(array|string $relativePath = '', ?string $scheme = null): string
{
// Convert array of segments to a string
if (is_array($relativePath)) {
$relativePath = implode('/', $relativePath);
}
$uri = new URI(rtrim(config(Media::class)->baseURL, '/') . '/' . ltrim($relativePath));
$uri = new URI(rtrim(config('Media')->baseURL, '/') . '/' . ltrim($relativePath));
return URI::createURIString(
$scheme ?? $uri->getScheme(),

View file

@ -48,7 +48,7 @@ class MediaModel extends Model
protected $createdField = 'uploaded_at';
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = [
'id',
@ -66,12 +66,12 @@ class MediaModel extends Model
/**
* clear cache before update if by any chance, the podcast name changes, so will the podcast link
*
* @var string[]
* @var list<string>
*/
protected $beforeUpdate = ['clearCache'];
/**
* @var string[]
* @var list<string>
*/
protected $beforeDelete = ['clearCache'];

View file

@ -156,7 +156,7 @@ class TranscriptParser
case VTT_STATE_TEXT:
if (trim($line) === '') {
$state = VTT_STATE_TIME;
//$subs[] = $sub;
// @phpstan-ignore-next-line
} elseif ($subText !== '') {
$subText .= PHP_EOL . $line;
} else {

View file

@ -9,7 +9,6 @@ use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\Files\File;
use CodeIgniter\I18n\Time;
use Exception;
use Modules\Admin\Config\Admin;
use Modules\MediaClipper\VideoClipper;
class Generate extends BaseCommand
@ -25,7 +24,7 @@ class Generate extends BaseCommand
// get number of running clips to prevent from having too much running in parallel
// TODO: get the number of running ffmpeg processes directly from the machine?
$runningVideoClips = (new ClipModel())->getRunningVideoClipsCount();
if ($runningVideoClips >= config(Admin::class)->videoClipWorkers) {
if ($runningVideoClips >= config('Admin')->videoClipWorkers) {
return;
}

View file

@ -15,7 +15,6 @@ use Exception;
use GdImage;
use Modules\Media\Entities\Transcript;
use Modules\Media\FileManagers\FileManagerInterface;
use Modules\MediaClipper\Config\MediaClipper;
/**
* TODO: refactor this by splitting process modules into different classes (image generation, subtitles clip, video
@ -81,9 +80,9 @@ class VideoClipper
) {
$this->duration = $end - $start;
$this->episodeNumbering = $this->episodeNumbering($this->episode->number, $this->episode->season_number);
$this->dimensions = config(MediaClipper::class)
$this->dimensions = config('MediaClipper')
->formats[$format];
$this->colors = config(MediaClipper::class)
$this->colors = config('MediaClipper')
->themes[$theme];
/** @var FileManagerInterface $fileManager */
@ -239,7 +238,7 @@ class VideoClipper
) . ":text='%{pts\:gmtime\:{$this->start}\:%H\\\\\\\\\\:%M\\\\\\\\\\:%S\}':x={$this->dimensions['timestamp']['x']}:y={$this->dimensions['timestamp']['y']}:fontsize={$this->dimensions['timestamp']['fontsize']}:fontcolor=0x{$this->colors['timestampText']}:box=1:boxcolor=0x{$this->colors['timestampBg']}:boxborderw={$this->dimensions['timestamp']['padding']}[v3]",
"color=c=0x{$this->colors['progressbar']}:s={$this->dimensions['width']}x{$this->dimensions['progressbar']['height']}[progressbar]",
"[v3][progressbar]overlay=-w+(w/{$this->duration})*t:0:shortest=1:format=rgb,subtitles={$this->subtitlesClipOutput}:fontsdir=" . config(
MediaClipper::class
'MediaClipper'
)->fontsFolder . ":force_style='Fontname=" . self::FONTS['subtitles'] . ",Alignment=5,Fontsize={$this->dimensions['subtitles']['fontsize']},PrimaryColour=&H{$this->colors['subtitles']}&,BorderStyle=1,Outline=0,Shadow=0,MarginL={$this->dimensions['subtitles']['marginL']},MarginR={$this->dimensions['subtitles']['marginR']},MarginV={$this->dimensions['subtitles']['marginV']}'[outv]",
"[6:v]scale={$this->dimensions['watermark']['width']}:{$this->dimensions['watermark']['height']}[watermark]",
"color=0x{$this->colors['watermarkBg']}:{$this->dimensions['watermark']['width']}x{$this->dimensions['watermark']['height']}[over]",
@ -248,7 +247,7 @@ class VideoClipper
'[watermarked]scale=w=-1:h=-1:out_color_matrix=bt709[outfinal]',
];
$watermark = config(MediaClipper::class)
$watermark = config('MediaClipper')
->watermark;
$videoClipCmd = [
@ -403,7 +402,7 @@ class VideoClipper
);
// Add quotes for subtitles
$quotes = imagecreatefrompng(config(MediaClipper::class)->quotesImage);
$quotes = imagecreatefrompng(config('MediaClipper')->quotesImage);
if (! $quotes) {
return false;
@ -481,7 +480,7 @@ class VideoClipper
private function getFont(string $name): string
{
return config(MediaClipper::class)->fontsFolder . self::FONTS[$name];
return config('MediaClipper')->fontsFolder . self::FONTS[$name];
}
private function generateBackground(int $width, int $height): ?GdImage

View file

@ -5,15 +5,14 @@ declare(strict_types=1);
namespace Modules\PremiumPodcasts\Config;
use CodeIgniter\Router\RouteCollection;
use Modules\Admin\Config\Admin;
$routes->addPlaceholder('platformType', '\bpodcasting|\bsocial|\bfunding');
/** @var RouteCollection $routes */
$routes->addPlaceholder('platformType', '\bpodcasting|\bsocial|\bfunding');
// Admin routes for subscriptions
$routes->group(
config(Admin::class)
config('Admin')
->gateway,
[
'namespace' => 'Modules\Platforms\Controllers',

View file

@ -73,7 +73,7 @@ class PlatformController extends BaseController
as $platformSlug => $podcastPlatform
) {
$podcastPlatformUrl = trim((string) $podcastPlatform['url']);
if ($podcastPlatformUrl === null) {
if ($podcastPlatformUrl === '') {
continue;
}

View file

@ -28,7 +28,7 @@ class PlatformModel extends Model
protected $primaryKey = 'id';
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = ['podcast_id', 'type', 'slug', 'link_url', 'account_id', 'is_visible'];
@ -127,6 +127,8 @@ class PlatformModel extends Model
}
/**
* @param array<array<string, string|int>> $data
*
* @return int|false Number of rows inserted or FALSE on failure
*/
public function savePlatforms(int $podcastId, string $platformType, array $data): int | false

View file

@ -19,7 +19,6 @@ use CodeIgniter\Shield\Entities\User;
use Config\Services;
use Exception;
use League\HTMLToMarkdown\HtmlConverter;
use Modules\Auth\Config\AuthGroups;
use Modules\Auth\Models\UserModel;
use Modules\Platforms\Models\PlatformModel;
use Modules\PodcastImport\Entities\PodcastImportTask;
@ -266,7 +265,7 @@ class PodcastImport extends BaseCommand
// set current user as podcast admin
// 1. create new group
config(AuthGroups::class)
config('AuthGroups')
->generatePodcastAuthorizations($podcast->id);
add_podcast_group($this->user, $podcast->id, 'admin');
@ -332,23 +331,19 @@ class PodcastImport extends BaseCommand
$personGroup = $person->getAttribute('group');
$personRole = $person->getAttribute('role');
$isTaxonomyFound = false;
// set default group and role if taxonomy is not found
$personGroupSlug = 'cast';
$personRoleSlug = 'host';
if (array_key_exists(strtolower((string) $personGroup), ReversedTaxonomy::$taxonomy)) {
$personGroup = ReversedTaxonomy::$taxonomy[strtolower((string) $personGroup)];
$personGroupSlug = $personGroup['slug'];
if (array_key_exists(strtolower((string) $personRole), $personGroup['roles'])) {
$personRoleSlug = $personGroup['roles'][strtolower((string) $personRole)]['slug'];
$isTaxonomyFound = true;
}
}
if (! $isTaxonomyFound) {
// taxonomy was not found, set default group and role
$personGroupSlug = 'cast';
$personRoleSlug = 'host';
}
$podcastPersonModel = new PersonModel();
if (! $podcastPersonModel->addPodcastPerson(
$this->podcast->id,
@ -410,7 +405,7 @@ class PodcastImport extends BaseCommand
'slug' => $platformSlug,
'link_url' => $platform->getAttribute($platformType['account_url_key']),
'account_id' => $platform->getAttribute($platformType['account_id_key']),
'is_visible' => false,
'is_visible' => 0,
];
}
@ -556,23 +551,19 @@ class PodcastImport extends BaseCommand
$personGroup = $person->getAttribute('group');
$personRole = $person->getAttribute('role');
$isTaxonomyFound = false;
// set default group and role if taxonomy is not found
$personGroupSlug = 'cast';
$personRoleSlug = 'host';
if (array_key_exists(strtolower((string) $personGroup), ReversedTaxonomy::$taxonomy)) {
$personGroup = ReversedTaxonomy::$taxonomy[strtolower((string) $personGroup)];
$personGroupSlug = $personGroup['slug'];
if (array_key_exists(strtolower((string) $personRole), $personGroup['roles'])) {
$personRoleSlug = $personGroup['roles'][strtolower((string) $personRole)]['slug'];
$isTaxonomyFound = true;
}
}
if (! $isTaxonomyFound) {
// taxonomy was not found, set default group and role
$personGroupSlug = 'cast';
$personRoleSlug = 'host';
}
$episodePersonModel = new PersonModel();
if (! $episodePersonModel->addEpisodePerson(
$this->podcast->id,

View file

@ -5,13 +5,12 @@ declare(strict_types=1);
namespace Modules\PodcastImport\Config;
use CodeIgniter\Router\RouteCollection;
use Modules\Admin\Config\Admin;
/** @var RouteCollection $routes */
// Admin routes for imports
$routes->group(
config(Admin::class)
config('Admin')
->gateway,
[
'namespace' => 'Modules\PodcastImport\Controllers',

View file

@ -8,6 +8,9 @@ use Modules\PremiumPodcasts\Filters\PodcastUnlockFilter;
class Registrar
{
/**
* @return array<string, mixed>
*/
public static function Filters(): array
{
return [

View file

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Modules\PremiumPodcasts\Config;
use CodeIgniter\Router\RouteCollection;
use Modules\Admin\Config\Admin;
/** @var RouteCollection $routes */
@ -13,7 +12,7 @@ $routes->addPlaceholder('podcastHandle', '[a-zA-Z0-9\_]{1,32}');
// Admin routes for subscriptions
$routes->group(
config(Admin::class)
config('Admin')
->gateway,
[
'namespace' => 'Modules\PremiumPodcasts\Controllers',

View file

@ -20,7 +20,7 @@ class Services extends BaseService
$premiumPodcasts = new PremiumPodcasts();
$subscriptionModel ??= model(SubscriptionModel::class);
$subscriptionModel ??= model('SubscriptionModel');
return $premiumPodcasts
->setSubscriptionModel($subscriptionModel);

View file

@ -38,7 +38,7 @@ class Subscription extends Entity
protected ?Podcast $podcast = null;
/**
* @var string[]
* @var list<string>
*/
protected $dates = ['expires_at', 'created_at', 'updated_at'];

View file

@ -28,7 +28,7 @@ class SubscriptionModel extends Model
protected $primaryKey = 'id';
/**
* @var string[]
* @var list<string>
*/
protected $allowedFields = [
'id',
@ -55,17 +55,17 @@ class SubscriptionModel extends Model
protected $useTimestamps = true;
/**
* @var string[]
* @var list<string>
*/
protected $afterInsert = ['clearCache'];
/**
* @var string[]
* @var list<string>
*/
protected $afterUpdate = ['clearCache'];
/**
* @var string[]
* @var list<string>
*/
protected $beforeDelete = ['clearCache'];
@ -131,8 +131,13 @@ class SubscriptionModel extends Model
*/
protected function clearCache(array $data): array
{
/** @var ?Subscription */
$subscription = (new self())->find(is_array($data['id']) ? $data['id'][0] : $data['id']);
if (! $subscription instanceof Subscription) {
return $data;
}
cache()
->delete("subscription#{$subscription->id}");
cache()

View file

@ -9,7 +9,6 @@ use App\Models\PodcastModel;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\HTTP\CURLRequest;
use Exception;
use Modules\WebSub\Config\WebSub;
class Publish extends BaseCommand
{
@ -56,7 +55,7 @@ class Publish extends BaseCommand
],
];
$hubUrls = config(WebSub::class)
$hubUrls = config('WebSub')
->hubs;
foreach ($podcasts as $podcast) {
@ -78,7 +77,7 @@ class Publish extends BaseCommand
// set podcast feed as having been pushed onto hubs
(new PodcastModel())->update($podcast->id, [
'is_published_on_hubs' => true,
'is_published_on_hubs' => 1,
]);
// set newly published episodes as pushed onto hubs