From fb3593f8287284ec62d67a404b9032b688847d88 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Tue, 18 May 2021 17:16:36 +0000 Subject: [PATCH] refactor: remove all empty declarations + add missing type declarations update composer dependencies --- app/Config/ActivityPub.php | 29 +- app/Config/Analytics.php | 3 +- app/Config/App.php | 115 ++--- app/Config/Cache.php | 23 +- app/Config/ContentSecurityPolicy.php | 38 +- app/Config/Cookie.php | 25 +- app/Config/Database.php | 3 +- app/Config/DocTypes.php | 2 +- app/Config/Email.php | 78 ++-- app/Config/Encryption.php | 12 +- app/Config/Exceptions.php | 8 +- app/Config/Filters.php | 8 +- app/Config/Format.php | 6 +- app/Config/Generators.php | 2 +- app/Config/Honeypot.php | 15 +- app/Config/Images.php | 58 +-- app/Config/Kint.php | 57 +-- app/Config/Logger.php | 16 +- app/Config/Migrations.php | 9 +- app/Config/Pager.php | 5 +- app/Config/Paths.php | 15 +- app/Config/Security.php | 20 +- app/Config/Toolbar.php | 11 +- app/Config/UserAgents.php | 8 +- app/Config/Validation.php | 4 +- .../Admin/ContributorController.php | 11 +- app/Controllers/Admin/EpisodeController.php | 11 +- app/Controllers/Admin/PageController.php | 5 +- app/Controllers/Admin/PersonController.php | 5 +- app/Controllers/Admin/PodcastController.php | 2 +- .../Admin/PodcastImportController.php | 30 +- .../Admin/PodcastPersonController.php | 2 +- .../Admin/PodcastPlatformController.php | 2 +- app/Controllers/Admin/UserController.php | 5 +- app/Controllers/EpisodeController.php | 10 +- app/Controllers/NoteController.php | 12 +- app/Controllers/PageController.php | 5 +- app/Controllers/PodcastController.php | 2 +- ...2020-12-25-140000_add_episodes_persons.php | 2 +- app/Database/Seeds/AuthSeeder.php | 4 +- .../Seeds/FakePodcastsAnalyticsSeeder.php | 4 +- .../Seeds/FakeWebsiteAnalyticsSeeder.php | 6 +- app/Entities/Category.php | 2 +- app/Entities/Episode.php | 24 +- app/Entities/Location.php | 8 +- app/Entities/Person.php | 12 +- app/Entities/Podcast.php | 68 +-- app/Filters/PermissionFilter.php | 2 +- app/Helpers/components_helper.php | 5 +- app/Helpers/id3_helper.php | 6 +- app/Helpers/misc_helper.php | 9 +- app/Helpers/rss_helper.php | 107 +++-- app/Helpers/url_helper.php | 2 +- .../ActivityPub/Activities/AcceptActivity.php | 5 +- .../Activities/AnnounceActivity.php | 5 +- .../ActivityPub/Activities/CreateActivity.php | 5 +- .../ActivityPub/Activities/DeleteActivity.php | 5 +- .../ActivityPub/Activities/FollowActivity.php | 5 +- .../ActivityPub/Activities/LikeActivity.php | 5 +- .../ActivityPub/Activities/UndoActivity.php | 5 +- app/Libraries/ActivityPub/ActivityRequest.php | 19 +- .../ActivityPub/Config/ActivityPub.php | 29 +- .../Controllers/ActorController.php | 13 +- .../Controllers/NoteController.php | 11 +- app/Libraries/ActivityPub/Core/Activity.php | 17 +- app/Libraries/ActivityPub/Core/ObjectType.php | 30 +- .../ActivityPub/Entities/Activity.php | 29 +- app/Libraries/ActivityPub/Entities/Actor.php | 25 +- app/Libraries/ActivityPub/Entities/Note.php | 84 ++-- .../ActivityPub/Filters/ActivityPubFilter.php | 5 +- .../Helpers/activitypub_helper.php | 1 + .../ActivityPub/Models/NoteModel.php | 2 +- .../ActivityPub/Objects/ActorObject.php | 63 +-- .../ActivityPub/Objects/NoteObject.php | 23 +- .../Objects/OrderedCollectionObject.php | 29 +- .../Objects/OrderedCollectionPage.php | 23 +- .../ActivityPub/Objects/TombstoneObject.php | 5 +- app/Libraries/ActivityPub/WebFinger.php | 27 +- app/Libraries/Analytics/AnalyticsTrait.php | 9 +- app/Libraries/Analytics/Config/Analytics.php | 6 +- .../Controllers/AnalyticsController.php | 25 +- .../EpisodeAnalyticsController.php | 8 +- .../Controllers/EpisodeController.php | 11 +- .../Analytics/Helpers/analytics_helper.php | 9 +- app/Libraries/Breadcrumb.php | 2 +- app/Libraries/PodcastActor.php | 5 +- app/Libraries/Router.php | 7 +- app/Models/CategoryModel.php | 8 +- app/Models/PersonModel.php | 6 +- app/Models/PodcastModel.php | 69 ++- app/Views/admin/episode/soundbites.php | 1 - app/Views/admin/person/list.php | 2 +- app/Views/admin/podcast/list.php | 2 +- app/Views/credits.php | 2 +- app/Views/errors/html/error_404.php | 2 +- app/Views/errors/html/error_exception.php | 14 +- app/Views/install/instance_config.php | 2 +- app/Views/podcast/episode_authenticated.php | 31 +- composer.json | 3 +- composer.lock | 399 +++++++++--------- phpstan.neon | 10 +- tests/_support/SessionTestCase.php | 2 +- tests/unit/HealthTest.php | 4 +- 103 files changed, 750 insertions(+), 1292 deletions(-) diff --git a/app/Config/ActivityPub.php b/app/Config/ActivityPub.php index 97606454..50a9bddf 100644 --- a/app/Config/ActivityPub.php +++ b/app/Config/ActivityPub.php @@ -10,32 +10,21 @@ class ActivityPub extends ActivityPubBase * -------------------------------------------------------------------- * ActivityPub Objects * -------------------------------------------------------------------- - * @var string */ - public $actorObject = PodcastActor::class; - /** - * @var string - */ - public $noteObject = NoteObject::class; + public string $actorObject = PodcastActor::class; + + public string $noteObject = NoteObject::class; /** * -------------------------------------------------------------------- * Default avatar and cover images * -------------------------------------------------------------------- - * @var string */ - public $defaultAvatarImagePath = 'assets/images/castopod-avatar-default.jpg'; - /** - * @var string - */ - public $defaultAvatarImageMimetype = 'image/jpeg'; + public string $defaultAvatarImagePath = 'assets/images/castopod-avatar-default.jpg'; - /** - * @var string - */ - public $defaultCoverImagePath = 'assets/images/castopod-cover-default.jpg'; - /** - * @var string - */ - public $defaultCoverImageMimetype = 'image/jpeg'; + public string $defaultAvatarImageMimetype = 'image/jpeg'; + + public string $defaultCoverImagePath = 'assets/images/castopod-cover-default.jpg'; + + public string $defaultCoverImageMimetype = 'image/jpeg'; } diff --git a/app/Config/Analytics.php b/app/Config/Analytics.php index 66fe6945..cf79bf63 100644 --- a/app/Config/Analytics.php +++ b/app/Config/Analytics.php @@ -10,9 +10,8 @@ class Analytics extends AnalyticsBase * -------------------------------------------------------------------- * Route filters options * -------------------------------------------------------------------- - * @var array */ - public $routeFilters = [ + public array $routeFilters = [ 'analytics-full-data' => 'permission:podcasts-view,podcast-view', 'analytics-data' => 'permission:podcasts-view,podcast-view', 'analytics-filtered-data' => 'permission:podcasts-view,podcast-view', diff --git a/app/Config/App.php b/app/Config/App.php index 61096007..29f17116 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -22,9 +22,8 @@ class App extends BaseConfig * explicitly and never rely on auto-guessing, especially in production * environments. * - * @var string */ - public $baseURL = 'http://localhost:8080/'; + public string $baseURL = 'http://localhost:8080/'; /** * -------------------------------------------------------------------------- @@ -36,9 +35,8 @@ class App extends BaseConfig * * http://cdn.example.com/ * - * @var string */ - public $mediaBaseURL = 'http://127.0.0.2:8080/'; + public string $mediaBaseURL = 'http://127.0.0.2:8080/'; /** * -------------------------------------------------------------------------- @@ -49,9 +47,8 @@ class App extends BaseConfig * something else. If you are using mod_rewrite to remove the page set this * variable so that it is blank. * - * @var string */ - public $indexPage = ''; + public string $indexPage = ''; /** * -------------------------------------------------------------------------- @@ -68,9 +65,8 @@ class App extends BaseConfig * * WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded! * - * @var string */ - public $uriProtocol = 'REQUEST_URI'; + public string $uriProtocol = 'REQUEST_URI'; /** * -------------------------------------------------------------------------- @@ -82,9 +78,8 @@ class App extends BaseConfig * strings (like currency markers, numbers, etc), that your program * should run under for this request. * - * @var string */ - public $defaultLocale = 'en'; + public string $defaultLocale = 'en'; /** * -------------------------------------------------------------------------- @@ -95,10 +90,8 @@ class App extends BaseConfig * language to use based on the value of the Accept-Language header. * * If false, no automatic detection will be performed. - * - * @var boolean */ - public $negotiateLocale = true; + public bool $negotiateLocale = true; /** * -------------------------------------------------------------------------- @@ -111,7 +104,7 @@ class App extends BaseConfig * * @var string[] */ - public $supportedLocales = ['en', 'fr']; + public array $supportedLocales = ['en', 'fr']; /** * -------------------------------------------------------------------------- @@ -121,9 +114,8 @@ class App extends BaseConfig * The default timezone that will be used in your application to display * dates with the date helper, and can be retrieved through app_timezone() * - * @var string */ - public $appTimezone = 'UTC'; + public string $appTimezone = 'UTC'; /** * -------------------------------------------------------------------------- @@ -135,9 +127,8 @@ class App extends BaseConfig * * @see http://php.net/htmlspecialchars for a list of supported charsets. * - * @var string */ - public $charset = 'UTF-8'; + public string $charset = 'UTF-8'; /** * -------------------------------------------------------------------------- @@ -149,9 +140,8 @@ class App extends BaseConfig * secure, the user will be redirected to a secure version of the page * and the HTTP Strict Transport Security header will be set. * - * @var boolean */ - public $forceGlobalSecureRequests = true; + public bool $forceGlobalSecureRequests = true; /** * -------------------------------------------------------------------------- @@ -164,9 +154,8 @@ class App extends BaseConfig * - `CodeIgniter\Session\Handlers\MemcachedHandler` * - `CodeIgniter\Session\Handlers\RedisHandler` * - * @var string */ - public $sessionDriver = FileHandler::class; + public string $sessionDriver = FileHandler::class; /** * -------------------------------------------------------------------------- @@ -175,9 +164,8 @@ class App extends BaseConfig * * The session cookie name, must contain only [0-9a-z_-] characters * - * @var string */ - public $sessionCookieName = 'ci_session'; + public string $sessionCookieName = 'ci_session'; /** * -------------------------------------------------------------------------- @@ -187,9 +175,8 @@ class App extends BaseConfig * The number of SECONDS you want the session to last. * Setting to 0 (zero) means expire when the browser is closed. * - * @var integer */ - public $sessionExpiration = 7200; + public int $sessionExpiration = 7200; /** * -------------------------------------------------------------------------- @@ -206,9 +193,8 @@ class App extends BaseConfig * * IMPORTANT: You are REQUIRED to set a valid save path! * - * @var string */ - public $sessionSavePath = WRITEPATH . 'session'; + public string $sessionSavePath = WRITEPATH . 'session'; /** * -------------------------------------------------------------------------- @@ -220,9 +206,8 @@ class App extends BaseConfig * WARNING: If you're using the database driver, don't forget to update * your session table's PRIMARY KEY when changing this setting. * - * @var boolean */ - public $sessionMatchIP = false; + public bool $sessionMatchIP = false; /** * -------------------------------------------------------------------------- @@ -231,9 +216,8 @@ class App extends BaseConfig * * How many seconds between CI regenerating the session ID. * - * @var integer */ - public $sessionTimeToUpdate = 300; + public int $sessionTimeToUpdate = 300; /** * -------------------------------------------------------------------------- @@ -244,9 +228,8 @@ class App extends BaseConfig * when auto-regenerating the session ID. When set to FALSE, the data * will be later deleted by the garbage collector. * - * @var boolean */ - public $sessionRegenerateDestroy = false; + public bool $sessionRegenerateDestroy = false; /** * -------------------------------------------------------------------------- @@ -259,7 +242,7 @@ class App extends BaseConfig * * @deprecated use Config\Cookie::$prefix property instead. */ - public $cookiePrefix = ''; + public string $cookiePrefix = ''; /** * -------------------------------------------------------------------------- @@ -272,7 +255,7 @@ class App extends BaseConfig * * @deprecated use Config\Cookie::$domain property instead. */ - public $cookieDomain = ''; + public string $cookieDomain = ''; /** * -------------------------------------------------------------------------- @@ -285,7 +268,7 @@ class App extends BaseConfig * * @deprecated use Config\Cookie::$path property instead. */ - public $cookiePath = '/'; + public string $cookiePath = '/'; /** * -------------------------------------------------------------------------- @@ -294,11 +277,11 @@ class App extends BaseConfig * * Cookie will only be set if a secure HTTPS connection exists. * - * @var boolean + * @var bool * * @deprecated use Config\Cookie::$secure property instead. */ - public $cookieSecure = false; + public bool $cookieSecure = false; /** * -------------------------------------------------------------------------- @@ -311,7 +294,7 @@ class App extends BaseConfig * * @deprecated use Config\Cookie::$httponly property instead. */ - public $cookieHTTPOnly = true; + public bool $cookieHTTPOnly = true; /** * -------------------------------------------------------------------------- @@ -337,7 +320,7 @@ class App extends BaseConfig * * @deprecated use Config\Cookie::$samesite property instead. */ - public $cookieSameSite = 'Lax'; + public string $cookieSameSite = 'Lax'; /** * -------------------------------------------------------------------------- @@ -357,7 +340,7 @@ class App extends BaseConfig * * @var string|string[] */ - public $proxyIPs = ''; + public string|array $proxyIPs = ''; /** * -------------------------------------------------------------------------- @@ -367,10 +350,8 @@ class App extends BaseConfig * The token name. * * @deprecated Use `Config\Security` $tokenName property instead of using this property. - * - * @var string */ - public $CSRFTokenName = 'csrf_test_name'; + public string $CSRFTokenName = 'csrf_test_name'; /** * -------------------------------------------------------------------------- @@ -380,10 +361,8 @@ class App extends BaseConfig * The header name. * * @deprecated Use `Config\Security` $headerName property instead of using this property. - * - * @var string */ - public $CSRFHeaderName = 'X-CSRF-TOKEN'; + public string $CSRFHeaderName = 'X-CSRF-TOKEN'; /** * -------------------------------------------------------------------------- @@ -393,10 +372,8 @@ class App extends BaseConfig * The cookie name. * * @deprecated Use `Config\Security` $cookieName property instead of using this property. - * - * @var string */ - public $CSRFCookieName = 'csrf_cookie_name'; + public string $CSRFCookieName = 'csrf_cookie_name'; /** * -------------------------------------------------------------------------- @@ -406,10 +383,8 @@ class App extends BaseConfig * The number in seconds the token should expire. * * @deprecated Use `Config\Security` $expire property instead of using this property. - * - * @var integer */ - public $CSRFExpire = 7200; + public int $CSRFExpire = 7200; /** * -------------------------------------------------------------------------- @@ -419,10 +394,8 @@ class App extends BaseConfig * Regenerate token on every submission? * * @deprecated Use `Config\Security` $regenerate property instead of using this property. - * - * @var boolean */ - public $CSRFRegenerate = true; + public bool $CSRFRegenerate = true; /** * -------------------------------------------------------------------------- @@ -432,10 +405,8 @@ class App extends BaseConfig * Redirect to previous page with error on failure? * * @deprecated Use `Config\Security` $redirect property instead of using this property. - * - * @var boolean */ - public $CSRFRedirect = true; + public bool $CSRFRedirect = true; /** * -------------------------------------------------------------------------- @@ -453,10 +424,8 @@ class App extends BaseConfig * @see https://portswigger.net/web-security/csrf/samesite-cookies * * @deprecated Use `Config\Security` $samesite property instead of using this property. - * - * @var string */ - public $CSRFSameSite = 'Lax'; + public string $CSRFSameSite = 'Lax'; /** * -------------------------------------------------------------------------- @@ -473,48 +442,38 @@ class App extends BaseConfig * * @see http://www.html5rocks.com/en/tutorials/security/content-security-policy/ * @see http://www.w3.org/TR/CSP/ - * - * @var boolean */ - public $CSPEnabled = false; + public bool $CSPEnabled = false; /** * -------------------------------------------------------------------------- * Media root folder * -------------------------------------------------------------------------- * Defines the root folder for media files storage - * - * @var string */ - public $mediaRoot = 'media'; + public string $mediaRoot = 'media'; /** * -------------------------------------------------------------------------- * Admin gateway * -------------------------------------------------------------------------- * Defines a base route for all admin pages - * - * @var string */ - public $adminGateway = 'cp-admin'; + public string $adminGateway = 'cp-admin'; /** * -------------------------------------------------------------------------- * Auth gateway * -------------------------------------------------------------------------- * Defines a base route for all authentication related pages - * - * @var string */ - public $authGateway = 'cp-auth'; + public string $authGateway = 'cp-auth'; /** * -------------------------------------------------------------------------- * Install gateway * -------------------------------------------------------------------------- * Defines a base route for instance installation - * - * @var string */ - public $installGateway = 'cp-install'; + public string $installGateway = 'cp-install'; } diff --git a/app/Config/Cache.php b/app/Config/Cache.php index c26c1cc4..a59e6d17 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -20,9 +20,8 @@ class Cache extends BaseConfig * The name of the preferred handler that should be used. If for some reason * it is not available, the $backupHandler will be used in its place. * - * @var string */ - public $handler = 'file'; + public string $handler = 'file'; /** * -------------------------------------------------------------------------- @@ -33,9 +32,8 @@ class Cache extends BaseConfig * unreachable. Often, 'file' is used here since the filesystem is * always available, though that's not always practical for the app. * - * @var string */ - public $backupHandler = 'dummy'; + public string $backupHandler = 'dummy'; /** * -------------------------------------------------------------------------- @@ -45,11 +43,9 @@ class Cache extends BaseConfig * The path to where cache files should be stored, if using a file-based * system. * - * @var string - * * @deprecated Use the driver-specific variant under $file */ - public $storePath = WRITEPATH . 'cache/'; + public string $storePath = WRITEPATH . 'cache/'; /** * -------------------------------------------------------------------------- @@ -68,7 +64,7 @@ class Cache extends BaseConfig * * @var boolean|string[] */ - public $cacheQueryString = false; + public bool|array $cacheQueryString = false; /** * -------------------------------------------------------------------------- @@ -78,9 +74,8 @@ class Cache extends BaseConfig * This string is added to all cache item names to help avoid collisions * if you run multiple applications with the same cache engine. * - * @var string */ - public $prefix = ''; + public string $prefix = ''; /** * -------------------------------------------------------------------------- @@ -91,7 +86,7 @@ class Cache extends BaseConfig * * @var array */ - public $file = [ + public array $file = [ 'storePath' => WRITEPATH . 'cache/', 'mode' => 0640, ]; @@ -107,7 +102,7 @@ class Cache extends BaseConfig * * @var array */ - public $memcached = [ + public array $memcached = [ 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 1, @@ -123,7 +118,7 @@ class Cache extends BaseConfig * * @var array */ - public $redis = [ + public array $redis = [ 'host' => '127.0.0.1', 'password' => null, 'port' => 6379, @@ -141,7 +136,7 @@ class Cache extends BaseConfig * * @var array */ - public $validHandlers = [ + public array $validHandlers = [ 'dummy' => DummyHandler::class, 'file' => FileHandler::class, 'memcached' => MemcachedHandler::class, diff --git a/app/Config/ContentSecurityPolicy.php b/app/Config/ContentSecurityPolicy.php index 05ffa5d7..29c3e2d2 100644 --- a/app/Config/ContentSecurityPolicy.php +++ b/app/Config/ContentSecurityPolicy.php @@ -22,9 +22,8 @@ class ContentSecurityPolicy extends BaseConfig /** * Default CSP report context * - * @var boolean */ - public $reportOnly = false; + public bool $reportOnly = false; /** * Specifies a URL where a browser will send reports @@ -32,16 +31,15 @@ class ContentSecurityPolicy extends BaseConfig * * @var string|null */ - public $reportURI; + public ?string $reportURI = null; /** * Instructs user agents to rewrite URL schemes, changing * HTTP to HTTPS. This directive is for websites with * large numbers of old URLs that need to be rewritten. * - * @var boolean */ - public $upgradeInsecureRequests = false; + public bool $upgradeInsecureRequests = false; //------------------------------------------------------------------------- // Sources allowed @@ -53,28 +51,28 @@ class ContentSecurityPolicy extends BaseConfig * * @var string|string[]|null */ - public $defaultSrc; + public string|array|null $defaultSrc; /** * Lists allowed scripts' URLs. * * @var string|string[] */ - public $scriptSrc = 'self'; + public string|array $scriptSrc = 'self'; /** * Lists allowed stylesheets' URLs. * * @var string|string[] */ - public $styleSrc = 'self'; + public string|array $styleSrc = 'self'; /** * Defines the origins from which images can be loaded. * * @var string|string[] */ - public $imageSrc = 'self'; + public string|array $imageSrc = 'self'; /** * Restricts the URLs that can appear in a page's `` element. @@ -83,14 +81,14 @@ class ContentSecurityPolicy extends BaseConfig * * @var string|string[]|null */ - public $baseURI; + public string|array|null $baseURI; /** * Lists the URLs for workers and embedded frame contents * * @var string|string[] */ - public $childSrc = 'self'; + public string|array $childSrc = 'self'; /** * Limits the origins that you can connect to (via XHR, @@ -98,21 +96,21 @@ class ContentSecurityPolicy extends BaseConfig * * @var string|string[] */ - public $connectSrc = 'self'; + public string|array $connectSrc = 'self'; /** * Specifies the origins that can serve web fonts. * * @var string|string[] */ - public $fontSrc; + public string|array $fontSrc; /** * Lists valid endpoints for submission from `
` tags. * * @var string|string[] */ - public $formAction = 'self'; + public string|array $formAction = 'self'; /** * Specifies the sources that can embed the current page. @@ -122,38 +120,38 @@ class ContentSecurityPolicy extends BaseConfig * * @var string|string[]|null */ - public $frameAncestors; + public string|array|null $frameAncestors; /** * Restricts the origins allowed to deliver video and audio. * * @var string|string[]|null */ - public $mediaSrc; + public string|array|null $mediaSrc; /** * Allows control over Flash and other plugins. * * @var string|string[] */ - public $objectSrc = 'self'; + public string|array $objectSrc = 'self'; /** * @var string|string[]|null */ - public $manifestSrc; + public string|array|null $manifestSrc; /** * Limits the kinds of plugins a page may invoke. * * @var string|string[]|null */ - public $pluginTypes; + public string|array|null $pluginTypes; /** * List of actions allowed. * * @var string|string[]|null */ - public $sandbox; + public string|array|null $sandbox; } diff --git a/app/Config/Cookie.php b/app/Config/Cookie.php index 68c403e5..dcd371ab 100644 --- a/app/Config/Cookie.php +++ b/app/Config/Cookie.php @@ -14,9 +14,8 @@ class Cookie extends BaseConfig * * Set a cookie name prefix if you need to avoid collisions. * - * @var string */ - public $prefix = ''; + public string $prefix = ''; /** * -------------------------------------------------------------------------- @@ -27,9 +26,8 @@ class Cookie extends BaseConfig * cookie will not have the `Expires` attribute and will behave as a session * cookie. * - * @var DateTimeInterface|integer|string */ - public $expires = 0; + public DateTimeInterface|int|string $expires = 0; /** * -------------------------------------------------------------------------- @@ -38,9 +36,8 @@ class Cookie extends BaseConfig * * Typically will be a forward slash. * - * @var string */ - public $path = '/'; + public string $path = '/'; /** * -------------------------------------------------------------------------- @@ -49,9 +46,8 @@ class Cookie extends BaseConfig * * Set to `.your-domain.com` for site-wide cookies. * - * @var string */ - public $domain = ''; + public string $domain = ''; /** * -------------------------------------------------------------------------- @@ -60,9 +56,8 @@ class Cookie extends BaseConfig * * Cookie will only be set if a secure HTTPS connection exists. * - * @var boolean */ - public $secure = false; + public bool $secure = false; /** * -------------------------------------------------------------------------- @@ -71,9 +66,8 @@ class Cookie extends BaseConfig * * Cookie will only be accessible via HTTP(S) (no JavaScript). * - * @var boolean */ - public $httponly = true; + public bool $httponly = true; /** * -------------------------------------------------------------------------- @@ -95,9 +89,8 @@ class Cookie extends BaseConfig * (empty string) means default SameSite attribute set by browsers (`Lax`) * will be set on cookies. If set to `None`, `$secure` must also be set. * - * @var string */ - public $samesite = 'Lax'; + public string $samesite = 'Lax'; /** * -------------------------------------------------------------------------- @@ -110,10 +103,8 @@ class Cookie extends BaseConfig * If this is set to `true`, cookie names should be compliant of RFC 2616's * list of allowed characters. * - * @var boolean - * * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes * @see https://tools.ietf.org/html/rfc2616#section-2.2 */ - public $raw = false; + public bool $raw = false; } diff --git a/app/Config/Database.php b/app/Config/Database.php index a854688a..b856344a 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -50,6 +50,8 @@ class Database extends Config * This database connection is used when * running PHPUnit database tests. * + * @noRector StringClassNameToClassConstantRector + * * @var array */ public array $tests = [ @@ -58,7 +60,6 @@ class Database extends Config 'username' => '', 'password' => '', 'database' => ':memory:', - /** @noRector StringClassNameToClassConstantRector */ 'DBDriver' => 'SQLite3', 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS 'pConnect' => false, diff --git a/app/Config/DocTypes.php b/app/Config/DocTypes.php index d29036f0..81bdfb26 100644 --- a/app/Config/DocTypes.php +++ b/app/Config/DocTypes.php @@ -9,7 +9,7 @@ class DocTypes * * @var array */ - public $list = [ + public array $list = [ 'xhtml11' => '', 'xhtml1-strict' => diff --git a/app/Config/Email.php b/app/Config/Email.php index 61f9f140..f5f3b2d2 100644 --- a/app/Config/Email.php +++ b/app/Config/Email.php @@ -6,165 +6,135 @@ use CodeIgniter\Config\BaseConfig; class Email extends BaseConfig { - /** - * @var string - */ - public $fromEmail; + public string $fromEmail; - /** - * @var string - */ - public $fromName; + public string $fromName; - /** - * @var string - */ - public $recipients; + public string $recipients; /** * The "user agent" * - * @var string */ - public $userAgent = 'CodeIgniter'; + public string $userAgent = 'CodeIgniter'; /** * The mail sending protocol: mail, sendmail, smtp * - * @var string */ - public $protocol = 'mail'; + public string $protocol = 'mail'; /** * The server path to Sendmail. * - * @var string */ - public $mailPath = '/usr/sbin/sendmail'; + public string $mailPath = '/usr/sbin/sendmail'; /** * SMTP Server Address * - * @var string */ - public $SMTPHost; + public string $SMTPHost; /** * SMTP Username * - * @var string */ - public $SMTPUser; + public string $SMTPUser; /** * SMTP Password * - * @var string */ - public $SMTPPass; + public string $SMTPPass; /** * SMTP Port * - * @var integer */ - public $SMTPPort = 25; + public int $SMTPPort = 25; /** * SMTP Timeout (in seconds) * - * @var integer */ - public $SMTPTimeout = 5; + public int $SMTPTimeout = 5; /** * Enable persistent SMTP connections * - * @var boolean */ - public $SMTPKeepAlive = false; + public bool $SMTPKeepAlive = false; /** * SMTP Encryption. Either tls or ssl * - * @var string */ - public $SMTPCrypto = 'tls'; + public string $SMTPCrypto = 'tls'; /** * Enable word-wrap * - * @var boolean */ - public $wordWrap = true; + public bool $wordWrap = true; /** * Character count to wrap at * - * @var integer */ - public $wrapChars = 76; + public int $wrapChars = 76; /** * Type of mail, either 'text' or 'html' * - * @var string */ - public $mailType = 'text'; + public string $mailType = 'text'; /** * Character set (utf-8, iso-8859-1, etc.) * - * @var string */ - public $charset = 'UTF-8'; + public string $charset = 'UTF-8'; /** * Whether to validate the email address * - * @var boolean */ - public $validate = false; + public bool $validate = false; /** * Email Priority. 1 = highest. 5 = lowest. 3 = normal * - * @var integer */ - public $priority = 3; + public int $priority = 3; /** * Newline character. (Use ā€œ\r\nā€ to comply with RFC 822) * - * @var string */ - public $CRLF = "\r\n"; + public string $CRLF = "\r\n"; /** * Newline character. (Use ā€œ\r\nā€ to comply with RFC 822) * - * @var string */ - public $newline = "\r\n"; + public string $newline = "\r\n"; /** * Enable BCC Batch Mode. * - * @var boolean */ - public $BCCBatchMode = false; + public bool $BCCBatchMode = false; /** * Number of emails in each BCC batch * - * @var integer */ - public $BCCBatchSize = 200; + public int $BCCBatchSize = 200; /** * Enable notify message from server * - * @var boolean */ - public $DSN = false; + public bool $DSN = false; } diff --git a/app/Config/Encryption.php b/app/Config/Encryption.php index 51f8d01a..5e806ff1 100644 --- a/app/Config/Encryption.php +++ b/app/Config/Encryption.php @@ -21,9 +21,8 @@ class Encryption extends BaseConfig * You need to ensure it is long enough for the cipher and mode you plan to use. * See the user guide for more info. * - * @var string */ - public $key = ''; + public string $key = ''; /** * -------------------------------------------------------------------------- @@ -36,9 +35,8 @@ class Encryption extends BaseConfig * - OpenSSL * - Sodium * - * @var string */ - public $driver = 'OpenSSL'; + public string $driver = 'OpenSSL'; /** * -------------------------------------------------------------------------- @@ -50,9 +48,8 @@ class Encryption extends BaseConfig * * See the user guide for more information on padding. * - * @var integer */ - public $blockSize = 16; + public int $blockSize = 16; /** * -------------------------------------------------------------------------- @@ -61,7 +58,6 @@ class Encryption extends BaseConfig * * HMAC digest to use, e.g. 'SHA512' or 'SHA256'. Default value is 'SHA512'. * - * @var string */ - public $digest = 'SHA512'; + public string $digest = 'SHA512'; } diff --git a/app/Config/Exceptions.php b/app/Config/Exceptions.php index 47b85757..5461e0cb 100644 --- a/app/Config/Exceptions.php +++ b/app/Config/Exceptions.php @@ -18,9 +18,8 @@ class Exceptions extends BaseConfig * * Default: true * - * @var boolean */ - public $log = true; + public bool $log = true; /** * -------------------------------------------------------------------------- @@ -31,7 +30,7 @@ class Exceptions extends BaseConfig * * @var int[] */ - public $ignoreCodes = [404]; + public array $ignoreCodes = [404]; /** * -------------------------------------------------------------------------- @@ -42,7 +41,6 @@ class Exceptions extends BaseConfig * * Default: APPPATH.'Views/errors' * - * @var string */ - public $errorViewPath = APPPATH . 'Views/errors'; + public string $errorViewPath = APPPATH . 'Views/errors'; } diff --git a/app/Config/Filters.php b/app/Config/Filters.php index 573fc1ee..6a9ee2dd 100644 --- a/app/Config/Filters.php +++ b/app/Config/Filters.php @@ -19,7 +19,7 @@ class Filters extends BaseConfig * * @var array */ - public $aliases = [ + public array $aliases = [ 'csrf' => CSRF::class, 'toolbar' => DebugToolbar::class, 'honeypot' => Honeypot::class, @@ -35,7 +35,7 @@ class Filters extends BaseConfig * * @var array */ - public $globals = [ + public array $globals = [ 'before' => [ // 'honeypot', // 'csrf', @@ -55,7 +55,7 @@ class Filters extends BaseConfig * * @var array */ - public $methods = []; + public array $methods = []; /** * List of filter aliases that should run on any @@ -66,7 +66,7 @@ class Filters extends BaseConfig * * @var array> */ - public $filters = []; + public array $filters = []; public function __construct() { diff --git a/app/Config/Format.php b/app/Config/Format.php index b3ba4690..94d6d948 100644 --- a/app/Config/Format.php +++ b/app/Config/Format.php @@ -24,7 +24,7 @@ class Format extends BaseConfig * * @var string[] */ - public $supportedResponseFormats = [ + public array $supportedResponseFormats = [ 'application/json', 'application/xml', // machine-readable XML 'text/xml', // human-readable XML @@ -41,7 +41,7 @@ class Format extends BaseConfig * * @var array */ - public $formatters = [ + public array $formatters = [ 'application/json' => JSONFormatter::class, 'application/xml' => XMLFormatter::class, 'text/xml' => XMLFormatter::class, @@ -57,7 +57,7 @@ class Format extends BaseConfig * * @var array */ - public $formatterOptions = [ + public array $formatterOptions = [ 'application/json' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES, 'application/xml' => 0, 'text/xml' => 0, diff --git a/app/Config/Generators.php b/app/Config/Generators.php index 1f32e4bb..922a02ff 100644 --- a/app/Config/Generators.php +++ b/app/Config/Generators.php @@ -25,7 +25,7 @@ class Generators extends BaseConfig * * @var array */ - public $views = [ + public array $views = [ 'make:command' => 'CodeIgniter\Commands\Generators\Views\command.tpl.php', 'make:controller' => diff --git a/app/Config/Honeypot.php b/app/Config/Honeypot.php index 84f2a854..3e18afb5 100644 --- a/app/Config/Honeypot.php +++ b/app/Config/Honeypot.php @@ -9,35 +9,30 @@ class Honeypot extends BaseConfig /** * Makes Honeypot visible or not to human * - * @var boolean */ - public $hidden = true; + public bool $hidden = true; /** * Honeypot Label Content * - * @var string */ - public $label = 'Fill This Field'; + public string $label = 'Fill This Field'; /** * Honeypot Field Name * - * @var string */ - public $name = 'honeypot'; + public string $name = 'honeypot'; /** * Honeypot HTML Template * - * @var string */ - public $template = ''; + public string $template = ''; /** * Honeypot container * - * @var string */ - public $container = '
{template}
'; + public string $container = '
{template}
'; } diff --git a/app/Config/Images.php b/app/Config/Images.php index e1067cb6..dfe15694 100644 --- a/app/Config/Images.php +++ b/app/Config/Images.php @@ -11,24 +11,22 @@ class Images extends BaseConfig /** * Default handler used if no other handler is specified. * - * @var string */ - public $defaultHandler = 'gd'; + public string $defaultHandler = 'gd'; /** * The path to the image library. * Required for ImageMagick, GraphicsMagick, or NetPBM. * - * @var string */ - public $libraryPath = '/usr/local/bin/convert'; + public string $libraryPath = '/usr/local/bin/convert'; /** * The available handler classes. * * @var array */ - public $handlers = [ + public array $handlers = [ 'gd' => GDHandler::class, 'imagick' => ImageMagickHandler::class, ]; @@ -41,34 +39,19 @@ class Images extends BaseConfig | All uploaded images are of 1:1 ratio (width and height are the same). */ - /** - * @var integer - */ - public $thumbnailSize = 150; - - /** - * @var integer - */ - public $mediumSize = 320; - - /** - * @var integer - */ - public $largeSize = 1024; + public int $thumbnailSize = 150; + public int $mediumSize = 320; + public int $largeSize = 1024; /** * Size of images linked in the rss feed (should be between 1400 and 3000) - * - * @var integer */ - public $feedSize = 1400; + public int $feedSize = 1400; /** * Size for ID3 tag cover art (should be between 300 and 800) - * - * @var integer */ - public $id3Size = 500; + public int $id3Size = 500; /* |-------------------------------------------------------------------------- @@ -77,28 +60,13 @@ class Images extends BaseConfig | The properties listed below set the name extensions for the resized images */ - /** - * @var string - */ - public $thumbnailSuffix = '_thumbnail'; + public string $thumbnailSuffix = '_thumbnail'; - /** - * @var string - */ - public $mediumSuffix = '_medium'; + public string $mediumSuffix = '_medium'; - /** - * @var string - */ - public $largeSuffix = '_large'; + public string $largeSuffix = '_large'; - /** - * @var string - */ - public $feedSuffix = '_feed'; + public string $feedSuffix = '_feed'; - /** - * @var string - */ - public $id3Suffix = '_id3'; + public string $id3Suffix = '_id3'; } diff --git a/app/Config/Kint.php b/app/Config/Kint.php index ce2ff28a..26a74ac5 100644 --- a/app/Config/Kint.php +++ b/app/Config/Kint.php @@ -26,52 +26,35 @@ class Kint extends BaseConfig /** * @var string[] */ - public $plugins = []; + public array $plugins = []; - /** - * @var int - */ - public $maxDepth = 6; + public int $maxDepth = 6; - /** - * @var bool - */ - public $displayCalledFrom = true; + public bool $displayCalledFrom = true; - /** - * @var bool - */ - public $expanded = false; + public bool $expanded = false; /* |-------------------------------------------------------------------------- | RichRenderer Settings |-------------------------------------------------------------------------- */ - /** - * @var string - */ - public $richTheme = 'aante-light.css'; - /** - * @var bool - */ - public $richFolder = false; + public string $richTheme = 'aante-light.css'; - /** - * @var int - */ - public $richSort = Renderer::SORT_FULL; + public bool $richFolder = false; + + public int $richSort = Renderer::SORT_FULL; /** * @var string[] */ - public $richObjectPlugins = []; + public array $richObjectPlugins = []; /** * @var string[] */ - public $richTabPlugins = []; + public array $richTabPlugins = []; /* |-------------------------------------------------------------------------- @@ -79,23 +62,11 @@ class Kint extends BaseConfig |-------------------------------------------------------------------------- */ - /** - * @var bool - */ - public $cliColors = true; + public bool $cliColors = true; - /** - * @var bool - */ - public $cliForceUTF8 = false; + public bool $cliForceUTF8 = false; - /** - * @var bool - */ - public $cliDetectWidth = true; + public bool $cliDetectWidth = true; - /** - * @var int - */ - public $cliMinWidth = 40; + public int $cliMinWidth = 40; } diff --git a/app/Config/Logger.php b/app/Config/Logger.php index cfee2757..b0ae3c7d 100644 --- a/app/Config/Logger.php +++ b/app/Config/Logger.php @@ -36,7 +36,7 @@ class Logger extends BaseConfig * For a live site you'll usually enable Critical or higher (3) to be logged otherwise * your log files will fill up very fast. * - * @var integer|int[] + * @var int|int[] */ public int|array $threshold = 4; @@ -75,7 +75,7 @@ class Logger extends BaseConfig * Handlers are executed in the order defined in this array, starting with * the handler on top and continuing down. * - * @var array> + * @var array */ public array $handlers = [ /* @@ -123,17 +123,5 @@ class Logger extends BaseConfig */ 'path' => '', ], - - /** - * The ChromeLoggerHandler requires the use of the Chrome web browser - * and the ChromeLogger extension. Uncomment this block to use it. - */ - // 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [ - // /* - // * The log levels that this handler will handle. - // */ - // 'handles' => ['critical', 'alert', 'emergency', 'debug', - // 'error', 'info', 'notice', 'warning'], - // ] ]; } diff --git a/app/Config/Migrations.php b/app/Config/Migrations.php index 2913c4ca..e62dabc5 100644 --- a/app/Config/Migrations.php +++ b/app/Config/Migrations.php @@ -16,9 +16,8 @@ class Migrations extends BaseConfig * You should enable migrations whenever you intend to do a schema migration * and disable it back when you're done. * - * @var boolean */ - public $enabled = true; + public bool $enabled = true; /** * -------------------------------------------------------------------------- @@ -31,9 +30,8 @@ class Migrations extends BaseConfig * table to the $config['migration_version'] if they are not the same it * will migrate up. This must be set. * - * @var string */ - public $table = 'migrations'; + public string $table = 'migrations'; /** * -------------------------------------------------------------------------- @@ -49,7 +47,6 @@ class Migrations extends BaseConfig * - Y-m-d-His_ * - Y_m_d_His_ * - * @var string */ - public $timestampFormat = 'Y-m-d-His_'; + public string $timestampFormat = 'Y-m-d-His_'; } diff --git a/app/Config/Pager.php b/app/Config/Pager.php index 8f38d983..0f725d21 100644 --- a/app/Config/Pager.php +++ b/app/Config/Pager.php @@ -20,7 +20,7 @@ class Pager extends BaseConfig * * @var array */ - public $templates = [ + public array $templates = [ 'default_full' => 'App\Views\pager\default_full', 'default_simple' => 'CodeIgniter\Pager\Views\default_simple', 'default_head' => 'CodeIgniter\Pager\Views\default_head', @@ -33,7 +33,6 @@ class Pager extends BaseConfig * * The default number of results shown in a single page. * - * @var integer */ - public $perPage = 20; + public int $perPage = 20; } diff --git a/app/Config/Paths.php b/app/Config/Paths.php index 38eb3057..7b8b8591 100644 --- a/app/Config/Paths.php +++ b/app/Config/Paths.php @@ -24,9 +24,8 @@ class Paths * This must contain the name of your "system" folder. Include * the path if the folder is not in the same directory as this file. * - * @var string */ - public $systemDirectory = + public string $systemDirectory = __DIR__ . '/../../vendor/codeigniter4/codeigniter4/system'; /** * --------------------------------------------------------------- @@ -40,9 +39,8 @@ class Paths * * @see http://codeigniter.com/user_guide/general/managing_apps.html * - * @var string */ - public $appDirectory = __DIR__ . '/..'; + public string $appDirectory = __DIR__ . '/..'; /** * --------------------------------------------------------------- @@ -55,9 +53,8 @@ class Paths * for maximum security, keeping it out of the app and/or * system directories. * - * @var string */ - public $writableDirectory = __DIR__ . '/../../writable'; + public string $writableDirectory = __DIR__ . '/../../writable'; /** * --------------------------------------------------------------- @@ -66,9 +63,8 @@ class Paths * * This variable must contain the name of your "tests" directory. * - * @var string */ - public $testsDirectory = __DIR__ . '/../../tests'; + public string $testsDirectory = __DIR__ . '/../../tests'; /** * --------------------------------------------------------------- @@ -80,7 +76,6 @@ class Paths * default this is in `app/Views`. This value * is used when no value is provided to `Services::renderer()`. * - * @var string */ - public $viewDirectory = __DIR__ . '/../Views'; + public string $viewDirectory = __DIR__ . '/../Views'; } diff --git a/app/Config/Security.php b/app/Config/Security.php index ba00bd08..872fcf15 100644 --- a/app/Config/Security.php +++ b/app/Config/Security.php @@ -13,9 +13,8 @@ class Security extends BaseConfig * * Token name for Cross Site Request Forgery protection cookie. * - * @var string */ - public $tokenName = 'csrf_test_name'; + public string $tokenName = 'csrf_test_name'; /** * -------------------------------------------------------------------------- @@ -24,9 +23,8 @@ class Security extends BaseConfig * * Token name for Cross Site Request Forgery protection cookie. * - * @var string */ - public $headerName = 'X-CSRF-TOKEN'; + public string $headerName = 'X-CSRF-TOKEN'; /** * -------------------------------------------------------------------------- @@ -35,9 +33,8 @@ class Security extends BaseConfig * * Cookie name for Cross Site Request Forgery protection cookie. * - * @var string */ - public $cookieName = 'csrf_cookie_name'; + public string $cookieName = 'csrf_cookie_name'; /** * -------------------------------------------------------------------------- @@ -48,9 +45,8 @@ class Security extends BaseConfig * * Defaults to two hours (in seconds). * - * @var integer */ - public $expires = 7200; + public int $expires = 7200; /** * -------------------------------------------------------------------------- @@ -59,9 +55,8 @@ class Security extends BaseConfig * * Regenerate CSRF Token on every request. * - * @var boolean */ - public $regenerate = true; + public bool $regenerate = true; /** * -------------------------------------------------------------------------- @@ -70,9 +65,8 @@ class Security extends BaseConfig * * Redirect to previous page with error on failure. * - * @var boolean */ - public $redirect = true; + public bool $redirect = true; /** * -------------------------------------------------------------------------- @@ -88,5 +82,5 @@ class Security extends BaseConfig * * @var string 'Lax'|'None'|'Strict' */ - public $samesite = 'Lax'; + public string $samesite = 'Lax'; } diff --git a/app/Config/Toolbar.php b/app/Config/Toolbar.php index 5d7596d9..5be34fca 100644 --- a/app/Config/Toolbar.php +++ b/app/Config/Toolbar.php @@ -33,7 +33,7 @@ class Toolbar extends BaseConfig * * @var string[] */ - public $collectors = [ + public array $collectors = [ Timers::class, Database::class, Logs::class, @@ -53,9 +53,8 @@ class Toolbar extends BaseConfig * helping to conserve file space used to store them. You can set it to * 0 (zero) to not have any history stored, or -1 for unlimited history. * - * @var integer */ - public $maxHistory = 20; + public int $maxHistory = 20; /** * -------------------------------------------------------------------------- @@ -65,9 +64,8 @@ class Toolbar extends BaseConfig * The full path to the the views that are used by the toolbar. * This MUST have a trailing slash. * - * @var string */ - public $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/'; + public string $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/'; /** * -------------------------------------------------------------------------- @@ -81,7 +79,6 @@ class Toolbar extends BaseConfig * * `$maxQueries` defines the maximum amount of queries that will be stored. * - * @var integer */ - public $maxQueries = 100; + public int $maxQueries = 100; } diff --git a/app/Config/UserAgents.php b/app/Config/UserAgents.php index 18ad6c41..ef474693 100644 --- a/app/Config/UserAgents.php +++ b/app/Config/UserAgents.php @@ -22,7 +22,7 @@ class UserAgents extends BaseConfig * * @var array */ - public $platforms = [ + public array $platforms = [ 'windows nt 10.0' => 'Windows 10', 'windows nt 6.3' => 'Windows 8.1', 'windows nt 6.2' => 'Windows 8', @@ -77,7 +77,7 @@ class UserAgents extends BaseConfig * * @var array */ - public $browsers = [ + public array $browsers = [ 'OPR' => 'Opera', 'Flock' => 'Flock', 'Edge' => 'Spartan', @@ -118,7 +118,7 @@ class UserAgents extends BaseConfig * * @var array */ - public $mobiles = [ + public array $mobiles = [ // legacy array, old values commented out 'mobileexplorer' => 'Mobile Explorer', // 'openwave' => 'Open Wave', @@ -227,7 +227,7 @@ class UserAgents extends BaseConfig * * @var array */ - public $robots = [ + public array $robots = [ 'googlebot' => 'Googlebot', 'msnbot' => 'MSNBot', 'baiduspider' => 'Baiduspider', diff --git a/app/Config/Validation.php b/app/Config/Validation.php index 0db23ed2..cd201f97 100644 --- a/app/Config/Validation.php +++ b/app/Config/Validation.php @@ -22,7 +22,7 @@ class Validation * * @var string[] */ - public $ruleSets = [ + public array $ruleSets = [ Rules::class, FormatRules::class, FileRules::class, @@ -38,7 +38,7 @@ class Validation * * @var array */ - public $templates = [ + public array $templates = [ 'list' => 'CodeIgniter\Validation\Views\list', 'single' => 'CodeIgniter\Validation\Views\single', ]; diff --git a/app/Controllers/Admin/ContributorController.php b/app/Controllers/Admin/ContributorController.php index bcdc2214..e1aabd78 100644 --- a/app/Controllers/Admin/ContributorController.php +++ b/app/Controllers/Admin/ContributorController.php @@ -19,15 +19,8 @@ use CodeIgniter\HTTP\RedirectResponse; class ContributorController extends BaseController { - /** - * @var Podcast - */ - protected $podcast; - - /** - * @var User|null - */ - protected $user; + protected Podcast $podcast; + protected ?User $user; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/Admin/EpisodeController.php b/app/Controllers/Admin/EpisodeController.php index 4eb61cf2..94d6d97d 100644 --- a/app/Controllers/Admin/EpisodeController.php +++ b/app/Controllers/Admin/EpisodeController.php @@ -23,15 +23,8 @@ use CodeIgniter\I18n\Time; class EpisodeController extends BaseController { - /** - * @var Podcast - */ - protected $podcast; - - /** - * @var Episode|null - */ - protected $episode; + protected Podcast $podcast; + protected ?Episode $episode; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/Admin/PageController.php b/app/Controllers/Admin/PageController.php index 2308f3db..e5364734 100644 --- a/app/Controllers/Admin/PageController.php +++ b/app/Controllers/Admin/PageController.php @@ -15,10 +15,7 @@ use App\Models\PageModel; class PageController extends BaseController { - /** - * @var Page|null - */ - protected $page; + protected ?Page $page; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/Admin/PersonController.php b/app/Controllers/Admin/PersonController.php index 6e07467d..7cbb0373 100644 --- a/app/Controllers/Admin/PersonController.php +++ b/app/Controllers/Admin/PersonController.php @@ -16,10 +16,7 @@ use App\Models\PersonModel; class PersonController extends BaseController { - /** - * @var Person|null - */ - protected $person; + protected ?Person $person; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/Admin/PodcastController.php b/app/Controllers/Admin/PodcastController.php index cbeb6022..c5d03fbd 100644 --- a/app/Controllers/Admin/PodcastController.php +++ b/app/Controllers/Admin/PodcastController.php @@ -25,7 +25,7 @@ class PodcastController extends BaseController /** * @var Podcast */ - protected $podcast; + protected Podcast $podcast; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/Admin/PodcastImportController.php b/app/Controllers/Admin/PodcastImportController.php index f94997b2..57380f3e 100644 --- a/app/Controllers/Admin/PodcastImportController.php +++ b/app/Controllers/Admin/PodcastImportController.php @@ -32,7 +32,7 @@ class PodcastImportController extends BaseController /** * @var Podcast|null */ - protected $podcast; + protected ?Podcast $podcast; public function _remap(string $method, string ...$params): mixed { @@ -122,7 +122,7 @@ class PodcastImportController extends BaseController try { if ( - isset($nsItunes->image) && + property_exists($nsItunes, 'image') && $nsItunes->image !== null && $nsItunes->image->attributes()['href'] !== null ) { $imageFile = download_file( @@ -135,7 +135,7 @@ class PodcastImportController extends BaseController } $location = null; - if (isset($nsPodcast->location)) { + if (property_exists($nsPodcast, 'location') && $nsPodcast->location !== null) { $location = new Location( (string) $nsPodcast->location, (string) $nsPodcast->location->attributes()['geo'], @@ -160,7 +160,7 @@ class PodcastImportController extends BaseController 'language_code' => $this->request->getPost('language'), 'category_id' => $this->request->getPost('category'), 'parental_advisory' => - isset($nsItunes->explicit) + property_exists($nsItunes, 'explicit') && $nsItunes->explicit !== null ? (in_array((string) $nsItunes->explicit, ['yes', 'true']) ? 'explicit' : (in_array((string) $nsItunes->explicit, ['no', 'false']) @@ -170,16 +170,12 @@ class PodcastImportController extends BaseController 'owner_name' => (string) $nsItunes->owner->name, 'owner_email' => (string) $nsItunes->owner->email, 'publisher' => (string) $nsItunes->author, - 'type' => isset($nsItunes->type) ? (string) $nsItunes->type : 'episodic', + 'type' => property_exists($nsItunes, 'type') && $nsItunes->type !== null ? (string) $nsItunes->type : 'episodic', 'copyright' => (string) $feed->channel[0]->copyright, 'is_blocked' => - isset($nsItunes->block) - ? (string) $nsItunes->block === 'yes' - : false, + property_exists($nsItunes, 'block') && $nsItunes->block !== null && (string) $nsItunes->block === 'yes', 'is_completed' => - isset($nsItunes->complete) - ? (string) $nsItunes->complete === 'yes' - : false, + property_exists($nsItunes, 'complete') && $nsItunes->complete !== null && (string) $nsItunes->complete === 'yes', 'location' => $location, 'created_by' => user_id(), 'updated_by' => user_id(), @@ -337,7 +333,7 @@ class PodcastImportController extends BaseController }; if ( - isset($nsItunes->image) && + property_exists($nsItunes, 'image') && $nsItunes->image !== null && $nsItunes->image->attributes()['href'] !== null ) { $episodeImage = new Image( @@ -350,7 +346,7 @@ class PodcastImportController extends BaseController } $location = null; - if (isset($nsPodcast->location)) { + if (property_exists($nsPodcast, 'location') && $nsPodcast->location !== null) { $location = new Location( (string) $nsPodcast->location, (string) $nsPodcast->location->attributes()['geo'], @@ -372,7 +368,7 @@ class PodcastImportController extends BaseController 'description_html' => $itemDescriptionHtml, 'image' => $episodeImage, 'parental_advisory' => - isset($nsItunes->explicit) + property_exists($nsItunes, 'explicit') && $nsItunes->explicit !== null ? (in_array((string) $nsItunes->explicit, ['yes', 'true']) ? 'explicit' : (in_array((string) $nsItunes->explicit, ['no', 'false']) @@ -387,12 +383,10 @@ class PodcastImportController extends BaseController $this->request->getPost('season_number') === null ? $nsItunes->season : $this->request->getPost('season_number'), - 'type' => isset($nsItunes->episodeType) + 'type' => property_exists($nsItunes, 'episodeType') && $nsItunes->episodeType !== null ? (string) $nsItunes->episodeType : 'full', - 'is_blocked' => isset($nsItunes->block) - ? (string) $nsItunes->block === 'yes' - : false, + 'is_blocked' => property_exists($nsItunes, 'block') && $nsItunes->block !== null && (string) $nsItunes->block === 'yes', 'location' => $location, 'created_by' => user_id(), 'updated_by' => user_id(), diff --git a/app/Controllers/Admin/PodcastPersonController.php b/app/Controllers/Admin/PodcastPersonController.php index 3b6a8147..e2c12e5d 100644 --- a/app/Controllers/Admin/PodcastPersonController.php +++ b/app/Controllers/Admin/PodcastPersonController.php @@ -19,7 +19,7 @@ class PodcastPersonController extends BaseController /** * @var Podcast */ - protected $podcast; + protected Podcast $podcast; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/Admin/PodcastPlatformController.php b/app/Controllers/Admin/PodcastPlatformController.php index c68d2a17..db00694f 100644 --- a/app/Controllers/Admin/PodcastPlatformController.php +++ b/app/Controllers/Admin/PodcastPlatformController.php @@ -20,7 +20,7 @@ class PodcastPlatformController extends BaseController /** * @var Podcast|null */ - protected $podcast; + protected ?Podcast $podcast; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 04b10570..e537c3c2 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -17,10 +17,7 @@ use Config\Services; class UserController extends BaseController { - /** - * @var User|null - */ - protected $user; + protected ?User $user; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/EpisodeController.php b/app/Controllers/EpisodeController.php index ec531e16..517048cd 100644 --- a/app/Controllers/EpisodeController.php +++ b/app/Controllers/EpisodeController.php @@ -22,15 +22,9 @@ class EpisodeController extends BaseController { use AnalyticsTrait; - /** - * @var Podcast - */ - protected $podcast; + protected Podcast $podcast; - /** - * @var Episode - */ - protected $episode; + protected Episode $episode; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/NoteController.php b/app/Controllers/NoteController.php index bcf8f094..e6f5106e 100644 --- a/app/Controllers/NoteController.php +++ b/app/Controllers/NoteController.php @@ -25,15 +25,8 @@ class NoteController extends ActivityPubNoteController { use AnalyticsTrait; - /** - * @var Podcast - */ - protected $podcast; - - /** - * @var Actor - */ - protected $actor; + protected Podcast $podcast; + protected Actor $actor; /** * @var string[] @@ -219,6 +212,7 @@ class NoteController extends ActivityPubNoteController } $action = $this->request->getPost('action'); + /** @phpstan-ignore-next-line */ switch ($action) { case 'favourite': return $this->attemptFavourite(); diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php index 8f02363a..d10686fb 100644 --- a/app/Controllers/PageController.php +++ b/app/Controllers/PageController.php @@ -16,10 +16,7 @@ use App\Models\PodcastModel; class PageController extends BaseController { - /** - * @var Page|null - */ - protected $page; + protected ?Page $page; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Controllers/PodcastController.php b/app/Controllers/PodcastController.php index f4ae6663..2df70dc7 100644 --- a/app/Controllers/PodcastController.php +++ b/app/Controllers/PodcastController.php @@ -22,7 +22,7 @@ class PodcastController extends BaseController /** * @var Podcast */ - protected $podcast; + protected Podcast $podcast; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Database/Migrations/2020-12-25-140000_add_episodes_persons.php b/app/Database/Migrations/2020-12-25-140000_add_episodes_persons.php index 9382b9ac..b23c7018 100644 --- a/app/Database/Migrations/2020-12-25-140000_add_episodes_persons.php +++ b/app/Database/Migrations/2020-12-25-140000_add_episodes_persons.php @@ -44,7 +44,7 @@ class AddEpisodesPersons extends Migration 'constraint' => 32, ], ]); - $this->forge->addPrimaryKey('id', true); + $this->forge->addPrimaryKey('id'); $this->forge->addUniqueKey([ 'podcast_id', 'episode_id', diff --git a/app/Database/Seeds/AuthSeeder.php b/app/Database/Seeds/AuthSeeder.php index 24835c26..bd26b133 100644 --- a/app/Database/Seeds/AuthSeeder.php +++ b/app/Database/Seeds/AuthSeeder.php @@ -18,7 +18,7 @@ class AuthSeeder extends Seeder /** * @var array[] */ - protected $groups = [ + protected array $groups = [ [ 'name' => 'superadmin', 'description' => @@ -43,7 +43,7 @@ class AuthSeeder extends Seeder * * @var array[]> */ - protected $permissions = [ + protected array $permissions = [ 'users' => [ [ 'name' => 'create', diff --git a/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php b/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php index 0a8e3d15..7d84aa6c 100644 --- a/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php +++ b/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php @@ -114,11 +114,11 @@ class FakePodcastsAnalyticsSeeder extends Seeder try { $city = $cityReader->city($fakeIp); - $countryCode = empty($city->country->isoCode) + $countryCode = $city->country->isoCode === null ? 'N/A' : $city->country->isoCode; - $regionCode = empty($city->subdivisions[0]->isoCode) + $regionCode = $city->subdivisions[0]->isoCode === null ? 'N/A' : $city->subdivisions[0]->isoCode; $latitude = round($city->location->latitude, 3); diff --git a/app/Database/Seeds/FakeWebsiteAnalyticsSeeder.php b/app/Database/Seeds/FakeWebsiteAnalyticsSeeder.php index 21fbc8fa..e33e5095 100644 --- a/app/Database/Seeds/FakeWebsiteAnalyticsSeeder.php +++ b/app/Database/Seeds/FakeWebsiteAnalyticsSeeder.php @@ -21,7 +21,7 @@ class FakeWebsiteAnalyticsSeeder extends Seeder /** * @var string[] */ - protected $keywords = [ + protected array $keywords = [ 'all the smoke podcast', 'apple podcast', 'bad friends podcast', @@ -77,7 +77,7 @@ class FakeWebsiteAnalyticsSeeder extends Seeder /** * @var string[] */ - protected $domains = [ + protected array $domains = [ '360.cn ', 'adobe.com ', 'aliexpress.com ', @@ -133,7 +133,7 @@ class FakeWebsiteAnalyticsSeeder extends Seeder /** * @var string[] */ - protected $browsers = [ + protected array $browsers = [ 'Android Browser', 'Avast Secure Browser', 'BlackBerry Browser', diff --git a/app/Entities/Category.php b/app/Entities/Category.php index afc4e265..b9c32209 100644 --- a/app/Entities/Category.php +++ b/app/Entities/Category.php @@ -36,7 +36,7 @@ class Category extends Entity public function getParent(): ?Category { - if (empty($this->parent_id)) { + if ($this->parent_id === null) { return null; } diff --git a/app/Entities/Episode.php b/app/Entities/Episode.php index a9d72656..a48e1e71 100644 --- a/app/Entities/Episode.php +++ b/app/Entities/Episode.php @@ -95,19 +95,19 @@ class Episode extends Entity protected File $chapters_file; /** - * @var Person[] + * @var Person[]|null */ - protected $persons = []; + protected ?array $persons = null; /** - * @var Soundbite[] + * @var Soundbite[]|null */ - protected $soundbites = []; + protected ?array $soundbites = null; /** - * @var Note[] + * @var Note[]|null */ - protected $notes = []; + protected ?array $notes = null; protected ?Location $location = null; protected string $custom_rss_string; @@ -348,13 +348,13 @@ class Episode extends Entity */ public function getPersons(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Episode must be created before getting persons.', ); } - if (empty($this->persons)) { + if ($this->persons === null) { $this->persons = (new PersonModel())->getEpisodePersons( $this->podcast_id, $this->id, @@ -371,13 +371,13 @@ class Episode extends Entity */ public function getSoundbites(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Episode must be created before getting soundbites.', ); } - if (empty($this->soundbites)) { + if ($this->soundbites === null) { $this->soundbites = (new SoundbiteModel())->getEpisodeSoundbites( $this->getPodcast()->id, $this->id, @@ -392,13 +392,13 @@ class Episode extends Entity */ public function getNotes(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Episode must be created before getting soundbites.', ); } - if (empty($this->notes)) { + if ($this->notes === null) { $this->notes = (new NoteModel())->getEpisodeNotes($this->id); } diff --git a/app/Entities/Location.php b/app/Entities/Location.php index 40f256fa..7726b15e 100644 --- a/app/Entities/Location.php +++ b/app/Entities/Location.php @@ -61,10 +61,8 @@ class Location extends Entity /** * Fetches places from Nominatim OpenStreetMap - * - * @return array|null */ - public function fetchOsmLocation(): self + public function fetchOsmLocation(): static { $client = Services::curlrequest(); @@ -93,11 +91,11 @@ class Location extends Entity return $this; } - if (isset($places[0]->lat, $places[0]->lon)) { + if (property_exists($places[0], 'lat') && $places[0]->lat !== null && (property_exists($places[0], 'lon') && $places[0]->lon !== null)) { $this->attributes['geo'] = "geo:{$places[0]->lat},{$places[0]->lon}"; } - if (isset($places[0]->osm_type, $places[0]->osm_id)) { + if (property_exists($places[0], 'osm_type') && $places[0]->osm_type !== null && (property_exists($places[0], 'osm_id') && $places[0]->osm_id !== null)) { $this->attributes['osm'] = strtoupper(substr($places[0]->osm_type, 0, 1)) . $places[0]->osm_id; } diff --git a/app/Entities/Person.php b/app/Entities/Person.php index eb15dbdc..be338f1a 100644 --- a/app/Entities/Person.php +++ b/app/Entities/Person.php @@ -22,14 +22,16 @@ use RuntimeException; * @property string $image_mimetype * @property int $created_by * @property int $updated_by - * @property string[]|null $roles + * @property object[]|null $roles */ class Person extends Entity { protected Image $image; + protected ?int $podcast_id = null; + protected ?int $episode_id = null; /** - * @var string[]|null + * @var object[]|null */ protected ?array $roles = null; @@ -75,17 +77,17 @@ class Person extends Entity } /** - * @return stdClass[] + * @return object[] */ public function getRoles(): array { - if ($this->podcast_id === null) { + if ($this->attributes['podcast_id'] === null) { throw new RuntimeException( 'Person must have a podcast_id before getting roles.', ); } if ($this->roles === null) { - $this->roles = (new PersonModel())->getPersonRoles($this->id, $this->podcast_id, $this->episode_id); + $this->roles = (new PersonModel())->getPersonRoles($this->id, $this->attributes['podcast_id'], $this->episode_id); } return $this->roles; diff --git a/app/Entities/Podcast.php b/app/Entities/Podcast.php index 55ba0356..f76156c5 100644 --- a/app/Entities/Podcast.php +++ b/app/Entities/Podcast.php @@ -84,44 +84,44 @@ class Podcast extends Entity protected ?Category $category = null; /** - * @var Category[] + * @var Category[]|null */ - protected $other_categories = []; + protected ?array $other_categories = null; /** - * @var string[] + * @var string[]|null */ - protected $other_categories_ids = []; + protected ?array $other_categories_ids = null; /** - * @var Episode[] + * @var Episode[]|null */ - protected $episodes = []; + protected ?array $episodes = null; /** - * @var Person[] + * @var Person[]|null */ - protected $persons = []; + protected ?array $persons = null; /** - * @var User[] + * @var User[]|null */ - protected $contributors = []; + protected ?array $contributors = null; /** - * @var Platform[] + * @var Platform[]|null */ - protected $podcasting_platforms = []; + protected ?array $podcasting_platforms = null; /** - * @var Platform[] + * @var Platform[]|null */ - protected $social_platforms = []; + protected ?array $social_platforms = null; /** - * @var Platform[] + * @var Platform[]|null */ - protected $funding_platforms = []; + protected ?array $funding_platforms = null; protected ?Location $location = null; protected string $custom_rss_string; @@ -216,13 +216,13 @@ class Podcast extends Entity */ public function getEpisodes(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Podcast must be created before getting episodes.', ); } - if (empty($this->episodes)) { + if ($this->episodes === null) { $this->episodes = (new EpisodeModel())->getPodcastEpisodes( $this->id, $this->type, @@ -239,13 +239,13 @@ class Podcast extends Entity */ public function getPersons(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Podcast must be created before getting persons.', ); } - if (empty($this->persons)) { + if ($this->persons === null) { $this->persons = (new PersonModel())->getPodcastPersons($this->id); } @@ -279,13 +279,13 @@ class Podcast extends Entity */ public function getContributors(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Podcasts must be created before getting contributors.', ); } - if (empty($this->contributors)) { + if ($this->contributors === null) { $this->contributors = (new UserModel())->getPodcastContributors( $this->id, ); @@ -351,13 +351,13 @@ class Podcast extends Entity */ public function getPodcastingPlatforms(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Podcast must be created before getting podcasting platform links.', ); } - if (empty($this->podcasting_platforms)) { + if ($this->podcasting_platforms === null) { $this->podcasting_platforms = (new PlatformModel())->getPodcastPlatforms( $this->id, 'podcasting', @@ -374,13 +374,13 @@ class Podcast extends Entity */ public function getSocialPlatforms(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Podcast must be created before getting social platform links.', ); } - if (empty($this->social_platforms)) { + if ($this->social_platforms === null) { $this->social_platforms = (new PlatformModel())->getPodcastPlatforms( $this->id, 'social', @@ -397,13 +397,13 @@ class Podcast extends Entity */ public function getFundingPlatforms(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Podcast must be created before getting funding platform links.', ); } - if (empty($this->funding_platforms)) { + if ($this->funding_platforms === null) { $this->funding_platforms = (new PlatformModel())->getPodcastPlatforms( $this->id, 'funding', @@ -418,13 +418,13 @@ class Podcast extends Entity */ public function getOtherCategories(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Podcast must be created before getting other categories.', ); } - if (empty($this->other_categories)) { + if ($this->other_categories === null) { $this->other_categories = (new CategoryModel())->getPodcastCategories( $this->id, ); @@ -434,11 +434,11 @@ class Podcast extends Entity } /** - * @return array + * @return int[] */ public function getOtherCategoriesIds(): array { - if (empty($this->other_categories_ids)) { + if ($this->other_categories_ids === null) { $this->other_categories_ids = array_column( $this->getOtherCategories(), 'id', @@ -497,7 +497,7 @@ class Podcast extends Entity */ function getCustomRssString(): string { - if (empty($this->attributes['custom_rss'])) { + if ($this->attributes['custom_rss'] === null) { return ''; } @@ -521,7 +521,7 @@ class Podcast extends Entity */ function setCustomRssString(string $customRssString): static { - if (empty($customRssString)) { + if ($customRssString === '') { return $this; } diff --git a/app/Filters/PermissionFilter.php b/app/Filters/PermissionFilter.php index 84495dc3..770f5fb2 100644 --- a/app/Filters/PermissionFilter.php +++ b/app/Filters/PermissionFilter.php @@ -28,7 +28,7 @@ class PermissionFilter implements FilterInterface { helper('auth'); - if (empty($params)) { + if ($params === null) { return; } diff --git a/app/Helpers/components_helper.php b/app/Helpers/components_helper.php index 172bfca1..d0dcdbc8 100644 --- a/app/Helpers/components_helper.php +++ b/app/Helpers/components_helper.php @@ -78,7 +78,7 @@ if (!function_exists('button')) { ' ' . $variantClass[$options['variant']]; - if (!empty($customAttributes['class'])) { + if (array_key_exists('class', $customAttributes)) { $buttonClass .= ' ' . $customAttributes['class']; unset($customAttributes['class']); } @@ -298,6 +298,7 @@ if (!function_exists('publication_button')) { int $episodeId, string $publicationStatus ): string { + /** @phpstan-ignore-next-line */ switch ($publicationStatus) { case 'not_published': $label = lang('Episode.publish'); @@ -406,7 +407,7 @@ if (!function_exists('location_link')) { [ 'class' => 'inline-flex items-baseline hover:underline' . - (empty($class) ? '' : " {$class}"), + ($class === '' ? '' : " {$class}"), 'target' => '_blank', 'rel' => 'noreferrer noopener', ], diff --git a/app/Helpers/id3_helper.php b/app/Helpers/id3_helper.php index d13239dd..1b789984 100644 --- a/app/Helpers/id3_helper.php +++ b/app/Helpers/id3_helper.php @@ -62,7 +62,7 @@ if (!function_exists('write_audio_file_tags')) { $TagData = [ 'title' => [$episode->title], 'artist' => [ - empty($episode->podcast->publisher) + $episode->podcast->publisher === null ? $episode->podcast->owner_name : $episode->podcast->publisher, ], @@ -77,7 +77,7 @@ if (!function_exists('write_audio_file_tags')) { 'track_number' => [(string) $episode->number], 'copyright_message' => [$episode->podcast->copyright], 'publisher' => [ - empty($episode->podcast->publisher) + $episode->podcast->publisher === null ? $episode->podcast->owner_name : $episode->podcast->publisher, ], @@ -103,7 +103,7 @@ if (!function_exists('write_audio_file_tags')) { // write tags if ($tagwriter->WriteTags()) { echo 'Successfully wrote tags
'; - if (!empty($tagwriter->warnings)) { + if ($tagwriter->warnings !== []) { echo 'There were some warnings:
' . implode('

', $tagwriter->warnings); } diff --git a/app/Helpers/misc_helper.php b/app/Helpers/misc_helper.php index d90e8fa5..e660118f 100644 --- a/app/Helpers/misc_helper.php +++ b/app/Helpers/misc_helper.php @@ -10,16 +10,13 @@ if (!function_exists('get_browser_language')) { /** * Gets the browser default language using the request header key `HTTP_ACCEPT_LANGUAGE` * - * @return string|null ISO 639-1 language code or null + * @return string ISO 639-1 language code */ - function get_browser_language(string $httpAcceptLanguage): ?string + function get_browser_language(string $httpAcceptLanguage): string { $langs = explode(',', $httpAcceptLanguage); - if (!empty($langs)) { - return substr($langs[0], 0, 2); - } - return null; + return substr($langs[0], 0, 2); } } diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php index 8fed1cd0..98485117 100644 --- a/app/Helpers/rss_helper.php +++ b/app/Helpers/rss_helper.php @@ -181,53 +181,45 @@ if (!function_exists('get_rss_feed')) { } } - foreach ($podcast->persons as $podcastPerson) { - $podcastPersonElement = $channel->addChild( - 'person', - htmlspecialchars($podcastPerson->full_name), - $podcastNamespace, - ); + foreach ($podcast->persons as $person) { + foreach ($person->roles as $role) { + $personElement = $channel->addChild( + 'person', + htmlspecialchars($person->full_name), + $podcastNamespace, + ); - if ( - $podcastPerson->role !== null && - $podcastPerson->role !== null - ) { - $podcastPersonElement->addAttribute( + $personElement->addAttribute('img', $person->image->large_url); + + if ($person->information_url !== null) { + $personElement->addAttribute( + 'href', + $person->information_url, + ); + } + + $personElement->addAttribute( 'role', htmlspecialchars( lang( - "PersonsTaxonomy.persons.{$podcastPerson->group}.roles.{$podcastPerson->role}.label", + "PersonsTaxonomy.persons.{$role->group}.roles.{$role->role}.label", [], 'en', ), ), ); - } - if ($podcastPerson->group !== null) { - $podcastPersonElement->addAttribute( + $personElement->addAttribute( 'group', htmlspecialchars( lang( - "PersonsTaxonomy.persons.{$podcastPerson->group}.label", + "PersonsTaxonomy.persons.{$role->group}.label", [], 'en', ), ), ); } - - $podcastPersonElement->addAttribute( - 'img', - $podcastPerson->image->large_url, - ); - - if ($podcastPerson->information_url !== null) { - $podcastPersonElement->addAttribute( - 'href', - $podcastPerson->information_url, - ); - } } // set main category first, then other categories as apple @@ -399,7 +391,7 @@ if (!function_exists('get_rss_feed')) { foreach ($episode->soundbites as $soundbite) { $soundbiteElement = $item->addChild( 'soundbite', - empty($soundbite->label) ? null : $soundbite->label, + $soundbite->label, $podcastNamespace, ); $soundbiteElement->addAttribute( @@ -412,55 +404,54 @@ if (!function_exists('get_rss_feed')) { ); } - foreach ($episode->persons as $episodePerson) { - $episodePersonElement = $item->addChild( - 'person', - htmlspecialchars($episodePerson->full_name), - $podcastNamespace, - ); - if ( - !empty($episodePerson->role) && - !empty($episodePerson->group) - ) { - $episodePersonElement->addAttribute( + foreach ($episode->persons as $person) { + foreach ($person->roles as $role) { + $personElement = $item->addChild( + 'person', + htmlspecialchars($person->full_name), + $podcastNamespace, + ); + + $personElement->addAttribute( 'role', htmlspecialchars( lang( - "PersonsTaxonomy.persons.{$episodePerson->group}.roles.{$episodePerson->role}.label", + "PersonsTaxonomy.persons.{$role->group}.roles.{$role->role}.label", [], 'en', ), ), ); - } - if (!empty($episodePerson->person_group)) { - $episodePersonElement->addAttribute( + + $personElement->addAttribute( 'group', htmlspecialchars( lang( - "PersonsTaxonomy.persons.{$episodePerson->group}.label", + "PersonsTaxonomy.persons.{$role->group}.label", [], 'en', ), ), ); - } - $episodePersonElement->addAttribute( - 'img', - $episodePerson->image->large_url, - ); - if (!empty($episodePerson->information_url)) { - $episodePersonElement->addAttribute( - 'href', - $episodePerson->information_url, + + $personElement->addAttribute( + 'img', + $person->image->large_url, ); + + if ($person->information_url !== null) { + $personElement->addAttribute( + 'href', + $person->information_url, + ); + } } } $episode->is_blocked && $item->addChild('block', 'Yes', $itunesNamespace); - if (!empty($episode->custom_rss)) { + if ($episode->custom_rss !== null) { array_to_rss( [ 'elements' => $episode->custom_rss, @@ -557,9 +548,9 @@ if (!function_exists('array_to_rss')) { $childXmlNode = $xmlNode->addChild( $childArrayNode['name'], $childArrayNode['content'] ?? null, - empty($childArrayNode['namespace']) - ? null - : current($childArrayNode['namespace']), + array_key_exists('namespace', $childArrayNode) + ? current($childArrayNode['namespace']) + : null, ); if (array_key_exists('attributes', $childArrayNode)) { foreach ( diff --git a/app/Helpers/url_helper.php b/app/Helpers/url_helper.php index d58614bb..8574beda 100644 --- a/app/Helpers/url_helper.php +++ b/app/Helpers/url_helper.php @@ -16,7 +16,7 @@ if (!function_exists('host_url')) { { if (isset($_SERVER['HTTP_HOST'])) { $protocol = - (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || + (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://'; diff --git a/app/Libraries/ActivityPub/Activities/AcceptActivity.php b/app/Libraries/ActivityPub/Activities/AcceptActivity.php index 13c18021..10d8b07f 100644 --- a/app/Libraries/ActivityPub/Activities/AcceptActivity.php +++ b/app/Libraries/ActivityPub/Activities/AcceptActivity.php @@ -17,8 +17,5 @@ use ActivityPub\Core\Activity; class AcceptActivity extends Activity { - /** - * @var string - */ - protected $type = 'Accept'; + protected string $type = 'Accept'; } diff --git a/app/Libraries/ActivityPub/Activities/AnnounceActivity.php b/app/Libraries/ActivityPub/Activities/AnnounceActivity.php index e9650898..8371f709 100644 --- a/app/Libraries/ActivityPub/Activities/AnnounceActivity.php +++ b/app/Libraries/ActivityPub/Activities/AnnounceActivity.php @@ -18,10 +18,7 @@ use ActivityPub\Entities\Note; class AnnounceActivity extends Activity { - /** - * @var string - */ - protected $type = 'Announce'; + protected string $type = 'Announce'; public function __construct(Note $reblogNote) { diff --git a/app/Libraries/ActivityPub/Activities/CreateActivity.php b/app/Libraries/ActivityPub/Activities/CreateActivity.php index bb479e04..29b63451 100644 --- a/app/Libraries/ActivityPub/Activities/CreateActivity.php +++ b/app/Libraries/ActivityPub/Activities/CreateActivity.php @@ -17,8 +17,5 @@ use ActivityPub\Core\Activity; class CreateActivity extends Activity { - /** - * @var string - */ - protected $type = 'Create'; + protected string $type = 'Create'; } diff --git a/app/Libraries/ActivityPub/Activities/DeleteActivity.php b/app/Libraries/ActivityPub/Activities/DeleteActivity.php index 58483f6e..0ae54017 100644 --- a/app/Libraries/ActivityPub/Activities/DeleteActivity.php +++ b/app/Libraries/ActivityPub/Activities/DeleteActivity.php @@ -17,8 +17,5 @@ use ActivityPub\Core\Activity; class DeleteActivity extends Activity { - /** - * @var string - */ - protected $type = 'Delete'; + protected string $type = 'Delete'; } diff --git a/app/Libraries/ActivityPub/Activities/FollowActivity.php b/app/Libraries/ActivityPub/Activities/FollowActivity.php index b78e0912..78fe9151 100644 --- a/app/Libraries/ActivityPub/Activities/FollowActivity.php +++ b/app/Libraries/ActivityPub/Activities/FollowActivity.php @@ -17,8 +17,5 @@ use ActivityPub\Core\Activity; class FollowActivity extends Activity { - /** - * @var string - */ - protected $type = 'Follow'; + protected string $type = 'Follow'; } diff --git a/app/Libraries/ActivityPub/Activities/LikeActivity.php b/app/Libraries/ActivityPub/Activities/LikeActivity.php index df21cc42..e1789329 100644 --- a/app/Libraries/ActivityPub/Activities/LikeActivity.php +++ b/app/Libraries/ActivityPub/Activities/LikeActivity.php @@ -17,8 +17,5 @@ use ActivityPub\Core\Activity; class LikeActivity extends Activity { - /** - * @var string - */ - protected $type = 'Like'; + protected string $type = 'Like'; } diff --git a/app/Libraries/ActivityPub/Activities/UndoActivity.php b/app/Libraries/ActivityPub/Activities/UndoActivity.php index aa21fd34..ce239394 100644 --- a/app/Libraries/ActivityPub/Activities/UndoActivity.php +++ b/app/Libraries/ActivityPub/Activities/UndoActivity.php @@ -17,8 +17,5 @@ use ActivityPub\Core\Activity; class UndoActivity extends Activity { - /** - * @var string - */ - protected $type = 'Undo'; + protected string $type = 'Undo'; } diff --git a/app/Libraries/ActivityPub/ActivityRequest.php b/app/Libraries/ActivityPub/ActivityRequest.php index a7955976..789684ca 100644 --- a/app/Libraries/ActivityPub/ActivityRequest.php +++ b/app/Libraries/ActivityPub/ActivityRequest.php @@ -18,25 +18,14 @@ use phpseclib\Crypt\RSA; class ActivityRequest { - /** - * @var CURLRequest - */ - protected $request; - - /** - * @var URI - */ - protected $uri; - - /** - * @var Activity|null - */ - protected $activity; + protected CURLRequest $request; + protected URI $uri; + protected ?Activity $activity; /** * @var array */ - protected $options = [ + protected array $options = [ 'headers' => [ 'Content-Type' => 'application/activity+json', 'Accept' => 'application/activity+json', // TODO: outgoing and incoming requests diff --git a/app/Libraries/ActivityPub/Config/ActivityPub.php b/app/Libraries/ActivityPub/Config/ActivityPub.php index 47ae7d3e..45f63fb6 100644 --- a/app/Libraries/ActivityPub/Config/ActivityPub.php +++ b/app/Libraries/ActivityPub/Config/ActivityPub.php @@ -18,43 +18,28 @@ class ActivityPub extends BaseConfig * -------------------------------------------------------------------- * ActivityPub Objects * -------------------------------------------------------------------- - * @var string */ - public $actorObject = ActorObject::class; + public string $actorObject = ActorObject::class; - /** - * @var string - */ - public $noteObject = NoteObject::class; + public string $noteObject = NoteObject::class; /** * -------------------------------------------------------------------- * Default avatar and cover images * -------------------------------------------------------------------- - * @var string */ - public $defaultAvatarImagePath = 'assets/images/avatar-default.jpg'; + public string $defaultAvatarImagePath = 'assets/images/avatar-default.jpg'; - /** - * @var string - */ - public $defaultAvatarImageMimetype = 'image/jpeg'; + public string $defaultAvatarImageMimetype = 'image/jpeg'; - /** - * @var string - */ - public $defaultCoverImagePath = 'assets/images/cover-default.jpg'; + public string $defaultCoverImagePath = 'assets/images/cover-default.jpg'; - /** - * @var string - */ - public $defaultCoverImageMimetype = 'image/jpeg'; + public string $defaultCoverImageMimetype = 'image/jpeg'; /** * -------------------------------------------------------------------- * Cache options * -------------------------------------------------------------------- - * @var string */ - public $cachePrefix = 'ap_'; + public string $cachePrefix = 'ap_'; } diff --git a/app/Libraries/ActivityPub/Controllers/ActorController.php b/app/Libraries/ActivityPub/Controllers/ActorController.php index 671fa56a..a808d1a2 100644 --- a/app/Libraries/ActivityPub/Controllers/ActorController.php +++ b/app/Libraries/ActivityPub/Controllers/ActorController.php @@ -26,15 +26,8 @@ class ActorController extends Controller */ protected $helpers = ['activitypub']; - /** - * @var Actor - */ - protected $actor; - - /** - * @var ActivityPub - */ - protected $config; + protected Actor $actor; + protected ActivityPub $config; public function __construct() { @@ -87,6 +80,7 @@ class ActorController extends Controller ); // switch/case on activity type + /** @phpstan-ignore-next-line */ switch ($payload->type) { case 'Create': if ($payload->object->type == 'Note') { @@ -168,6 +162,7 @@ class ActorController extends Controller return $this->response->setStatusCode(200)->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 diff --git a/app/Libraries/ActivityPub/Controllers/NoteController.php b/app/Libraries/ActivityPub/Controllers/NoteController.php index bea02669..52268929 100644 --- a/app/Libraries/ActivityPub/Controllers/NoteController.php +++ b/app/Libraries/ActivityPub/Controllers/NoteController.php @@ -26,15 +26,8 @@ class NoteController extends Controller */ protected $helpers = ['activitypub']; - /** - * @var Note - */ - protected $note; - - /** - * @var ActivityPub - */ - protected $config; + protected Note $note; + protected ActivityPub $config; public function __construct() { diff --git a/app/Libraries/ActivityPub/Core/Activity.php b/app/Libraries/ActivityPub/Core/Activity.php index ece7239c..bbe8345a 100644 --- a/app/Libraries/ActivityPub/Core/Activity.php +++ b/app/Libraries/ActivityPub/Core/Activity.php @@ -15,18 +15,7 @@ namespace ActivityPub\Core; class Activity extends ObjectType { - /** - * @var string - */ - protected $type = 'Activity'; - - /** - * @var string - */ - protected $actor; - - /** - * @var string|ObjectType - */ - protected $object; + protected string $type = 'Activity'; + protected string $actor; + protected string|ObjectType $object; } diff --git a/app/Libraries/ActivityPub/Core/ObjectType.php b/app/Libraries/ActivityPub/Core/ObjectType.php index caf64e6d..82a476ae 100644 --- a/app/Libraries/ActivityPub/Core/ObjectType.php +++ b/app/Libraries/ActivityPub/Core/ObjectType.php @@ -18,35 +18,19 @@ class ObjectType extends AbstractObject /** * @var string|string[] */ - protected $context = 'https://www.w3.org/ns/activitystreams'; - - /** - * @var string - */ - protected $id; - - /** - * @var string - */ - protected $type = 'Object'; - - /** - * @var string - */ - protected $content; - - /** - * @var string - */ - protected $published; + protected string|array $context = 'https://www.w3.org/ns/activitystreams'; + protected string $id; + protected string $type = 'Object'; + protected string $content; + protected string $published; /** * @var string[] */ - protected $to = ['https://www.w3.org/ns/activitystreams#Public']; + protected array $to = ['https://www.w3.org/ns/activitystreams#Public']; /** * @var string[] */ - protected $cc = []; + protected array $cc = []; } diff --git a/app/Libraries/ActivityPub/Entities/Activity.php b/app/Libraries/ActivityPub/Entities/Activity.php index 54cfc90f..a629b1f4 100644 --- a/app/Libraries/ActivityPub/Entities/Activity.php +++ b/app/Libraries/ActivityPub/Entities/Activity.php @@ -27,20 +27,9 @@ use Michalsn\Uuid\UuidEntity; */ class Activity extends UuidEntity { - /** - * @var Actor - */ - protected $actor; - - /** - * @var Actor|null - */ - protected $target_actor; - - /** - * @var Note|null - */ - protected $note; + protected ?Actor $actor; + protected ?Actor $target_actor; + protected ?Note $note; /** * @var string[] @@ -67,13 +56,13 @@ class Activity extends UuidEntity public function getActor(): Actor { - if (empty($this->actor_id)) { + if ($this->actor_id === null) { throw new RuntimeException( 'Activity must have an actor_id before getting the actor.', ); } - if (empty($this->actor)) { + if ($this->actor === null) { $this->actor = model('ActorModel')->getActorById($this->actor_id); } @@ -82,13 +71,13 @@ class Activity extends UuidEntity public function getTargetActor(): Actor { - if (empty($this->target_actor_id)) { + if ($this->target_actor_id === null) { throw new RuntimeException( 'Activity must have a target_actor_id before getting the target actor.', ); } - if (empty($this->target_actor)) { + if ($this->target_actor === null) { $this->target_actor = model('ActorModel')->getActorById( $this->target_actor_id, ); @@ -99,13 +88,13 @@ class Activity extends UuidEntity public function getNote(): Note { - if (empty($this->note_id)) { + if ($this->note_id === null) { throw new RuntimeException( 'Activity must have a note_id before getting note.', ); } - if (empty($this->note)) { + if ($this->note === null) { $this->note = model('NoteModel')->getNoteById($this->note_id); } diff --git a/app/Libraries/ActivityPub/Entities/Actor.php b/app/Libraries/ActivityPub/Entities/Actor.php index 51215ceb..09fb61ff 100644 --- a/app/Libraries/ActivityPub/Entities/Actor.php +++ b/app/Libraries/ActivityPub/Entities/Actor.php @@ -37,20 +37,13 @@ use CodeIgniter\Entity\Entity; */ class Actor extends Entity { - /** - * @var string - */ - protected $public_key_id; + protected string $public_key_id; /** * @var Actor[] */ - protected $followers = []; - - /** - * @var boolean - */ - protected $is_local = false; + protected ?array $followers = null; + protected bool $is_local = false; /** * @var array @@ -100,13 +93,13 @@ class Actor extends Entity */ public function getFollowers(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Actor must be created before getting followers.', ); } - if (empty($this->followers)) { + if ($this->followers === null) { $this->followers = (array) model('ActorModel')->getFollowers( $this->id, ); @@ -117,7 +110,7 @@ class Actor extends Entity public function getAvatarImageUrl(): string { - if (empty($this->attributes['avatar_image_url'])) { + if ($this->attributes['avatar_image_url'] === null) { return base_url(config('ActivityPub')->defaultAvatarImagePath); } @@ -126,7 +119,7 @@ class Actor extends Entity public function getAvatarImageMimetype(): string { - if (empty($this->attributes['avatar_image_mimetype'])) { + if ($this->attributes['avatar_image_mimetype'] === null) { return config('ActivityPub')->defaultAvatarImageMimetype; } @@ -135,7 +128,7 @@ class Actor extends Entity public function getCoverImageUrl(): string { - if (empty($this->attributes['cover_image_url'])) { + if ($this->attributes['cover_image_url'] === null) { return base_url(config('ActivityPub')->defaultCoverImagePath); } @@ -144,7 +137,7 @@ class Actor extends Entity public function getCoverImageMimetype(): string { - if (empty($this->attributes['cover_image_mimetype'])) { + if ($this->attributes['cover_image_mimetype'] === null) { return config('ActivityPub')->defaultCoverImageMimetype; } diff --git a/app/Libraries/ActivityPub/Entities/Note.php b/app/Libraries/ActivityPub/Entities/Note.php index 484fc3dd..a99a934d 100644 --- a/app/Libraries/ActivityPub/Entities/Note.php +++ b/app/Libraries/ActivityPub/Entities/Note.php @@ -40,55 +40,25 @@ use Michalsn\Uuid\UuidEntity; */ class Note extends UuidEntity { - /** - * @var Actor - */ - protected $actor; + protected ?Actor $actor = null; + protected bool $is_reply = false; + protected ?Note $reply_to_note = null; + protected bool $is_reblog = false; + protected ?Note $reblog_of_note = null; + protected ?PreviewCard $preview_card = null; + protected bool $has_preview_card = false; /** - * @var boolean + * @var Note[]|null */ - protected $is_reply = false; + protected ?array $replies = null; + + protected bool $has_replies = false; /** - * @var Note + * @var Note[]|null */ - protected $reply_to_note; - - /** - * @var boolean - */ - protected $is_reblog = false; - - /** - * @var Note - */ - protected $reblog_of_note; - - /** - * @var PreviewCard|null - */ - protected $preview_card; - - /** - * @var boolean - */ - protected $has_preview_card = false; - - /** - * @var Note[] - */ - protected $replies = []; - - /** - * @var boolean - */ - protected $has_replies = false; - - /** - * @var Note[] - */ - protected $reblogs = []; + protected ?array $reblogs = null; /** * @var string[] @@ -121,13 +91,13 @@ class Note extends UuidEntity */ public function getActor(): Actor { - if (empty($this->actor_id)) { + if ($this->actor_id === null) { throw new RuntimeException( 'Note must have an actor_id before getting actor.', ); } - if (empty($this->actor)) { + if ($this->actor === null) { $this->actor = model('ActorModel')->getActorById($this->actor_id); } @@ -136,13 +106,13 @@ class Note extends UuidEntity public function getPreviewCard(): ?PreviewCard { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Note must be created before getting preview_card.', ); } - if (empty($this->preview_card)) { + if ($this->preview_card === null) { $this->preview_card = model('PreviewCardModel')->getNotePreviewCard( $this->id, ); @@ -153,7 +123,7 @@ class Note extends UuidEntity public function getHasPreviewCard(): bool { - return !empty($this->getPreviewCard()); + return $this->getPreviewCard() !== null; } public function getIsReply(): bool @@ -168,13 +138,13 @@ class Note extends UuidEntity */ public function getReplies(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Note must be created before getting replies.', ); } - if (empty($this->replies)) { + if ($this->replies === null) { $this->replies = (array) model('NoteModel')->getNoteReplies( $this->id, ); @@ -185,16 +155,16 @@ class Note extends UuidEntity public function getHasReplies(): bool { - return !empty($this->getReplies()); + return $this->getReplies() !== null; } public function getReplyToNote(): Note { - if (empty($this->in_reply_to_id)) { + if ($this->in_reply_to_id === null) { throw new RuntimeException('Note is not a reply.'); } - if (empty($this->reply_to_note)) { + if ($this->reply_to_note === null) { $this->reply_to_note = model('NoteModel')->getNoteById( $this->in_reply_to_id, ); @@ -208,13 +178,13 @@ class Note extends UuidEntity */ public function getReblogs(): array { - if (empty($this->id)) { + if ($this->id === null) { throw new RuntimeException( 'Note must be created before getting reblogs.', ); } - if (empty($this->reblogs)) { + if ($this->reblogs === null) { $this->reblogs = (array) model('NoteModel')->getNoteReblogs( $this->id, ); @@ -230,11 +200,11 @@ class Note extends UuidEntity public function getReblogOfNote(): Note { - if (empty($this->reblog_of_id)) { + if ($this->reblog_of_id === null) { throw new RuntimeException('Note is not a reblog.'); } - if (empty($this->reblog_of_note)) { + if ($this->reblog_of_note === null) { $this->reblog_of_note = model('NoteModel')->getNoteById( $this->reblog_of_id, ); diff --git a/app/Libraries/ActivityPub/Filters/ActivityPubFilter.php b/app/Libraries/ActivityPub/Filters/ActivityPubFilter.php index 73559417..6eb5c4bf 100644 --- a/app/Libraries/ActivityPub/Filters/ActivityPubFilter.php +++ b/app/Libraries/ActivityPub/Filters/ActivityPubFilter.php @@ -28,7 +28,7 @@ class ActivityPubFilter implements FilterInterface */ public function before(RequestInterface $request, $params = null) { - if (empty($params)) { + if ($params === null) { return; } @@ -40,8 +40,7 @@ class ActivityPubFilter implements FilterInterface 'application/activity+json', ]; - if (empty($negotiate->media($allowedContentTypes))) { - // return $this->response->setStatusCode(415)->setJSON([]); + if ($negotiate->media($allowedContentTypes) === '') { throw PageNotFoundException::forPageNotFound(); } } diff --git a/app/Libraries/ActivityPub/Helpers/activitypub_helper.php b/app/Libraries/ActivityPub/Helpers/activitypub_helper.php index abb73622..167d9925 100644 --- a/app/Libraries/ActivityPub/Helpers/activitypub_helper.php +++ b/app/Libraries/ActivityPub/Helpers/activitypub_helper.php @@ -361,6 +361,7 @@ if (!function_exists('linkify')) { // Extract text links for each protocol foreach ($protocols as $protocol) { + /** @phpstan-ignore-next-line */ switch ($protocol) { case 'http': case 'https': diff --git a/app/Libraries/ActivityPub/Models/NoteModel.php b/app/Libraries/ActivityPub/Models/NoteModel.php index 01c09884..037f34c2 100644 --- a/app/Libraries/ActivityPub/Models/NoteModel.php +++ b/app/Libraries/ActivityPub/Models/NoteModel.php @@ -238,7 +238,7 @@ class NoteModel extends UuidModel $messageUrls = extract_urls_from_message($note->message); if ( - !empty($messageUrls) && + $messageUrls !== [] && ($previewCard = get_or_create_preview_card_from_url( new URI($messageUrls[0]), )) && diff --git a/app/Libraries/ActivityPub/Objects/ActorObject.php b/app/Libraries/ActivityPub/Objects/ActorObject.php index 20cc9cb8..21677056 100644 --- a/app/Libraries/ActivityPub/Objects/ActorObject.php +++ b/app/Libraries/ActivityPub/Objects/ActorObject.php @@ -16,65 +16,34 @@ class ActorObject extends ObjectType /** * @var string|string[] */ - protected $context = [ + protected string|array $context = [ 'https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ]; - /** - * @var string - */ - protected $type = 'Person'; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $preferredUsername; - - /** - * @var string - */ - protected $summary; - - /** - * @var string - */ - protected $inbox; - - /** - * @var string - */ - protected $outbox; - - /** - * @var string - */ - protected $followers; - - /** - * @var string - */ - protected $url; - - /** - * @var array|null - */ - protected $image; + protected string $type = 'Person'; + protected string $name; + protected string $preferredUsername; + protected string $summary; + protected string $inbox; + protected string $outbox; + protected string $followers; + protected string $url; /** * @var array */ - protected $icon = []; + protected array $image = []; /** * @var array */ - protected $publicKey = []; + protected array $icon = []; + + /** + * @var array + */ + protected array $publicKey = []; public function __construct(Actor $actor) { diff --git a/app/Libraries/ActivityPub/Objects/NoteObject.php b/app/Libraries/ActivityPub/Objects/NoteObject.php index 2a433927..b6ebbed7 100644 --- a/app/Libraries/ActivityPub/Objects/NoteObject.php +++ b/app/Libraries/ActivityPub/Objects/NoteObject.php @@ -18,25 +18,10 @@ use ActivityPub\Core\ObjectType; class NoteObject extends ObjectType { - /** - * @var string - */ - protected $type = 'Note'; - - /** - * @var string - */ - protected $attributedTo; - - /** - * @var string - */ - protected $inReplyTo; - - /** - * @var string - */ - protected $replies; + protected string $type = 'Note'; + protected string $attributedTo; + protected string $inReplyTo; + protected string $replies; public function __construct(Note $note) { diff --git a/app/Libraries/ActivityPub/Objects/OrderedCollectionObject.php b/app/Libraries/ActivityPub/Objects/OrderedCollectionObject.php index e407965a..024ab7c0 100644 --- a/app/Libraries/ActivityPub/Objects/OrderedCollectionObject.php +++ b/app/Libraries/ActivityPub/Objects/OrderedCollectionObject.php @@ -16,30 +16,11 @@ use ActivityPub\Core\ObjectType; class OrderedCollectionObject extends ObjectType { - /** - * @var string - */ - protected $type = 'OrderedCollection'; - - /** - * @var integer - */ - protected $totalItems; - - /** - * @var string|null - */ - protected $first; - - /** - * @var string|null - */ - protected $current; - - /** - * @var string|null - */ - protected $last; + protected string $type = 'OrderedCollection'; + protected int $totalItems; + protected ?string $first; + protected ?string $current; + protected ?string $last; /** * @param ObjectType[] $orderedItems diff --git a/app/Libraries/ActivityPub/Objects/OrderedCollectionPage.php b/app/Libraries/ActivityPub/Objects/OrderedCollectionPage.php index dfa237d0..89d95075 100644 --- a/app/Libraries/ActivityPub/Objects/OrderedCollectionPage.php +++ b/app/Libraries/ActivityPub/Objects/OrderedCollectionPage.php @@ -14,25 +14,10 @@ namespace ActivityPub\Objects; use CodeIgniter\Pager\Pager; class OrderedCollectionPage extends OrderedCollectionObject { - /** - * @var string - */ - protected $type = 'OrderedCollectionPage'; - - /** - * @var string - */ - protected $partOf; - - /** - * @var string|null - */ - protected $prev; - - /** - * @var string|null - */ - protected $next; + protected string $type = 'OrderedCollectionPage'; + protected string $partOf; + protected ?string $prev; + protected ?string $next; public function __construct(Pager $pager, ?array $orderedItems = null) { diff --git a/app/Libraries/ActivityPub/Objects/TombstoneObject.php b/app/Libraries/ActivityPub/Objects/TombstoneObject.php index a29bdd7a..5f4a5ea6 100644 --- a/app/Libraries/ActivityPub/Objects/TombstoneObject.php +++ b/app/Libraries/ActivityPub/Objects/TombstoneObject.php @@ -12,8 +12,5 @@ use ActivityPub\Core\ObjectType; class TombstoneObject extends ObjectType { - /** - * @var string - */ - protected $type = 'Tombstone'; + protected string $type = 'Tombstone'; } diff --git a/app/Libraries/ActivityPub/WebFinger.php b/app/Libraries/ActivityPub/WebFinger.php index 09113f92..108564e3 100644 --- a/app/Libraries/ActivityPub/WebFinger.php +++ b/app/Libraries/ActivityPub/WebFinger.php @@ -17,35 +17,20 @@ class WebFinger */ const RESOURCE_PATTERN = '/^acct:(?P([\w_]+))@(?P([\w\-\.]+[\w]+)(:[\d]+)?)$/x'; - /** - * @var string - */ - protected $username; - - /** - * @var string - */ - protected $domain; - - /** - * @var string - */ - protected $host; - - /** - * @var string - */ - protected $port; + protected string $username; + protected string $domain; + protected string $host; + protected string $port; /** * @var string[] */ - protected $aliases = []; + protected array $aliases = []; /** * @var array> */ - protected $links = []; + protected array $links = []; public function __construct(protected string $subject) { diff --git a/app/Libraries/Analytics/AnalyticsTrait.php b/app/Libraries/Analytics/AnalyticsTrait.php index 0e05b9ed..3b9ac209 100644 --- a/app/Libraries/Analytics/AnalyticsTrait.php +++ b/app/Libraries/Analytics/AnalyticsTrait.php @@ -29,11 +29,12 @@ trait AnalyticsTrait $db = Database::connect(); $referer = $session->get('referer'); - $domain = empty(parse_url($referer, PHP_URL_HOST)) - ? '- Direct -' - : parse_url($referer, PHP_URL_HOST); + $domain = + parse_url($referer, PHP_URL_HOST) === null + ? '- Direct -' + : parse_url($referer, PHP_URL_HOST); parse_str(parse_url($referer, PHP_URL_QUERY), $queries); - $keywords = empty($queries['q']) ? null : $queries['q']; + $keywords = array_key_exists('q', $queries) ? null : $queries['q']; $procedureName = $db->prefixTable('analytics_website'); $db->query("call {$procedureName}(?,?,?,?,?,?)", [ diff --git a/app/Libraries/Analytics/Config/Analytics.php b/app/Libraries/Analytics/Config/Analytics.php index 7b00ebb4..f4e29c52 100644 --- a/app/Libraries/Analytics/Config/Analytics.php +++ b/app/Libraries/Analytics/Config/Analytics.php @@ -9,10 +9,8 @@ class Analytics extends BaseConfig /** * Gateway to analytic routes. * By default, all analytics routes will be under `/analytics` path - * - * @var string */ - public $gateway = 'analytics'; + public string $gateway = 'analytics'; /** * -------------------------------------------------------------------- @@ -20,7 +18,7 @@ class Analytics extends BaseConfig * -------------------------------------------------------------------- * @var array */ - public $routeFilters = [ + public array $routeFilters = [ 'analytics-full-data' => '', 'analytics-data' => '', 'analytics-filtered-data' => '', diff --git a/app/Libraries/Analytics/Controllers/AnalyticsController.php b/app/Libraries/Analytics/Controllers/AnalyticsController.php index 40c04783..63a06290 100644 --- a/app/Libraries/Analytics/Controllers/AnalyticsController.php +++ b/app/Libraries/Analytics/Controllers/AnalyticsController.php @@ -11,31 +11,25 @@ namespace Analytics\Controllers; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Controller; +use CodeIgniter\Model; class AnalyticsController extends Controller { - /** - * @var string - */ - protected $className; - - /** - * @var string - */ - protected $methodName; + protected Model $analyticsModel; + protected string $methodName = ''; public function _remap(string $method, string ...$params): mixed { - if (!isset($params[1])) { + if (count($params) < 2) { throw PageNotFoundException::forPageNotFound(); } - $this->className = model('Analytics' . $params[1] . 'Model'); - $this->methodName = 'getData' . (empty($params[2]) ? '' : $params[2]); + $this->analyticsModel = model('Analytics' . $params[1] . 'Model'); + $this->methodName = 'getData' . (count($params) >= 3 ? $params[2] : ''); return $this->$method( $params[0], - isset($params[3]) ? $params[3] : null, + count($params) >= 4 ? $params[3] : null, ); } @@ -43,17 +37,16 @@ class AnalyticsController extends Controller int $podcastId, ?int $episodeId = null ): ResponseInterface { - $analyticsModel = new $this->className(); $methodName = $this->methodName; if ($episodeId === null) { return $this->response->setJSON( - $analyticsModel->$methodName($podcastId), + $this->analyticsModel->$methodName($podcastId), ); } return $this->response->setJSON( - $analyticsModel->$methodName($podcastId, $episodeId), + $this->analyticsModel->$methodName($podcastId, $episodeId), ); } } diff --git a/app/Libraries/Analytics/Controllers/EpisodeAnalyticsController.php b/app/Libraries/Analytics/Controllers/EpisodeAnalyticsController.php index 5c02415e..5efab3cc 100644 --- a/app/Libraries/Analytics/Controllers/EpisodeAnalyticsController.php +++ b/app/Libraries/Analytics/Controllers/EpisodeAnalyticsController.php @@ -27,10 +27,8 @@ class EpisodeAnalyticsController extends Controller */ protected $helpers = ['analytics']; - /** - * @var Analytics - */ - protected $config; + protected Analytics $config; + /** * Constructor. */ @@ -65,7 +63,7 @@ class EpisodeAnalyticsController extends Controller $serviceName = ''; if (isset($_GET['_from'])) { $serviceName = $_GET['_from']; - } elseif (!empty($session->get('embeddable_player_domain'))) { + } elseif ($session->get('embeddable_player_domain') !== null) { $serviceName = $session->get('embeddable_player_domain'); } elseif ($session->get('referer') !== '- Direct -') { $serviceName = parse_url($session->get('referer'), PHP_URL_HOST); diff --git a/app/Libraries/Analytics/Controllers/EpisodeController.php b/app/Libraries/Analytics/Controllers/EpisodeController.php index ec531e16..fe03ec5a 100644 --- a/app/Libraries/Analytics/Controllers/EpisodeController.php +++ b/app/Libraries/Analytics/Controllers/EpisodeController.php @@ -22,15 +22,8 @@ class EpisodeController extends BaseController { use AnalyticsTrait; - /** - * @var Podcast - */ - protected $podcast; - - /** - * @var Episode - */ - protected $episode; + protected Podcast $podcast; + protected Episode $episode; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Libraries/Analytics/Helpers/analytics_helper.php b/app/Libraries/Analytics/Helpers/analytics_helper.php index ed2cec5f..02e5382c 100644 --- a/app/Libraries/Analytics/Helpers/analytics_helper.php +++ b/app/Libraries/Analytics/Helpers/analytics_helper.php @@ -1,6 +1,5 @@ city($_SERVER['REMOTE_ADDR']); $location = [ - 'countryCode' => empty($city->country->isoCode) + 'countryCode' => $city->country->isoCode === null ? 'N/A' : $city->country->isoCode, - 'regionCode' => empty($city->subdivisions[0]->isoCode) + 'regionCode' => $city->subdivisions[0]->isoCode === null ? 'N/A' : $city->subdivisions[0]->isoCode, 'latitude' => round($city->location->latitude, 3), @@ -330,10 +329,10 @@ if (!function_exists('podcast_hit')) { $ranges = explode(',', substr($httpRange, 6)); foreach ($ranges as $range) { $parts = explode('-', $range); - $downloadedBytes += empty($parts[1]) + $downloadedBytes += array_key_exists(1, $parts) ? $fileSize : (int) $parts[1] - - (empty($parts[0]) ? 0 : (int) $parts[0]); + (array_key_exists(0, $parts) ? 0 : (int) $parts[0]); } } // We save the number of downloaded bytes for this user and this episode: diff --git a/app/Libraries/Breadcrumb.php b/app/Libraries/Breadcrumb.php index 68d76bf0..42682bfe 100644 --- a/app/Libraries/Breadcrumb.php +++ b/app/Libraries/Breadcrumb.php @@ -22,7 +22,7 @@ class Breadcrumb * * @var array> */ - protected $links = []; + protected array $links = []; /** * Initializes the Breadcrumb object using the segments from diff --git a/app/Libraries/PodcastActor.php b/app/Libraries/PodcastActor.php index e926e823..b419ac89 100644 --- a/app/Libraries/PodcastActor.php +++ b/app/Libraries/PodcastActor.php @@ -14,10 +14,7 @@ use App\Models\PodcastModel; class PodcastActor extends ActorObject { - /** - * @var string - */ - protected $rss; + protected string $rss; public function __construct(Actor $actor) { diff --git a/app/Libraries/Router.php b/app/Libraries/Router.php index dc41fa9b..0eb7e0f8 100644 --- a/app/Libraries/Router.php +++ b/app/Libraries/Router.php @@ -36,7 +36,7 @@ class Router extends CodeIgniterRouter ); // Don't waste any time - if (empty($routes)) { + if ($routes === []) { return false; } @@ -178,10 +178,7 @@ class Router extends CodeIgniterRouter str_replace('/', '\\', $replacekey), $val, ); - } elseif ( - str_contains($val, '$') && - str_contains($key, '(') - ) { + } elseif (str_contains($val, '$') && str_contains($key, '(')) { $val = preg_replace('#^' . $key . '$#u', $val, $uri); } elseif (str_contains($val, '/')) { [$controller, $method] = explode('::', $val); diff --git a/app/Models/CategoryModel.php b/app/Models/CategoryModel.php index d827fcd5..acf9793c 100644 --- a/app/Models/CategoryModel.php +++ b/app/Models/CategoryModel.php @@ -83,11 +83,11 @@ class CategoryModel extends Model /** * Sets categories for a given podcast * - * @param int[] $categories + * @param int[] $categoriesIds * * @return int|false Number of rows inserted or FALSE on failure */ - public function setPodcastCategories(int $podcastId, array $categories): int|false + public function setPodcastCategories(int $podcastId, array $categoriesIds = []): int|false { cache()->delete("podcast#{$podcastId}_categories"); @@ -96,14 +96,14 @@ class CategoryModel extends Model ->table('podcasts_categories') ->delete(['podcast_id' => $podcastId]); - if (empty($categories)) { + if ($categoriesIds === []) { // no row has been inserted after deletion return 0; } // prepare data for `podcasts_categories` table $data = array_reduce( - $categories, + $categoriesIds, function (array $result, int $categoryId) use ($podcastId): array { $result[] = [ 'podcast_id' => $podcastId, diff --git a/app/Models/PersonModel.php b/app/Models/PersonModel.php index d7ce0be8..3aaf42eb 100644 --- a/app/Models/PersonModel.php +++ b/app/Models/PersonModel.php @@ -100,7 +100,7 @@ class PersonModel extends Model } /** - * @return stdClass[] + * @return object[] */ public function getPersonRoles(int $personId, int $podcastId, ?int $episodeId): array { if ($episodeId) { @@ -276,7 +276,7 @@ class PersonModel extends Model * Add persons to podcast * * @param array $persons - * @param array $groupsRoles + * @param array $roles * * @return bool|int Number of rows inserted or FALSE on failure */ @@ -342,7 +342,7 @@ class PersonModel extends Model array $personIds, array $groupsRoles ): bool|int { - if (!empty($personIds)) { + if ($personIds !== []) { (new EpisodeModel())->clearCache(['id' => $episodeId]); $data = []; diff --git a/app/Models/PodcastModel.php b/app/Models/PodcastModel.php index dddcc5e0..0f7fc221 100644 --- a/app/Models/PodcastModel.php +++ b/app/Models/PodcastModel.php @@ -93,29 +93,29 @@ class PodcastModel extends Model 'created_by' => 'required', 'updated_by' => 'required', ]; - /** - * @var mixed[] - */ - protected $validationMessages = []; /** * @var string[] */ protected $beforeInsert = ['createPodcastActor']; + /** * @var string[] */ protected $afterInsert = ['setActorAvatar']; + /** * @var string[] */ protected $afterUpdate = ['updatePodcastActor']; - // clear cache before update if by any chance, the podcast name changes, so will the podcast link /** + * clear cache before update if by any chance, the podcast name changes, so will the podcast link + * * @var string[] */ protected $beforeUpdate = ['clearCache']; + /** * @var string[] */ @@ -336,7 +336,7 @@ class PodcastModel extends Model if (!($defaultQuery = cache($cacheName))) { $seasons = $this->getSeasons($podcastId); - if (!empty($seasons)) { + if ($seasons !== []) { // get latest season $defaultQuery = ['type' => 'season', 'data' => end($seasons)]; } else { @@ -348,6 +348,34 @@ class PodcastModel extends Model } return $defaultQuery; } + /** + * @param mixed[] $data + * + * @return mixed[] + */ + public function clearCache(array $data): array + { + $podcast = (new PodcastModel())->getPodcastById( + is_array($data['id']) ? $data['id'][0] : $data['id'], + ); + + // delete cache all podcast pages + cache()->deleteMatching("page_podcast#{$podcast->id}*"); + + // delete all cache for podcast actor + cache()->deleteMatching( + config('ActivityPub')->cachePrefix . "actor#{$podcast->actor_id}*", + ); + + // delete model requests cache, includes feed / query / episode lists, etc. + cache()->deleteMatching("podcast#{$podcast->id}*"); + cache()->delete("podcast-{$podcast->name}"); + + // clear cache for every credit page + cache()->deleteMatching('page_credits_*'); + + return $data; + } /** * Creates an actor linked to the podcast @@ -440,33 +468,4 @@ class PodcastModel extends Model return $data; } - - /** - * @param mixed[] $data - * - * @return mixed[] - */ - public function clearCache(array $data): array - { - $podcast = (new PodcastModel())->getPodcastById( - is_array($data['id']) ? $data['id'][0] : $data['id'], - ); - - // delete cache all podcast pages - cache()->deleteMatching("page_podcast#{$podcast->id}*"); - - // delete all cache for podcast actor - cache()->deleteMatching( - config('ActivityPub')->cachePrefix . "actor#{$podcast->actor_id}*", - ); - - // delete model requests cache, includes feed / query / episode lists, etc. - cache()->deleteMatching("podcast#{$podcast->id}*"); - cache()->delete("podcast-{$podcast->name}"); - - // clear cache for every credit page - cache()->deleteMatching('page_credits_*'); - - return $data; - } } diff --git a/app/Views/admin/episode/soundbites.php b/app/Views/admin/episode/soundbites.php index 462fa1a0..dc1c2362 100644 --- a/app/Views/admin/episode/soundbites.php +++ b/app/Views/admin/episode/soundbites.php @@ -148,7 +148,6 @@ 'data-soundbite-id' => '0', 'data-type' => 'soundbite-field', 'data-field-type' => 'duration', - 'min' => '0', ], ) ?> section('content') ?>