Skip to content
Snippets Groups Projects
Unverified Commit 6b74a9e9 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

refactor: update code base to php 8 and set phpstan lvl to 6

parent 4a33c50f
No related branches found
No related tags found
No related merge requests found
Showing
with 154 additions and 144 deletions
image: php:7.3-fpm image: php:8.0-fpm
stages: stages:
- quality - quality
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{ {
"files": "*.php", "files": "*.php",
"options": { "options": {
"phpVersion": "7.3", "phpVersion": "7.4",
"singleQuote": true "singleQuote": true
} }
}, },
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# should be used only for development purposes # should be used only for development purposes
#################################################### ####################################################
FROM php:7.3-fpm FROM php:8.0-fpm
LABEL maintainer="Yassine Doghri<yassine@podlibre.org>" LABEL maintainer="Yassine Doghri<yassine@podlibre.org>"
...@@ -37,8 +37,8 @@ RUN apt-get update && apt-get install -y \ ...@@ -37,8 +37,8 @@ RUN apt-get update && apt-get install -y \
zlib1g-dev \ zlib1g-dev \
&& docker-php-ext-install intl && docker-php-ext-install intl
RUN docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ \ RUN docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install gd && docker-php-ext-install gd
RUN pecl install -o -f redis \ RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \ && rm -rf /tmp/pear \
......
...@@ -10,7 +10,7 @@ or shared hosting, you can install it on most PHP-MySQL compatible web servers. ...@@ -10,7 +10,7 @@ or shared hosting, you can install it on most PHP-MySQL compatible web servers.
- [1. Install Wizard](#1-install-wizard) - [1. Install Wizard](#1-install-wizard)
- [1-alt Manual configuration](#1-alt-manual-configuration) - [1-alt Manual configuration](#1-alt-manual-configuration)
- [Web Server Requirements](#web-server-requirements) - [Web Server Requirements](#web-server-requirements)
- [PHP v7.3 or higher](#php-v73-or-higher) - [PHP v8.0 or higher](#php-v73-or-higher)
- [MySQL compatible database](#mysql-compatible-database) - [MySQL compatible database](#mysql-compatible-database)
- [Privileges](#privileges) - [Privileges](#privileges)
- [(Optional) Other recommendations](#optional-other-recommendations) - [(Optional) Other recommendations](#optional-other-recommendations)
...@@ -59,9 +59,9 @@ through the install wizard, you can create and update the `.env` file yourself: ...@@ -59,9 +59,9 @@ through the install wizard, you can create and update the `.env` file yourself:
## Web Server Requirements ## Web Server Requirements
### PHP v7.3 or higher ### PHP v8.0 or higher
PHP version 7.3 or higher is required, with the following extensions installed: PHP version 8.0 or higher is required, with the following extensions installed:
- [intl](https://php.net/manual/en/intl.requirements.php) - [intl](https://php.net/manual/en/intl.requirements.php)
- [libcurl](https://php.net/manual/en/curl.requirements.php) - [libcurl](https://php.net/manual/en/curl.requirements.php)
......
...@@ -17,10 +17,8 @@ class FlatAuthorization extends MythAuthFlatAuthorization ...@@ -17,10 +17,8 @@ class FlatAuthorization extends MythAuthFlatAuthorization
/** /**
* Checks a group to see if they have the specified permission. * Checks a group to see if they have the specified permission.
*
* @param int|string $permission
*/ */
public function groupHasPermission($permission, int $groupId): bool public function groupHasPermission(int|string $permission, int $groupId): bool
{ {
// Get the Permission ID // Get the Permission ID
$permissionId = $this->getPermissionID($permission); $permissionId = $this->getPermissionID($permission);
......
<?php namespace Config; <?php namespace Config;
use App\Libraries\PodcastActor;
use App\Libraries\NoteObject;
use ActivityPub\Config\ActivityPub as ActivityPubBase; use ActivityPub\Config\ActivityPub as ActivityPubBase;
class ActivityPub extends ActivityPubBase class ActivityPub extends ActivityPubBase
...@@ -8,18 +10,32 @@ class ActivityPub extends ActivityPubBase ...@@ -8,18 +10,32 @@ class ActivityPub extends ActivityPubBase
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* ActivityPub Objects * ActivityPub Objects
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* @var string
*/ */
public $actorObject = 'App\Libraries\PodcastActor'; public $actorObject = PodcastActor::class;
public $noteObject = 'App\Libraries\NoteObject'; /**
* @var string
*/
public $noteObject = NoteObject::class;
/** /**
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* Default avatar and cover images * Default avatar and cover images
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* @var string
*/ */
public $defaultAvatarImagePath = 'assets/images/castopod-avatar-default.jpg'; public $defaultAvatarImagePath = 'assets/images/castopod-avatar-default.jpg';
/**
* @var string
*/
public $defaultAvatarImageMimetype = 'image/jpeg'; public $defaultAvatarImageMimetype = 'image/jpeg';
/**
* @var string
*/
public $defaultCoverImagePath = 'assets/images/castopod-cover-default.jpg'; public $defaultCoverImagePath = 'assets/images/castopod-cover-default.jpg';
/**
* @var string
*/
public $defaultCoverImageMimetype = 'image/jpeg'; public $defaultCoverImageMimetype = 'image/jpeg';
} }
...@@ -10,6 +10,7 @@ class Analytics extends AnalyticsBase ...@@ -10,6 +10,7 @@ class Analytics extends AnalyticsBase
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* Route filters options * Route filters options
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* @var array<string, string>
*/ */
public $routeFilters = [ public $routeFilters = [
'analytics-full-data' => 'permission:podcasts-view,podcast-view', 'analytics-full-data' => 'permission:podcasts-view,podcast-view',
......
...@@ -12,25 +12,21 @@ class Database extends Config ...@@ -12,25 +12,21 @@ class Database extends Config
/** /**
* The directory that holds the Migrations * The directory that holds the Migrations
* and Seeds directories. * and Seeds directories.
*
* @var string
*/ */
public $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR; public string $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR;
/** /**
* Lets you choose which connection group to * Lets you choose which connection group to
* use if no other is specified. * use if no other is specified.
*
* @var string
*/ */
public $defaultGroup = 'default'; public string $defaultGroup = 'default';
/** /**
* The default database connection. * The default database connection.
* *
* @var array * @var array<string, string|bool|int|array>
*/ */
public $default = [ public array $default = [
'DSN' => '', 'DSN' => '',
'hostname' => 'localhost', 'hostname' => 'localhost',
'username' => '', 'username' => '',
...@@ -54,9 +50,9 @@ class Database extends Config ...@@ -54,9 +50,9 @@ class Database extends Config
* This database connection is used when * This database connection is used when
* running PHPUnit database tests. * running PHPUnit database tests.
* *
* @var array * @var array<string, string|bool|int|array>
*/ */
public $tests = [ public array $tests = [
'DSN' => '', 'DSN' => '',
'hostname' => '127.0.0.1', 'hostname' => '127.0.0.1',
'username' => '', 'username' => '',
......
...@@ -29,7 +29,7 @@ class Exceptions extends BaseConfig ...@@ -29,7 +29,7 @@ class Exceptions extends BaseConfig
* Any status codes here will NOT be logged if logging is turned on. * Any status codes here will NOT be logged if logging is turned on.
* By default, only 404 (Page Not Found) exceptions are ignored. * By default, only 404 (Page Not Found) exceptions are ignored.
* *
* @var array * @var int[]
*/ */
public $ignoreCodes = [404]; public $ignoreCodes = [404];
......
...@@ -17,7 +17,7 @@ class Filters extends BaseConfig ...@@ -17,7 +17,7 @@ class Filters extends BaseConfig
* Configures aliases for Filter classes to * Configures aliases for Filter classes to
* make reading things nicer and simpler. * make reading things nicer and simpler.
* *
* @var array * @var array<string, string>
*/ */
public $aliases = [ public $aliases = [
'csrf' => CSRF::class, 'csrf' => CSRF::class,
...@@ -33,7 +33,7 @@ class Filters extends BaseConfig ...@@ -33,7 +33,7 @@ class Filters extends BaseConfig
* List of filter aliases that are always * List of filter aliases that are always
* applied before and after every request. * applied before and after every request.
* *
* @var array * @var array<string, string[]>
*/ */
public $globals = [ public $globals = [
'before' => [ 'before' => [
...@@ -53,7 +53,7 @@ class Filters extends BaseConfig ...@@ -53,7 +53,7 @@ class Filters extends BaseConfig
* Example: * Example:
* 'post' => ['csrf', 'throttle'] * 'post' => ['csrf', 'throttle']
* *
* @var array * @var array<string, string[]>
*/ */
public $methods = []; public $methods = [];
...@@ -64,7 +64,7 @@ class Filters extends BaseConfig ...@@ -64,7 +64,7 @@ class Filters extends BaseConfig
* Example: * Example:
* 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']] * 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']]
* *
* @var array * @var array<string, array<string, string[]>>
*/ */
public $filters = []; public $filters = [];
......
...@@ -23,7 +23,10 @@ class Kint extends BaseConfig ...@@ -23,7 +23,10 @@ class Kint extends BaseConfig
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
*/ */
public $plugins; /**
* @var string[]
*/
public $plugins = [];
/** /**
* @var int * @var int
...@@ -60,9 +63,15 @@ class Kint extends BaseConfig ...@@ -60,9 +63,15 @@ class Kint extends BaseConfig
*/ */
public $richSort = Renderer::SORT_FULL; public $richSort = Renderer::SORT_FULL;
public $richObjectPlugins; /**
* @var string[]
*/
public $richObjectPlugins = [];
public $richTabPlugins; /**
* @var string[]
*/
public $richTabPlugins = [];
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
......
...@@ -36,9 +36,9 @@ class Logger extends BaseConfig ...@@ -36,9 +36,9 @@ class Logger extends BaseConfig
* For a live site you'll usually enable Critical or higher (3) to be logged otherwise * For a live site you'll usually enable Critical or higher (3) to be logged otherwise
* your log files will fill up very fast. * your log files will fill up very fast.
* *
* @var integer|array * @var integer|int[]
*/ */
public $threshold = 4; public int|array $threshold = 4;
/** /**
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
...@@ -50,7 +50,7 @@ class Logger extends BaseConfig ...@@ -50,7 +50,7 @@ class Logger extends BaseConfig
* *
* @var string * @var string
*/ */
public $dateFormat = 'Y-m-d H:i:s'; public string $dateFormat = 'Y-m-d H:i:s';
/** /**
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
...@@ -75,9 +75,9 @@ class Logger extends BaseConfig ...@@ -75,9 +75,9 @@ class Logger extends BaseConfig
* Handlers are executed in the order defined in this array, starting with * Handlers are executed in the order defined in this array, starting with
* the handler on top and continuing down. * the handler on top and continuing down.
* *
* @var array * @var array<string, string|int|array<string, string>>
*/ */
public $handlers = [ public array $handlers = [
/* /*
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* File Handler * File Handler
...@@ -125,9 +125,9 @@ class Logger extends BaseConfig ...@@ -125,9 +125,9 @@ class Logger extends BaseConfig
], ],
/** /**
* The ChromeLoggerHandler requires the use of the Chrome web browser * The ChromeLoggerHandler requires the use of the Chrome web browser
* and the ChromeLogger extension. Uncomment this block to use it. * and the ChromeLogger extension. Uncomment this block to use it.
*/ */
// 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [ // 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
// /* // /*
// * The log levels that this handler will handle. // * The log levels that this handler will handle.
......
...@@ -164,13 +164,13 @@ $routes->group( ...@@ -164,13 +164,13 @@ $routes->group(
]); ]);
$routes->group('persons', function ($routes): void { $routes->group('persons', function ($routes): void {
$routes->get('/', 'PodcastPersonController/$1', [ $routes->get('/', 'PodcastPodcastController/$1', [
'as' => 'podcast-person-manage', 'as' => 'podcast-person-manage',
'filter' => 'permission:podcast-edit', 'filter' => 'permission:podcast-edit',
]); ]);
$routes->post( $routes->post(
'/', '/',
'PodcastPersonController::attemptAdd/$1', 'PodcastPodcastController::attemptAdd/$1',
[ [
'filter' => 'permission:podcast-edit', 'filter' => 'permission:podcast-edit',
], ],
...@@ -178,7 +178,7 @@ $routes->group( ...@@ -178,7 +178,7 @@ $routes->group(
$routes->get( $routes->get(
'(:num)/remove', '(:num)/remove',
'PodcastPersonController::remove/$1/$2', 'PodcastPodcastController::remove/$1/$2',
[ [
'as' => 'podcast-person-remove', 'as' => 'podcast-person-remove',
'filter' => 'permission:podcast-edit', 'filter' => 'permission:podcast-edit',
......
...@@ -34,18 +34,12 @@ class Services extends BaseService ...@@ -34,18 +34,12 @@ class Services extends BaseService
/** /**
* The Router class uses a RouteCollection's array of routes, and determines * The Router class uses a RouteCollection's array of routes, and determines
* the correct Controller and Method to execute. * the correct Controller and Method to execute.
*
* @param RouteCollectionInterface|null $routes
* @param Request|null $request
* @param boolean $getShared
*
* @return Router
*/ */
public static function router( public static function router(
RouteCollectionInterface $routes = null, ?RouteCollectionInterface $routes = null,
Request $request = null, ?Request $request = null,
bool $getShared = true bool $getShared = true
) { ): Router {
if ($getShared) { if ($getShared) {
return static::getSharedInstance('router', $routes, $request); return static::getSharedInstance('router', $routes, $request);
} }
...@@ -60,16 +54,11 @@ class Services extends BaseService ...@@ -60,16 +54,11 @@ class Services extends BaseService
* The Negotiate class provides the content negotiation features for * The Negotiate class provides the content negotiation features for
* working the request to determine correct language, encoding, charset, * working the request to determine correct language, encoding, charset,
* and more. * and more.
*
* @param RequestInterface|null $request
* @param boolean $getShared
*
* @return Negotiate
*/ */
public static function negotiator( public static function negotiator(
RequestInterface $request = null, ?RequestInterface $request = null,
bool $getShared = true bool $getShared = true
) { ): Negotiate {
if ($getShared) { if ($getShared) {
return static::getSharedInstance('negotiator', $request); return static::getSharedInstance('negotiator', $request);
} }
...@@ -79,6 +68,9 @@ class Services extends BaseService ...@@ -79,6 +68,9 @@ class Services extends BaseService
return new Negotiate($request); return new Negotiate($request);
} }
/**
* @return mixed
*/
public static function authentication( public static function authentication(
string $lib = 'local', string $lib = 'local',
Model $userModel = null, Model $userModel = null,
...@@ -112,6 +104,9 @@ class Services extends BaseService ...@@ -112,6 +104,9 @@ class Services extends BaseService
return $instance->setUserModel($userModel)->setLoginModel($loginModel); return $instance->setUserModel($userModel)->setLoginModel($loginModel);
} }
/**
* @return mixed
*/
public static function authorization( public static function authorization(
Model $groupModel = null, Model $groupModel = null,
Model $permissionModel = null, Model $permissionModel = null,
...@@ -144,7 +139,7 @@ class Services extends BaseService ...@@ -144,7 +139,7 @@ class Services extends BaseService
return $instance->setUserModel($userModel); return $instance->setUserModel($userModel);
} }
public static function breadcrumb(bool $getShared = true) public static function breadcrumb(bool $getShared = true): Breadcrumb
{ {
if ($getShared) { if ($getShared) {
return self::getSharedInstance('breadcrumb'); return self::getSharedInstance('breadcrumb');
......
...@@ -29,7 +29,7 @@ class View extends BaseView ...@@ -29,7 +29,7 @@ class View extends BaseView
* { title|esc(js) } * { title|esc(js) }
* { created_on|date(Y-m-d)|esc(attr) } * { created_on|date(Y-m-d)|esc(attr) }
* *
* @var array * @var string[]
*/ */
public $filters = []; public $filters = [];
...@@ -38,7 +38,7 @@ class View extends BaseView ...@@ -38,7 +38,7 @@ class View extends BaseView
* by the core Parser by creating aliases that will be replaced with * by the core Parser by creating aliases that will be replaced with
* any callable. Can be single or tag pair. * any callable. Can be single or tag pair.
* *
* @var array * @var string[]
*/ */
public $plugins = []; public $plugins = [];
} }
...@@ -15,9 +15,12 @@ class ActorController extends ActivityPubActorController ...@@ -15,9 +15,12 @@ class ActorController extends ActivityPubActorController
{ {
use AnalyticsTrait; use AnalyticsTrait;
/**
* @var string[]
*/
protected $helpers = ['auth', 'svg', 'components', 'misc']; protected $helpers = ['auth', 'svg', 'components', 'misc'];
public function follow() public function follow(): string
{ {
// Prevent analytics hit when authenticated // Prevent analytics hit when authenticated
if (!can_user_interact()) { if (!can_user_interact()) {
......
...@@ -25,7 +25,7 @@ class BaseController extends Controller ...@@ -25,7 +25,7 @@ class BaseController extends Controller
* class instantiation. These helpers will be available * class instantiation. These helpers will be available
* to all other controllers that extend BaseController. * to all other controllers that extend BaseController.
* *
* @var array * @var string[]
*/ */
protected $helpers = ['auth', 'breadcrumb', 'svg', 'components', 'misc']; protected $helpers = ['auth', 'breadcrumb', 'svg', 'components', 'misc'];
......
...@@ -15,6 +15,7 @@ use Exception; ...@@ -15,6 +15,7 @@ use Exception;
use App\Authorization\GroupModel; use App\Authorization\GroupModel;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use App\Models\UserModel; use App\Models\UserModel;
use CodeIgniter\HTTP\RedirectResponse;
class ContributorController extends BaseController class ContributorController extends BaseController
{ {
...@@ -28,9 +29,9 @@ class ContributorController extends BaseController ...@@ -28,9 +29,9 @@ class ContributorController extends BaseController
*/ */
protected $user; protected $user;
public function _remap($method, ...$params) public function _remap(string $method, string ...$params): mixed
{ {
$this->podcast = (new PodcastModel())->getPodcastById($params[0]); $this->podcast = (new PodcastModel())->getPodcastById((int) $params[0]);
if (count($params) <= 1) { if (count($params) <= 1) {
return $this->$method(); return $this->$method();
...@@ -38,8 +39,8 @@ class ContributorController extends BaseController ...@@ -38,8 +39,8 @@ class ContributorController extends BaseController
if ( if (
$this->user = (new UserModel())->getPodcastContributor( $this->user = (new UserModel())->getPodcastContributor(
$params[1], (int) $params[1],
$params[0], (int) $params[0],
) )
) { ) {
return $this->$method(); return $this->$method();
...@@ -48,7 +49,7 @@ class ContributorController extends BaseController ...@@ -48,7 +49,7 @@ class ContributorController extends BaseController
throw PageNotFoundException::forPageNotFound(); throw PageNotFoundException::forPageNotFound();
} }
public function list() public function list(): string
{ {
$data = [ $data = [
'podcast' => $this->podcast, 'podcast' => $this->podcast,
...@@ -58,7 +59,7 @@ class ContributorController extends BaseController ...@@ -58,7 +59,7 @@ class ContributorController extends BaseController
return view('admin/contributor/list', $data); return view('admin/contributor/list', $data);
} }
public function view() public function view(): string
{ {
$data = [ $data = [
'contributor' => (new UserModel())->getPodcastContributor( 'contributor' => (new UserModel())->getPodcastContributor(
...@@ -74,7 +75,7 @@ class ContributorController extends BaseController ...@@ -74,7 +75,7 @@ class ContributorController extends BaseController
return view('admin/contributor/view', $data); return view('admin/contributor/view', $data);
} }
public function add() public function add(): string
{ {
helper('form'); helper('form');
...@@ -108,7 +109,7 @@ class ContributorController extends BaseController ...@@ -108,7 +109,7 @@ class ContributorController extends BaseController
return view('admin/contributor/add', $data); return view('admin/contributor/add', $data);
} }
public function attemptAdd() public function attemptAdd(): RedirectResponse
{ {
try { try {
(new PodcastModel())->addPodcastContributor( (new PodcastModel())->addPodcastContributor(
...@@ -116,7 +117,7 @@ class ContributorController extends BaseController ...@@ -116,7 +117,7 @@ class ContributorController extends BaseController
$this->podcast->id, $this->podcast->id,
$this->request->getPost('role'), $this->request->getPost('role'),
); );
} catch (Exception $exception) { } catch (Exception) {
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
...@@ -128,7 +129,7 @@ class ContributorController extends BaseController ...@@ -128,7 +129,7 @@ class ContributorController extends BaseController
return redirect()->route('contributor-list', [$this->podcast->id]); return redirect()->route('contributor-list', [$this->podcast->id]);
} }
public function edit() public function edit(): string
{ {
helper('form'); helper('form');
...@@ -159,7 +160,7 @@ class ContributorController extends BaseController ...@@ -159,7 +160,7 @@ class ContributorController extends BaseController
return view('admin/contributor/edit', $data); return view('admin/contributor/edit', $data);
} }
public function attemptEdit() public function attemptEdit(): RedirectResponse
{ {
(new PodcastModel())->updatePodcastContributor( (new PodcastModel())->updatePodcastContributor(
$this->user->id, $this->user->id,
...@@ -170,7 +171,7 @@ class ContributorController extends BaseController ...@@ -170,7 +171,7 @@ class ContributorController extends BaseController
return redirect()->route('contributor-list', [$this->podcast->id]); return redirect()->route('contributor-list', [$this->podcast->id]);
} }
public function remove() public function remove(): RedirectResponse
{ {
if ($this->podcast->created_by === $this->user->id) { if ($this->podcast->created_by === $this->user->id) {
return redirect() return redirect()
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse;
use Config\Database;
use App\Entities\Episode; use App\Entities\Episode;
use App\Entities\Note; use App\Entities\Note;
use App\Entities\Podcast; use App\Entities\Podcast;
...@@ -29,12 +32,14 @@ class EpisodeController extends BaseController ...@@ -29,12 +32,14 @@ class EpisodeController extends BaseController
*/ */
protected $episode; protected $episode;
public function _remap(string $method, ...$params) public function _remap(string $method, string ...$params): mixed
{ {
if ( if (
!($this->podcast = (new PodcastModel())->getPodcastById($params[0])) ($this->podcast = (new PodcastModel())->getPodcastById(
(int) $params[0],
)) === null
) { ) {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); throw PageNotFoundException::forPageNotFound();
} }
if (count($params) > 1) { if (count($params) > 1) {
...@@ -46,7 +51,7 @@ class EpisodeController extends BaseController ...@@ -46,7 +51,7 @@ class EpisodeController extends BaseController
]) ])
->first()) ->first())
) { ) {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); throw PageNotFoundException::forPageNotFound();
} }
unset($params[1]); unset($params[1]);
...@@ -56,7 +61,7 @@ class EpisodeController extends BaseController ...@@ -56,7 +61,7 @@ class EpisodeController extends BaseController
return $this->$method(...$params); return $this->$method(...$params);
} }
public function list() public function list(): string
{ {
$episodes = (new EpisodeModel()) $episodes = (new EpisodeModel())
->where('podcast_id', $this->podcast->id) ->where('podcast_id', $this->podcast->id)
...@@ -74,7 +79,7 @@ class EpisodeController extends BaseController ...@@ -74,7 +79,7 @@ class EpisodeController extends BaseController
return view('admin/episode/list', $data); return view('admin/episode/list', $data);
} }
public function view() public function view(): string
{ {
$data = [ $data = [
'podcast' => $this->podcast, 'podcast' => $this->podcast,
...@@ -88,7 +93,7 @@ class EpisodeController extends BaseController ...@@ -88,7 +93,7 @@ class EpisodeController extends BaseController
return view('admin/episode/view', $data); return view('admin/episode/view', $data);
} }
public function create() public function create(): string
{ {
helper(['form']); helper(['form']);
...@@ -102,7 +107,7 @@ class EpisodeController extends BaseController ...@@ -102,7 +107,7 @@ class EpisodeController extends BaseController
return view('admin/episode/create', $data); return view('admin/episode/create', $data);
} }
public function attemptCreate() public function attemptCreate(): RedirectResponse
{ {
$rules = [ $rules = [
'audio_file' => 'uploaded[audio_file]|ext_in[audio_file,mp3,m4a]', 'audio_file' => 'uploaded[audio_file]|ext_in[audio_file,mp3,m4a]',
...@@ -204,7 +209,7 @@ class EpisodeController extends BaseController ...@@ -204,7 +209,7 @@ class EpisodeController extends BaseController
]); ]);
} }
public function edit() public function edit(): string
{ {
helper(['form']); helper(['form']);
...@@ -220,7 +225,7 @@ class EpisodeController extends BaseController ...@@ -220,7 +225,7 @@ class EpisodeController extends BaseController
return view('admin/episode/edit', $data); return view('admin/episode/edit', $data);
} }
public function attemptEdit() public function attemptEdit(): RedirectResponse
{ {
$rules = [ $rules = [
'audio_file' => 'audio_file' =>
...@@ -282,17 +287,14 @@ class EpisodeController extends BaseController ...@@ -282,17 +287,14 @@ class EpisodeController extends BaseController
} }
} elseif ($transcriptChoice === 'remote-url') { } elseif ($transcriptChoice === 'remote-url') {
if ( if (
$transcriptFileRemoteUrl = $this->request->getPost( ($transcriptFileRemoteUrl = $this->request->getPost(
'transcript_file_remote_url', 'transcript_file_remote_url',
) )) &&
(($transcriptFile = $this->episode->transcript_file) &&
$transcriptFile !== null)
) { ) {
if ( unlink($transcriptFile);
($transcriptFile = $this->episode->transcript_file) && $this->episode->transcript_file_path = null;
$transcriptFile !== null
) {
unlink($transcriptFile);
$this->episode->transcript_file_path = null;
}
} }
$this->episode->transcript_file_remote_url = $transcriptFileRemoteUrl; $this->episode->transcript_file_remote_url = $transcriptFileRemoteUrl;
} }
...@@ -306,17 +308,14 @@ class EpisodeController extends BaseController ...@@ -306,17 +308,14 @@ class EpisodeController extends BaseController
} }
} elseif ($chaptersChoice === 'remote-url') { } elseif ($chaptersChoice === 'remote-url') {
if ( if (
$chaptersFileRemoteUrl = $this->request->getPost( ($chaptersFileRemoteUrl = $this->request->getPost(
'chapters_file_remote_url', 'chapters_file_remote_url',
) )) &&
(($chaptersFile = $this->episode->chapters_file) &&
$chaptersFile !== null)
) { ) {
if ( unlink($chaptersFile);
($chaptersFile = $this->episode->chapters_file) && $this->episode->chapters_file_path = null;
$chaptersFile !== null
) {
unlink($chaptersFile);
$this->episode->chapters_file_path = null;
}
} }
$this->episode->chapters_file_remote_url = $chaptersFileRemoteUrl; $this->episode->chapters_file_remote_url = $chaptersFileRemoteUrl;
} }
...@@ -351,7 +350,7 @@ class EpisodeController extends BaseController ...@@ -351,7 +350,7 @@ class EpisodeController extends BaseController
]); ]);
} }
public function transcriptDelete() public function transcriptDelete(): RedirectResponse
{ {
unlink($this->episode->transcript_file); unlink($this->episode->transcript_file);
$this->episode->transcript_file_path = null; $this->episode->transcript_file_path = null;
...@@ -368,7 +367,7 @@ class EpisodeController extends BaseController ...@@ -368,7 +367,7 @@ class EpisodeController extends BaseController
return redirect()->back(); return redirect()->back();
} }
public function chaptersDelete() public function chaptersDelete(): RedirectResponse
{ {
unlink($this->episode->chapters_file); unlink($this->episode->chapters_file);
$this->episode->chapters_file_path = null; $this->episode->chapters_file_path = null;
...@@ -385,7 +384,7 @@ class EpisodeController extends BaseController ...@@ -385,7 +384,7 @@ class EpisodeController extends BaseController
return redirect()->back(); return redirect()->back();
} }
public function publish() public function publish(): string
{ {
if ($this->episode->publication_status === 'not_published') { if ($this->episode->publication_status === 'not_published') {
helper(['form']); helper(['form']);
...@@ -400,12 +399,12 @@ class EpisodeController extends BaseController ...@@ -400,12 +399,12 @@ class EpisodeController extends BaseController
1 => $this->episode->title, 1 => $this->episode->title,
]); ]);
return view('admin/episode/publish', $data); return view('admin/episode/publish', $data);
} else {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
} }
throw PageNotFoundException::forPageNotFound();
} }
public function attemptPublish() public function attemptPublish(): RedirectResponse
{ {
$rules = [ $rules = [
'publication_method' => 'required', 'publication_method' => 'required',
...@@ -420,7 +419,7 @@ class EpisodeController extends BaseController ...@@ -420,7 +419,7 @@ class EpisodeController extends BaseController
->with('errors', $this->validator->getErrors()); ->with('errors', $this->validator->getErrors());
} }
$db = \Config\Database::connect(); $db = Database::connect();
$db->transStart(); $db->transStart();
$newNote = new Note([ $newNote = new Note([
...@@ -482,7 +481,7 @@ class EpisodeController extends BaseController ...@@ -482,7 +481,7 @@ class EpisodeController extends BaseController
]); ]);
} }
public function publishEdit() public function publishEdit(): string
{ {
if ($this->episode->publication_status === 'scheduled') { if ($this->episode->publication_status === 'scheduled') {
helper(['form']); helper(['form']);
...@@ -503,12 +502,11 @@ class EpisodeController extends BaseController ...@@ -503,12 +502,11 @@ class EpisodeController extends BaseController
1 => $this->episode->title, 1 => $this->episode->title,
]); ]);
return view('admin/episode/publish_edit', $data); return view('admin/episode/publish_edit', $data);
} else {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
} }
throw PageNotFoundException::forPageNotFound();
} }
public function attemptPublishEdit() public function attemptPublishEdit(): RedirectResponse
{ {
$rules = [ $rules = [
'note_id' => 'required', 'note_id' => 'required',
...@@ -524,7 +522,7 @@ class EpisodeController extends BaseController ...@@ -524,7 +522,7 @@ class EpisodeController extends BaseController
->with('errors', $this->validator->getErrors()); ->with('errors', $this->validator->getErrors());
} }
$db = \Config\Database::connect(); $db = Database::connect();
$db->transStart(); $db->transStart();
$note = (new NoteModel())->getNoteById( $note = (new NoteModel())->getNoteById(
...@@ -584,7 +582,7 @@ class EpisodeController extends BaseController ...@@ -584,7 +582,7 @@ class EpisodeController extends BaseController
]); ]);
} }
public function unpublish() public function unpublish(): string
{ {
if ($this->episode->publication_status === 'published') { if ($this->episode->publication_status === 'published') {
helper(['form']); helper(['form']);
...@@ -599,12 +597,12 @@ class EpisodeController extends BaseController ...@@ -599,12 +597,12 @@ class EpisodeController extends BaseController
1 => $this->episode->title, 1 => $this->episode->title,
]); ]);
return view('admin/episode/unpublish', $data); return view('admin/episode/unpublish', $data);
} else {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
} }
throw PageNotFoundException::forPageNotFound();
} }
public function attemptUnpublish() public function attemptUnpublish(): RedirectResponse
{ {
$rules = [ $rules = [
'understand' => 'required', 'understand' => 'required',
...@@ -617,7 +615,7 @@ class EpisodeController extends BaseController ...@@ -617,7 +615,7 @@ class EpisodeController extends BaseController
->with('errors', $this->validator->getErrors()); ->with('errors', $this->validator->getErrors());
} }
$db = \Config\Database::connect(); $db = Database::connect();
$db->transStart(); $db->transStart();
...@@ -650,14 +648,14 @@ class EpisodeController extends BaseController ...@@ -650,14 +648,14 @@ class EpisodeController extends BaseController
]); ]);
} }
public function delete() public function delete(): RedirectResponse
{ {
(new EpisodeModel())->delete($this->episode->id); (new EpisodeModel())->delete($this->episode->id);
return redirect()->route('episode-list', [$this->podcast->id]); return redirect()->route('episode-list', [$this->podcast->id]);
} }
public function soundbitesEdit() public function soundbitesEdit(): string
{ {
helper(['form']); helper(['form']);
...@@ -673,7 +671,7 @@ class EpisodeController extends BaseController ...@@ -673,7 +671,7 @@ class EpisodeController extends BaseController
return view('admin/episode/soundbites', $data); return view('admin/episode/soundbites', $data);
} }
public function soundbitesAttemptEdit() public function soundbitesAttemptEdit(): RedirectResponse
{ {
$soundbites_array = $this->request->getPost('soundbites_array'); $soundbites_array = $this->request->getPost('soundbites_array');
$rules = [ $rules = [
...@@ -682,7 +680,7 @@ class EpisodeController extends BaseController ...@@ -682,7 +680,7 @@ class EpisodeController extends BaseController
'soundbites_array.0.duration' => 'soundbites_array.0.duration' =>
'permit_empty|required_with[soundbites_array.0.start_time]|decimal|greater_than_equal_to[0]', 'permit_empty|required_with[soundbites_array.0.start_time]|decimal|greater_than_equal_to[0]',
]; ];
foreach ($soundbites_array as $soundbite_id => $soundbite) { foreach (array_keys($soundbites_array) as $soundbite_id) {
$rules += [ $rules += [
"soundbites_array.{$soundbite_id}.start_time" => 'required|decimal|greater_than_equal_to[0]', "soundbites_array.{$soundbite_id}.start_time" => 'required|decimal|greater_than_equal_to[0]',
"soundbites_array.{$soundbite_id}.duration" => 'required|decimal|greater_than_equal_to[0]', "soundbites_array.{$soundbite_id}.duration" => 'required|decimal|greater_than_equal_to[0]',
...@@ -728,7 +726,7 @@ class EpisodeController extends BaseController ...@@ -728,7 +726,7 @@ class EpisodeController extends BaseController
]); ]);
} }
public function soundbiteDelete($soundbiteId) public function soundbiteDelete(int $soundbiteId): RedirectResponse
{ {
(new SoundbiteModel())->deleteSoundbite( (new SoundbiteModel())->deleteSoundbite(
$this->podcast->id, $this->podcast->id,
...@@ -742,7 +740,7 @@ class EpisodeController extends BaseController ...@@ -742,7 +740,7 @@ class EpisodeController extends BaseController
]); ]);
} }
public function embeddablePlayer() public function embeddablePlayer(): string
{ {
helper(['form']); helper(['form']);
......
...@@ -8,27 +8,20 @@ ...@@ -8,27 +8,20 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use CodeIgniter\HTTP\RedirectResponse;
use App\Entities\Podcast; use App\Entities\Podcast;
use App\Entities\Episode; use App\Entities\Episode;
use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Exceptions\PageNotFoundException;
use App\Models\EpisodePersonModel;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use App\Models\EpisodeModel; use App\Models\EpisodeModel;
use App\Models\PersonModel; use App\Models\PersonModel;
class EpisodePersonController extends BaseController class EpisodePersonController extends BaseController
{ {
/** protected Podcast $podcast;
* @var Podcast protected Episode $episode;
*/
protected $podcast;
/** public function _remap(string $method, string ...$params): mixed
* @var Episode
*/
protected $episode;
public function _remap($method, ...$params)
{ {
if (count($params) <= 2) { if (count($params) <= 2) {
throw PageNotFoundException::forPageNotFound(); throw PageNotFoundException::forPageNotFound();
...@@ -36,7 +29,7 @@ class EpisodePersonController extends BaseController ...@@ -36,7 +29,7 @@ class EpisodePersonController extends BaseController
if ( if (
($this->podcast = (new PodcastModel())->getPodcastById( ($this->podcast = (new PodcastModel())->getPodcastById(
$params[0], (int) $params[0],
)) && )) &&
($this->episode = (new EpisodeModel()) ($this->episode = (new EpisodeModel())
->where([ ->where([
...@@ -54,14 +47,14 @@ class EpisodePersonController extends BaseController ...@@ -54,14 +47,14 @@ class EpisodePersonController extends BaseController
throw PageNotFoundException::forPageNotFound(); throw PageNotFoundException::forPageNotFound();
} }
public function index() public function index(): string
{ {
helper('form'); helper('form');
$data = [ $data = [
'episode' => $this->episode, 'episode' => $this->episode,
'podcast' => $this->podcast, 'podcast' => $this->podcast,
'episodePersons' => (new EpisodePersonModel())->getEpisodePersons( 'episodePersons' => (new PersonModel())->getEpisodePersons(
$this->podcast->id, $this->podcast->id,
$this->episode->id, $this->episode->id,
), ),
...@@ -75,7 +68,7 @@ class EpisodePersonController extends BaseController ...@@ -75,7 +68,7 @@ class EpisodePersonController extends BaseController
return view('admin/episode/person', $data); return view('admin/episode/person', $data);
} }
public function attemptAdd() public function attemptAdd(): RedirectResponse
{ {
$rules = [ $rules = [
'person' => 'required', 'person' => 'required',
...@@ -88,7 +81,7 @@ class EpisodePersonController extends BaseController ...@@ -88,7 +81,7 @@ class EpisodePersonController extends BaseController
->with('errors', $this->validator->getErrors()); ->with('errors', $this->validator->getErrors());
} }
(new EpisodePersonModel())->addEpisodePersons( (new PersonModel())->addEpisodePersons(
$this->podcast->id, $this->podcast->id,
$this->episode->id, $this->episode->id,
$this->request->getPost('person'), $this->request->getPost('person'),
...@@ -98,9 +91,9 @@ class EpisodePersonController extends BaseController ...@@ -98,9 +91,9 @@ class EpisodePersonController extends BaseController
return redirect()->back(); return redirect()->back();
} }
public function remove($episodePersonId) public function remove(int $episodePersonId): RedirectResponse
{ {
(new EpisodePersonModel())->removeEpisodePersons( (new PersonModel())->removeEpisodePersons(
$this->podcast->id, $this->podcast->id,
$this->episode->id, $this->episode->id,
$episodePersonId, $episodePersonId,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment