From efc5c57a79a5bad9b91135a436c1eca717082968 Mon Sep 17 00:00:00 2001 From: J0WI Date: Mon, 26 Apr 2021 12:33:36 +0200 Subject: [PATCH 1/4] Some more strict_types Signed-off-by: J0WI --- lib/autoloader.php | 8 ++--- lib/private/Updater.php | 27 +++++++++------- lib/public/AutoloadNotAllowedException.php | 3 ++ lib/public/Constants.php | 3 ++ lib/public/Defaults.php | 37 ++++++++++++---------- lib/public/PreConditionNotMetException.php | 3 ++ lib/versioncheck.php | 3 ++ 7 files changed, 51 insertions(+), 33 deletions(-) diff --git a/lib/autoloader.php b/lib/autoloader.php index cf25f4498a..b37e20c237 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -68,7 +68,7 @@ class Autoloader { * * @param string $root */ - public function addValidRoot(string $root) { + public function addValidRoot(string $root): void { $root = stream_resolve_include_path($root); $this->validRoots[$root] = true; } @@ -76,14 +76,14 @@ class Autoloader { /** * disable the usage of the global classpath \OC::$CLASSPATH */ - public function disableGlobalClassPath() { + public function disableGlobalClassPath(): void { $this->useGlobalClassPath = false; } /** * enable the usage of the global classpath \OC::$CLASSPATH */ - public function enableGlobalClassPath() { + public function enableGlobalClassPath(): void { $this->useGlobalClassPath = true; } @@ -184,7 +184,7 @@ class Autoloader { * * @param \OC\Memcache\Cache $memoryCache Instance of memory cache. */ - public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null) { + public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null): void { $this->memoryCache = $memoryCache; } } diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 78c652b6ee..4fc6fd5799 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -1,4 +1,7 @@ @@ -101,7 +104,7 @@ class Updater extends BasicEmitter { * * @return bool true if the operation succeeded, false otherwise */ - public function upgrade() { + public function upgrade(): bool { $this->emitRepairEvents(); $this->logAllEvents(); @@ -162,7 +165,7 @@ class Updater extends BasicEmitter { * * @return array allowed previous versions per vendor */ - private function getAllowedPreviousVersions() { + private function getAllowedPreviousVersions(): array { // this should really be a JSON file require \OC::$SERVERROOT . '/version.php'; /** @var array $OC_VersionCanBeUpgradedFrom */ @@ -174,7 +177,7 @@ class Updater extends BasicEmitter { * * @return string Get the vendor */ - private function getVendor() { + private function getVendor(): string { // this should really be a JSON file require \OC::$SERVERROOT . '/version.php'; /** @var string $vendor */ @@ -188,7 +191,7 @@ class Updater extends BasicEmitter { * @param array $allowedPreviousVersions * @return bool */ - public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { + public function isUpgradePossible(string $oldVersion, string $newVersion, array $allowedPreviousVersions): bool { $version = explode('.', $oldVersion); $majorMinor = $version[0] . '.' . $version[1]; @@ -223,7 +226,7 @@ class Updater extends BasicEmitter { * * @throws \Exception */ - private function doUpgrade($currentVersion, $installedVersion) { + private function doUpgrade(string $currentVersion, string $installedVersion): void { // Stop update if the update is over several major versions $allowedPreviousVersions = $this->getAllowedPreviousVersions(); if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { @@ -295,7 +298,7 @@ class Updater extends BasicEmitter { $this->config->setAppValue('core', 'vendor', $this->getVendor()); } - protected function doCoreUpgrade() { + protected function doCoreUpgrade(): void { $this->emit('\OC\Updater', 'dbUpgradeBefore'); // execute core migrations @@ -311,7 +314,7 @@ class Updater extends BasicEmitter { * * @throws NeedsUpdateException */ - protected function doAppUpgrade() { + protected function doAppUpgrade(): void { $apps = \OC_App::getEnabledApps(); $priorityTypes = ['authentication', 'filesystem', 'logging']; $pseudoOtherType = 'other'; @@ -360,7 +363,7 @@ class Updater extends BasicEmitter { * @return array * @throws \Exception */ - private function checkAppsRequirements() { + private function checkAppsRequirements(): array { $isCoreUpgrade = $this->isCodeUpgrade(); $apps = OC_App::getEnabledApps(); $version = implode('.', Util::getVersion()); @@ -395,7 +398,7 @@ class Updater extends BasicEmitter { /** * @return bool */ - private function isCodeUpgrade() { + private function isCodeUpgrade(): bool { $installedVersion = $this->config->getSystemValue('version', '0.0.0'); $currentVersion = implode('.', Util::getVersion()); if (version_compare($currentVersion, $installedVersion, '>')) { @@ -409,7 +412,7 @@ class Updater extends BasicEmitter { * @param bool $reenable * @throws \Exception */ - private function upgradeAppStoreApps(array $disabledApps, $reenable = false) { + private function upgradeAppStoreApps(array $disabledApps, bool $reenable = false): void { foreach ($disabledApps as $app) { try { $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); @@ -432,7 +435,7 @@ class Updater extends BasicEmitter { /** * Forward messages emitted by the repair routine */ - private function emitRepairEvents() { + private function emitRepairEvents(): void { $dispatcher = \OC::$server->getEventDispatcher(); $dispatcher->addListener('\OC\Repair::warning', function ($event) { if ($event instanceof GenericEvent) { @@ -456,7 +459,7 @@ class Updater extends BasicEmitter { }); } - private function logAllEvents() { + private function logAllEvents(): void { $log = $this->log; $dispatcher = \OC::$server->getEventDispatcher(); diff --git a/lib/public/AutoloadNotAllowedException.php b/lib/public/AutoloadNotAllowedException.php index 9d41315c32..6608e1739c 100644 --- a/lib/public/AutoloadNotAllowedException.php +++ b/lib/public/AutoloadNotAllowedException.php @@ -1,4 +1,7 @@ defaults->getBaseUrl(); } @@ -74,7 +77,7 @@ class Defaults { * @return string * @since 6.0.0 */ - public function getSyncClientUrl() { + public function getSyncClientUrl(): string { return $this->defaults->getSyncClientUrl(); } @@ -83,7 +86,7 @@ class Defaults { * @return string * @since 8.0.0 */ - public function getiOSClientUrl() { + public function getiOSClientUrl(): string { return $this->defaults->getiOSClientUrl(); } @@ -92,7 +95,7 @@ class Defaults { * @return string * @since 8.0.0 */ - public function getAndroidClientUrl() { + public function getAndroidClientUrl(): string { return $this->defaults->getAndroidClientUrl(); } @@ -101,7 +104,7 @@ class Defaults { * @return string * @since 6.0.0 */ - public function getDocBaseUrl() { + public function getDocBaseUrl(): string { return $this->defaults->getDocBaseUrl(); } @@ -110,7 +113,7 @@ class Defaults { * @return string * @since 6.0.0 */ - public function getName() { + public function getName(): string { return $this->defaults->getName(); } @@ -120,7 +123,7 @@ class Defaults { * @since 8.0.0 * @depreacted 22.0.0 */ - public function getHTMLName() { + public function getHTMLName(): string { return $this->defaults->getHTMLName(); } @@ -129,7 +132,7 @@ class Defaults { * @return string * @since 6.0.0 */ - public function getEntity() { + public function getEntity(): string { return $this->defaults->getEntity(); } @@ -138,7 +141,7 @@ class Defaults { * @return string * @since 6.0.0 */ - public function getSlogan(?string $lang = null) { + public function getSlogan(?string $lang = null): string { return $this->defaults->getSlogan($lang); } @@ -147,7 +150,7 @@ class Defaults { * @return string * @since 6.0.0 */ - public function getShortFooter() { + public function getShortFooter(): string { return $this->defaults->getShortFooter(); } @@ -156,7 +159,7 @@ class Defaults { * @return string * @since 6.0.0 */ - public function getLongFooter() { + public function getLongFooter(): string { return $this->defaults->getLongFooter(); } @@ -165,7 +168,7 @@ class Defaults { * @return string AppId * @since 8.0.0 */ - public function getiTunesAppId() { + public function getiTunesAppId(): string { return $this->defaults->getiTunesAppId(); } @@ -176,7 +179,7 @@ class Defaults { * @return string * @since 12.0.0 */ - public function getLogo($useSvg = true) { + public function getLogo(bool $useSvg = true): string { return $this->defaults->getLogo($useSvg); } @@ -185,7 +188,7 @@ class Defaults { * @return string * @since 12.0.0 */ - public function getColorPrimary() { + public function getColorPrimary(): string { return $this->defaults->getColorPrimary(); } @@ -194,7 +197,7 @@ class Defaults { * @return string URL to doc with key * @since 12.0.0 */ - public function buildDocLinkToKey($key) { + public function buildDocLinkToKey(string $key): string { return $this->defaults->buildDocLinkToKey($key); } @@ -203,7 +206,7 @@ class Defaults { * @return string title * @since 12.0.0 */ - public function getTitle() { + public function getTitle(): string { return $this->defaults->getTitle(); } @@ -212,7 +215,7 @@ class Defaults { * @return string * @since 13.0.0 */ - public function getTextColorPrimary() { + public function getTextColorPrimary(): string { return $this->defaults->getTextColorPrimary(); } } diff --git a/lib/public/PreConditionNotMetException.php b/lib/public/PreConditionNotMetException.php index 1871a16088..f48ac01ade 100644 --- a/lib/public/PreConditionNotMetException.php +++ b/lib/public/PreConditionNotMetException.php @@ -1,4 +1,7 @@ Date: Mon, 26 Apr 2021 12:44:05 +0200 Subject: [PATCH 2/4] Fix ini_set() type Signed-off-by: J0WI --- lib/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index 7e3f6d9567..9575f39626 100644 --- a/lib/base.php +++ b/lib/base.php @@ -404,7 +404,7 @@ class OC { public static function initSession() { if (self::$server->getRequest()->getServerProtocol() === 'https') { - ini_set('session.cookie_secure', true); + ini_set('session.cookie_secure', 'true'); } // prevents javascript from accessing php session cookies From d1f23b0428c04f8710987bb30183d8c7cc6d3261 Mon Sep 17 00:00:00 2001 From: J0WI Date: Mon, 26 Apr 2021 12:44:37 +0200 Subject: [PATCH 3/4] core: add more strict_types Signed-off-by: J0WI --- core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php | 3 +++ core/BackgroundJobs/CheckForUserCertificates.php | 5 ++++- core/BackgroundJobs/CleanupLoginFlowV2.php | 2 +- core/register_command.php | 3 +++ core/routes.php | 3 +++ core/strings.php | 3 +++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php b/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php index 44a14352cd..ee476633a9 100644 --- a/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php +++ b/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php @@ -1,4 +1,7 @@ * diff --git a/core/BackgroundJobs/CheckForUserCertificates.php b/core/BackgroundJobs/CheckForUserCertificates.php index 8b106c8ce7..d8892e03b5 100644 --- a/core/BackgroundJobs/CheckForUserCertificates.php +++ b/core/BackgroundJobs/CheckForUserCertificates.php @@ -1,4 +1,7 @@ * @@ -49,7 +52,7 @@ class CheckForUserCertificates extends QueuedJob { /** * Checks all user directories for old user uploaded certificates */ - public function run($arguments) { + public function run($arguments): void { $uploadList = []; $this->userManager->callForSeenUsers(function (IUser $user) use (&$uploadList) { $userId = $user->getUID(); diff --git a/core/BackgroundJobs/CleanupLoginFlowV2.php b/core/BackgroundJobs/CleanupLoginFlowV2.php index 9fee3550c8..69e7fe7195 100644 --- a/core/BackgroundJobs/CleanupLoginFlowV2.php +++ b/core/BackgroundJobs/CleanupLoginFlowV2.php @@ -42,7 +42,7 @@ class CleanupLoginFlowV2 extends TimedJob { $this->setInterval(3600); } - protected function run($argument) { + protected function run($argument): void { $this->loginFlowV2Mapper->cleanup(); } } diff --git a/core/register_command.php b/core/register_command.php index 2a68cbcbe8..4d0e0ceb99 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -1,4 +1,7 @@ Date: Mon, 26 Apr 2021 12:45:12 +0200 Subject: [PATCH 4/4] Use strict Signed-off-by: J0WI --- tests/docker/mysqlmb4.config.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/docker/mysqlmb4.config.php b/tests/docker/mysqlmb4.config.php index 528673950a..3511e3c372 100644 --- a/tests/docker/mysqlmb4.config.php +++ b/tests/docker/mysqlmb4.config.php @@ -1,5 +1,7 @@ true, ];