diff --git a/composer.json b/composer.json index 1627d038df..cee98582b2 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,9 @@ "config": { "platform": { "php": "8.0" + }, + "allow-plugins": { + "bamarni/composer-bin-plugin": true } }, "require": { @@ -19,7 +22,8 @@ "friendsofphp/php-cs-fixer": "^3.8", "nextcloud/coding-standard": "^1.0", "nextcloud/ocp": "dev-master", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "bamarni/composer-bin-plugin": "^1.8" }, "license": "AGPLv3", "authors": [ diff --git a/composer.lock b/composer.lock index 411a433a1f..b44a3079b6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,66 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f118a358162577fab7ee75cad4ef1383", + "content-hash": "dfca2194cfc2b7e48d963f85fa6d2b26", "packages": [], "packages-dev": [ + { + "name": "bamarni/composer-bin-plugin", + "version": "1.8.2", + "source": { + "type": "git", + "url": "https://github.com/bamarni/composer-bin-plugin.git", + "reference": "92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bamarni/composer-bin-plugin/zipball/92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880", + "reference": "92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "ext-json": "*", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-phpunit": "^1.1", + "phpunit/phpunit": "^8.5 || ^9.5", + "symfony/console": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0", + "symfony/finder": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0", + "symfony/process": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Bamarni\\Composer\\Bin\\BamarniBinPlugin" + }, + "autoload": { + "psr-4": { + "Bamarni\\Composer\\Bin\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "No conflicts for your bin dependencies", + "keywords": [ + "composer", + "conflict", + "dependency", + "executable", + "isolation", + "tool" + ], + "support": { + "issues": "https://github.com/bamarni/composer-bin-plugin/issues", + "source": "https://github.com/bamarni/composer-bin-plugin/tree/1.8.2" + }, + "time": "2022-10-31T08:38:03+00:00" + }, { "name": "doctrine/instantiator", "version": "1.5.0", @@ -130,6 +187,52 @@ "abandoned": "php-parallel-lint/php-parallel-lint", "time": "2018-02-24T15:31:20+00:00" }, + { + "name": "kubawerlos/php-cs-fixer-custom-fixers", + "version": "v3.22.0", + "source": { + "type": "git", + "url": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers.git", + "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/8701394f0c7cd450ac4fa577d24589122c1d5d5e", + "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-tokenizer": "*", + "friendsofphp/php-cs-fixer": "^3.61.1", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.6.4 || ^10.5.29" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpCsFixerCustomFixers\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kuba Werłos", + "email": "werlos@gmail.com" + } + ], + "description": "A set of custom fixers for PHP CS Fixer", + "support": { + "issues": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/issues", + "source": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/tree/v3.22.0" + }, + "time": "2024-08-16T20:44:35+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.12.0", @@ -192,19 +295,20 @@ }, { "name": "nextcloud/coding-standard", - "version": "v1.2.3", + "version": "v1.3.1", "source": { "type": "git", "url": "https://github.com/nextcloud/coding-standard.git", - "reference": "bc9c53a5306114b60c4363057aff9c2ed10a54da" + "reference": "e88acb0df6217b808d1632286ddfec9267a102e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/bc9c53a5306114b60c4363057aff9c2ed10a54da", - "reference": "bc9c53a5306114b60c4363057aff9c2ed10a54da", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/e88acb0df6217b808d1632286ddfec9267a102e4", + "reference": "e88acb0df6217b808d1632286ddfec9267a102e4", "shasum": "" }, "require": { + "kubawerlos/php-cs-fixer-custom-fixers": "^3.22", "php": "^7.3|^8.0", "php-cs-fixer/shim": "^3.17" }, @@ -227,9 +331,9 @@ "description": "Nextcloud coding standards for the php cs fixer", "support": { "issues": "https://github.com/nextcloud/coding-standard/issues", - "source": "https://github.com/nextcloud/coding-standard/tree/v1.2.3" + "source": "https://github.com/nextcloud/coding-standard/tree/v1.3.1" }, - "time": "2024-08-23T14:32:32+00:00" + "time": "2024-09-19T09:07:10+00:00" }, { "name": "nextcloud/ocp", @@ -237,12 +341,12 @@ "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "56dae49d60120c34b5651d37da7668c971424665" + "reference": "e3a87a417a6d51eda630e1bd56f0a42c9d277ec8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/56dae49d60120c34b5651d37da7668c971424665", - "reference": "56dae49d60120c34b5651d37da7668c971424665", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/e3a87a417a6d51eda630e1bd56f0a42c9d277ec8", + "reference": "e3a87a417a6d51eda630e1bd56f0a42c9d277ec8", "shasum": "" }, "require": { @@ -274,20 +378,20 @@ "issues": "https://github.com/nextcloud-deps/ocp/issues", "source": "https://github.com/nextcloud-deps/ocp/tree/master" }, - "time": "2024-09-14T00:40:10+00:00" + "time": "2024-09-19T08:25:34+00:00" }, { "name": "nikic/php-parser", - "version": "v5.1.0", + "version": "v5.2.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" + "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", - "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", + "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", "shasum": "" }, "require": { @@ -330,9 +434,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.2.0" }, - "time": "2024-07-01T20:03:41+00:00" + "time": "2024-09-15T16:40:33+00:00" }, { "name": "phar-io/manifest", @@ -454,16 +558,16 @@ }, { "name": "php-cs-fixer/shim", - "version": "v3.63.1", + "version": "v3.64.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/shim.git", - "reference": "27db669308f957ad1909e8c4aa4b957e4cfbc6c9" + "reference": "81ccfd24baf3a10810dab1152c403981a790b837" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/27db669308f957ad1909e8c4aa4b957e4cfbc6c9", - "reference": "27db669308f957ad1909e8c4aa4b957e4cfbc6c9", + "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/81ccfd24baf3a10810dab1152c403981a790b837", + "reference": "81ccfd24baf3a10810dab1152c403981a790b837", "shasum": "" }, "require": { @@ -500,9 +604,9 @@ "description": "A tool to automatically fix PHP code style", "support": { "issues": "https://github.com/PHP-CS-Fixer/shim/issues", - "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.63.1" + "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.64.0" }, - "time": "2024-08-26T14:03:48+00:00" + "time": "2024-08-30T23:10:11+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1168,12 +1272,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "f6f9a938afd75c2344952b0566983700829c7440" + "reference": "22aca9a3467be44288882a3bcf7f2865abe08ca3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/f6f9a938afd75c2344952b0566983700829c7440", - "reference": "f6f9a938afd75c2344952b0566983700829c7440", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/22aca9a3467be44288882a3bcf7f2865abe08ca3", + "reference": "22aca9a3467be44288882a3bcf7f2865abe08ca3", "shasum": "" }, "conflict": { @@ -1270,21 +1374,23 @@ "codeigniter4/shield": "<1.0.0.0-beta8", "codiad/codiad": "<=2.8.4", "composer/composer": "<1.10.27|>=2,<2.2.24|>=2.3,<2.7.7", - "concrete5/concrete5": "<9.3.3", + "concrete5/concrete5": "<9.3.4", "concrete5/core": "<8.5.8|>=9,<9.1", "contao-components/mediaelement": ">=2.14.2,<2.21.1", "contao/comments-bundle": ">=2,<4.13.40|>=5.0.0.0-RC1-dev,<5.3.4", "contao/contao": ">=3,<3.5.37|>=4,<4.4.56|>=4.5,<4.9.40|>=4.10,<4.11.7|>=4.13,<4.13.21|>=5.1,<5.1.4", "contao/core": "<3.5.39", - "contao/core-bundle": "<4.13.40|>=5,<5.3.4", + "contao/core-bundle": "<4.13.49|>=5,<5.3.15|>=5.4,<5.4.3", "contao/listing-bundle": ">=3,<=3.5.30|>=4,<4.4.8", "contao/managed-edition": "<=1.5", "corveda/phpsandbox": "<1.3.5", "cosenary/instagram": "<=2.3", - "craftcms/cms": "<4.6.2|>=5.0.0.0-beta1,<=5.2.2", + "craftcms/cms": "<4.6.2|>=5,<=5.2.2", "croogo/croogo": "<4", "cuyz/valinor": "<0.12", + "czim/file-handling": "<1.5|>=2,<2.3", "czproject/git-php": "<4.0.3", + "damienharper/auditor-bundle": "<5.2.6", "dapphp/securimage": "<3.6.6", "darylldoyle/safe-svg": "<1.9.10", "datadog/dd-trace": ">=0.30,<0.30.2", @@ -1309,8 +1415,9 @@ "dolibarr/dolibarr": "<19.0.2", "dompdf/dompdf": "<2.0.4", "doublethreedigital/guest-entries": "<3.1.2", - "drupal/core": ">=6,<6.38|>=7,<7.96|>=8,<10.1.8|>=10.2,<10.2.2", - "drupal/drupal": ">=5,<5.11|>=6,<6.38|>=7,<7.80|>=8,<8.9.16|>=9,<9.1.12|>=9.2,<9.2.4", + "drupal/core": ">=6,<6.38|>=7,<7.96|>=8,<10.1.8|>=10.2,<10.2.2|==11.9999999.9999999.9999999-dev", + "drupal/core-recommended": "==11.9999999.9999999.9999999-dev", + "drupal/drupal": ">=5,<5.11|>=6,<6.38|>=7,<7.80|>=8,<8.9.16|>=9,<9.1.12|>=9.2,<9.2.4|==11.9999999.9999999.9999999-dev", "duncanmcclean/guest-entries": "<3.1.2", "dweeves/magmi": "<=0.7.24", "ec-cube/ec-cube": "<2.4.4|>=2.11,<=2.17.1|>=3,<=3.0.18.0-patch4|>=4,<=4.1.2", @@ -1392,7 +1499,7 @@ "genix/cms": "<=1.1.11", "getformwork/formwork": "<1.13.1|==2.0.0.0-beta1", "getgrav/grav": "<1.7.46", - "getkirby/cms": "<4.1.1", + "getkirby/cms": "<=3.6.6.5|>=3.7,<=3.7.5.4|>=3.8,<=3.8.4.3|>=3.9,<=3.9.8.1|>=3.10,<=3.10.1|>=4,<=4.3", "getkirby/kirby": "<=2.5.12", "getkirby/panel": "<2.5.14", "getkirby/starterkit": "<=3.7.0.2", @@ -1439,7 +1546,7 @@ "in2code/femanager": "<5.5.3|>=6,<6.3.4|>=7,<7.2.3", "in2code/ipandlanguageredirect": "<5.1.2", "in2code/lux": "<17.6.1|>=18,<24.0.2", - "in2code/powermail": "<7.5|>=8,<8.5|>=9,<10.9|>=12,<12.4", + "in2code/powermail": "<7.5.1|>=8,<8.5.1|>=9,<10.9.1|>=11,<12.4.1", "innologi/typo3-appointments": "<2.0.6", "intelliants/subrion": "<4.2.2", "inter-mediator/inter-mediator": "==5.5", @@ -1469,7 +1576,7 @@ "kelvinmo/simplexrd": "<3.1.1", "kevinpapst/kimai2": "<1.16.7", "khodakhah/nodcms": "<=3", - "kimai/kimai": "<2.16", + "kimai/kimai": "<=2.20.1", "kitodo/presentation": "<3.2.3|>=3.3,<3.3.4", "klaviyo/magento2-extension": ">=1,<3", "knplabs/knp-snappy": "<=1.4.2", @@ -1502,7 +1609,7 @@ "lms/routes": "<2.1.1", "localizationteam/l10nmgr": "<7.4|>=8,<8.7|>=9,<9.2", "luyadev/yii-helpers": "<1.2.1", - "magento/community-edition": "<2.4.5|==2.4.5|>=2.4.5.0-patch1,<2.4.5.0-patch8|==2.4.6|>=2.4.6.0-patch1,<2.4.6.0-patch6|==2.4.7", + "magento/community-edition": "<2.4.5|==2.4.5|>=2.4.5.0-patch1,<2.4.5.0-patch9|==2.4.6|>=2.4.6.0-patch1,<2.4.6.0-patch7|==2.4.7|>=2.4.7.0-patch1,<2.4.7.0-patch2", "magento/core": "<=1.9.4.5", "magento/magento1ce": "<1.9.4.3-dev", "magento/magento1ee": ">=1,<1.14.4.3-dev", @@ -1513,7 +1620,8 @@ "mantisbt/mantisbt": "<2.26.2", "marcwillmann/turn": "<0.3.3", "matyhtf/framework": "<3.0.6", - "mautic/core": "<4.4.12|>=5.0.0.0-alpha,<5.0.4", + "mautic/core": "<4.4.13|>=5.0.0.0-alpha,<5.1.1", + "mautic/core-lib": ">=1.0.0.0-beta,<4.4.13|>=5.0.0.0-alpha,<5.1.1", "mdanter/ecc": "<2", "mediawiki/core": "<1.36.2", "mediawiki/matomo": "<2.4.3", @@ -1548,6 +1656,7 @@ "munkireport/softwareupdate": "<1.6", "mustache/mustache": ">=2,<2.14.1", "namshi/jose": "<2.2", + "nategood/httpful": "<1", "neoan3-apps/template": "<1.1.1", "neorazorx/facturascripts": "<2022.04", "neos/flow": ">=1,<1.0.4|>=1.1,<1.1.1|>=2,<2.0.1|>=2.3,<2.3.16|>=3,<3.0.12|>=3.1,<3.1.10|>=3.2,<3.2.13|>=3.3,<3.3.13|>=4,<4.0.6", @@ -1622,7 +1731,7 @@ "phpmyfaq/phpmyfaq": "<3.2.5|==3.2.5", "phpoffice/common": "<0.2.9", "phpoffice/phpexcel": "<1.8", - "phpoffice/phpspreadsheet": "<1.16", + "phpoffice/phpspreadsheet": "<1.29.1|>=2,<2.1.1|>=2.2,<2.2.1", "phpseclib/phpseclib": "<2.0.47|>=3,<3.0.36", "phpservermon/phpservermon": "<3.6", "phpsysinfo/phpsysinfo": "<3.4.3", @@ -1631,9 +1740,10 @@ "phpxmlrpc/extras": "<0.6.1", "phpxmlrpc/phpxmlrpc": "<4.9.2", "pi/pi": "<=2.5", - "pimcore/admin-ui-classic-bundle": "<=1.5.1", + "pimcore/admin-ui-classic-bundle": "<1.5.4", "pimcore/customer-management-framework-bundle": "<4.0.6", "pimcore/data-hub": "<1.2.4", + "pimcore/data-importer": "<1.8.9|>=1.9,<1.9.3", "pimcore/demo": "<10.3", "pimcore/ecommerce-framework-bundle": "<1.0.10", "pimcore/perspective-editor": "<1.5.1", @@ -1664,7 +1774,7 @@ "pubnub/pubnub": "<6.1", "pusher/pusher-php-server": "<2.2.1", "pwweb/laravel-core": "<=0.3.6.0-beta", - "pxlrbt/filament-excel": "<2.3.3", + "pxlrbt/filament-excel": "<1.1.14|>=2.0.0.0-alpha,<2.3.3", "pyrocms/pyrocms": "<=3.9.1", "qcubed/qcubed": "<=3.1.1", "quickapps/cms": "<=2.0.0.0-beta2", @@ -1815,7 +1925,7 @@ "tinymighty/wiki-seo": "<1.2.2", "titon/framework": "<9.9.99", "tobiasbg/tablepress": "<=2.0.0.0-RC1", - "topthink/framework": "<6.0.17|>=6.1,<6.1.5|>=8,<8.0.4", + "topthink/framework": "<6.0.17|>=6.1,<=8.0.4", "topthink/think": "<=6.1.1", "topthink/thinkphp": "<=3.2.3", "torrentpier/torrentpier": "<=2.4.3", @@ -1824,7 +1934,7 @@ "truckersmp/phpwhois": "<=4.3.1", "ttskch/pagination-service-provider": "<1", "twbs/bootstrap": "<=3.4.1|>=4,<=4.6.2", - "twig/twig": "<1.44.7|>=2,<2.15.3|>=3,<3.4.3", + "twig/twig": "<1.44.8|>=2,<2.16.1|>=3,<3.11.1|>=3.12,<3.14", "typo3/cms": "<9.5.29|>=10,<10.4.35|>=11,<11.5.23|>=12,<12.2", "typo3/cms-backend": "<4.1.14|>=4.2,<4.2.15|>=4.3,<4.3.7|>=4.4,<4.4.4|>=7,<=7.6.50|>=8,<=8.7.39|>=9,<=9.5.24|>=10,<=10.4.13|>=11,<=11.1", "typo3/cms-core": "<=8.7.56|>=9,<=9.5.47|>=10,<=10.4.44|>=11,<=11.5.36|>=12,<=12.4.14|>=13,<=13.1", @@ -1876,6 +1986,7 @@ "winter/wn-dusk-plugin": "<2.1", "winter/wn-system-module": "<1.2.4", "wintercms/winter": "<=1.2.3", + "wireui/wireui": "<1.19.3|>=2,<2.1.3", "woocommerce/woocommerce": "<6.6|>=8.8,<8.8.5|>=8.9,<8.9.3", "wp-cli/wp-cli": ">=0.12,<2.5", "wp-graphql/wp-graphql": "<=1.14.5", @@ -1977,7 +2088,7 @@ "type": "tidelift" } ], - "time": "2024-08-28T08:05:44+00:00" + "time": "2024-09-18T23:05:04+00:00" }, { "name": "sebastian/cli-parser", diff --git a/lib/AppConfig.php b/lib/AppConfig.php index c77fc032c1..18949b5345 100644 --- a/lib/AppConfig.php +++ b/lib/AppConfig.php @@ -112,7 +112,7 @@ public function getAppSettings() { $keys = $this->config->getAppKeys(self::WATERMARK_APP_NAMESPACE); foreach ($keys as $key) { - if (strpos($key, 'watermark_') === 0) { + if (str_starts_with($key, 'watermark_')) { $value = $this->getAppValueArray($key); $value = $value === 'yes' ? true : $value; $result[$key] = $value === 'no' ? false : $value; @@ -209,22 +209,18 @@ private function getFederationDomains(): array { } $federationService = \OCP\Server::get(FederationService::class); - $trustedNextcloudDomains = array_filter(array_map(function ($server) use ($federationService) { - return $federationService->isTrustedRemote($server) ? $server : null; - }, $federationService->getTrustedServers())); + $trustedNextcloudDomains = array_filter(array_map(fn ($server) => $federationService->isTrustedRemote($server) ? $server : null, $federationService->getTrustedServers())); $trustedCollaboraDomains = array_filter(array_map(function ($server) use ($federationService) { try { return $federationService->getRemoteCollaboraURL($server); - } catch (\Exception $e) { + } catch (\Exception) { // If there is no remote collabora server we can just skip that return null; } }, $trustedNextcloudDomains)); - return array_map(function ($url) { - return $this->domainOnly($url); - }, array_merge($trustedNextcloudDomains, $trustedCollaboraDomains)); + return array_map(fn ($url) => $this->domainOnly($url), array_merge($trustedNextcloudDomains, $trustedCollaboraDomains)); } private function getGSDomains(): array { diff --git a/lib/Backgroundjobs/Cleanup.php b/lib/Backgroundjobs/Cleanup.php index 71e0348ad2..a77fb59892 100644 --- a/lib/Backgroundjobs/Cleanup.php +++ b/lib/Backgroundjobs/Cleanup.php @@ -13,15 +13,12 @@ use OCP\IDBConnection; class Cleanup extends TimedJob { - /** @var IDBConnection */ - private $db; - /** @var WopiMapper $wopiMapper */ - private $wopiMapper; - - public function __construct(ITimeFactory $time, IDBConnection $db, WopiMapper $wopiMapper) { + public function __construct( + ITimeFactory $time, + private IDBConnection $db, + private WopiMapper $wopiMapper, + ) { parent::__construct($time); - $this->db = $db; - $this->wopiMapper = $wopiMapper; $this->setInterval(60 * 60); } diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 65f57da796..52ba4ab79c 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -90,7 +90,7 @@ public function __construct( private PermissionManager $permissionManager, private IAppManager $appManager, private ?string $userId, - private IURLGenerator $urlGenerator + private IURLGenerator $urlGenerator, ) { } diff --git a/lib/Command/ConvertToBigInt.php b/lib/Command/ConvertToBigInt.php index b7dec782ce..a66cffe441 100644 --- a/lib/Command/ConvertToBigInt.php +++ b/lib/Command/ConvertToBigInt.php @@ -18,7 +18,9 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; class ConvertToBigInt extends Command { - public function __construct(private Connection $connection) { + public function __construct( + private Connection $connection, + ) { parent::__construct(); } diff --git a/lib/Command/InstallDefaultFonts.php b/lib/Command/InstallDefaultFonts.php index b050799488..25b0c9527b 100644 --- a/lib/Command/InstallDefaultFonts.php +++ b/lib/Command/InstallDefaultFonts.php @@ -11,7 +11,9 @@ use Symfony\Component\Console\Output\OutputInterface; class InstallDefaultFonts extends Command { - public function __construct(private FontService $fontService) { + public function __construct( + private FontService $fontService, + ) { parent::__construct(); } diff --git a/lib/Command/UpdateEmptyTemplates.php b/lib/Command/UpdateEmptyTemplates.php index a32a1d0552..406891d283 100644 --- a/lib/Command/UpdateEmptyTemplates.php +++ b/lib/Command/UpdateEmptyTemplates.php @@ -13,11 +13,9 @@ use Symfony\Component\Console\Output\OutputInterface; class UpdateEmptyTemplates extends Command { - /** @var TemplateManager */ - private $templateManager; - - public function __construct(TemplateManager $templateManager) { - $this->templateManager = $templateManager; + public function __construct( + private TemplateManager $templateManager, + ) { parent::__construct(); } diff --git a/lib/Controller/AssetsController.php b/lib/Controller/AssetsController.php index d7792a6017..dac0f5e903 100644 --- a/lib/Controller/AssetsController.php +++ b/lib/Controller/AssetsController.php @@ -22,26 +22,16 @@ use OCP\IURLGenerator; class AssetsController extends Controller { - private AssetMapper $assetMapper; - private IRootFolder $rootFolder; - private ?string $userId; - private UserScopeService $userScopeService; - private IURLGenerator $urlGenerator; - - public function __construct($appName, + public function __construct( + $appName, IRequest $request, - AssetMapper $assetMapper, - IRootFolder $rootFolder, - $userId, - UserScopeService $userScopeService, - IURLGenerator $urlGenerator) { + private AssetMapper $assetMapper, + private IRootFolder $rootFolder, + private ?string $userId, + private UserScopeService $userScopeService, + private IURLGenerator $urlGenerator, + ) { parent::__construct($appName, $request); - - $this->assetMapper = $assetMapper; - $this->rootFolder = $rootFolder; - $this->userId = $userId; - $this->userScopeService = $userScopeService; - $this->urlGenerator = $urlGenerator; } /** @@ -56,7 +46,7 @@ public function create($path) { try { $node = $userFolder->get($path); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } @@ -80,7 +70,7 @@ public function create($path) { public function get($token) { try { $asset = $this->assetMapper->getAssetByToken($token); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { return new DataResponse([], Http::STATUS_NOT_FOUND); } diff --git a/lib/Controller/DirectViewController.php b/lib/Controller/DirectViewController.php index fc0c941a82..ccb8e80ca3 100644 --- a/lib/Controller/DirectViewController.php +++ b/lib/Controller/DirectViewController.php @@ -42,7 +42,7 @@ public function __construct( private AppConfig $appConfig, private TemplateManager $templateManager, private FederationService $federationService, - private LoggerInterface $logger + private LoggerInterface $logger, ) { parent::__construct($appName, $request); } diff --git a/lib/Controller/DocumentAPIController.php b/lib/Controller/DocumentAPIController.php index 3aa7edab3e..f2c6495f61 100644 --- a/lib/Controller/DocumentAPIController.php +++ b/lib/Controller/DocumentAPIController.php @@ -29,23 +29,17 @@ use Throwable; class DocumentAPIController extends \OCP\AppFramework\OCSController { - private $rootFolder; - private $shareManager; - private $templateManager; - private $l10n; - private $logger; - private $lockManager; - private $userId; - - public function __construct(IRequest $request, IRootFolder $rootFolder, IManager $shareManager, TemplateManager $templateManager, IL10N $l10n, LoggerInterface $logger, ILockManager $lockManager, $userId) { + public function __construct( + IRequest $request, + private IRootFolder $rootFolder, + private IManager $shareManager, + private TemplateManager $templateManager, + private IL10N $l10n, + private LoggerInterface $logger, + private ILockManager $lockManager, + private $userId, + ) { parent::__construct(Application::APPNAME, $request); - $this->rootFolder = $rootFolder; - $this->shareManager = $shareManager; - $this->templateManager = $templateManager; - $this->l10n = $l10n; - $this->logger = $logger; - $this->lockManager = $lockManager; - $this->userId = $userId; } /** @@ -153,9 +147,9 @@ public function openLocal(int $fileId): DataResponse { Application::APPNAME )); return new DataResponse([]); - } catch (NoLockProviderException|PreConditionNotMetException $e) { + } catch (NoLockProviderException|PreConditionNotMetException) { return new DataResponse([], Http::STATUS_BAD_REQUEST); - } catch (\Exception $e) { + } catch (\Exception) { return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index e5759751f7..488d337f18 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -58,7 +58,7 @@ public function __construct( private TemplateManager $templateManager, private FederationService $federationService, private InitialStateService $initialState, - private IURLGenerator $urlGenerator + private IURLGenerator $urlGenerator, ) { parent::__construct($appName, $request); } @@ -144,7 +144,7 @@ public function index($fileId, ?string $path = null): RedirectResponse|TemplateR if ($encryptionManager->isEnabled()) { // Update the current file to be accessible with system public shared key $owner = $file->getOwner()->getUID(); - $absPath = '/' . $owner . '/' . $file->getInternalPath(); + $absPath = '/' . $owner . '/' . $file->getInternalPath(); $accessList = OC::$server->getEncryptionFilesHelper()->getAccessList($absPath); $accessList['public'] = true; $encryptionManager->getEncryptionModule()->update($absPath, $owner, $accessList); @@ -169,7 +169,7 @@ public function createFromTemplate(int $templateId, string $fileName, string $di $userFolder = $this->rootFolder->getUserFolder($this->userId); try { $folder = $userFolder->get($dir); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new TemplateResponse('core', '403', [], 'guest'); } @@ -286,7 +286,7 @@ public function remote(string $shareToken, string $remoteServer, string $remoteS $response->addHeader('X-Frame-Options', 'ALLOW'); return $response; } - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { return new TemplateResponse('core', '404', [], 'guest'); } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); diff --git a/lib/Controller/DocumentTrait.php b/lib/Controller/DocumentTrait.php index 7971478555..99520dc7a8 100644 --- a/lib/Controller/DocumentTrait.php +++ b/lib/Controller/DocumentTrait.php @@ -46,7 +46,7 @@ private function applyPolicies($response) { private function domainOnly(string $url): string { $parsed_url = parse_url($url); $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; - $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; + $host = $parsed_url['host'] ?? ''; $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; return "$scheme$host$port"; } diff --git a/lib/Controller/FederationController.php b/lib/Controller/FederationController.php index fc97e4bdff..7397af88c3 100644 --- a/lib/Controller/FederationController.php +++ b/lib/Controller/FederationController.php @@ -19,36 +19,16 @@ use Psr\Log\LoggerInterface; class FederationController extends OCSController { - /** @var IConfig */ - private $config; - - /** @var LoggerInterface */ - private $logger; - - /** @var WopiMapper */ - private $wopiMapper; - - /** @var IUserManager */ - private $userManager; - - /** @var IURLGenerator */ - private $urlGenerator; - public function __construct( string $appName, IRequest $request, - IConfig $config, - LoggerInterface $logger, - WopiMapper $wopiMapper, - IUserManager $userManager, - IURLGenerator $urlGenerator + private IConfig $config, + private LoggerInterface $logger, + private WopiMapper $wopiMapper, + private IUserManager $userManager, + private IURLGenerator $urlGenerator, ) { parent::__construct($appName, $request); - $this->config = $config; - $this->logger = $logger; - $this->wopiMapper = $wopiMapper; - $this->userManager = $userManager; - $this->urlGenerator = $urlGenerator; } /** @@ -97,10 +77,10 @@ public function remoteWopiToken($token): DataResponse { } $this->logger->debug('COOL-Federation-Initiator: Token ' . $token . ' returned'); return new DataResponse($initiatorWopi); - } catch (UnknownTokenException $e) { + } catch (UnknownTokenException) { $this->logger->debug('COOL-Federation-Initiator: Token ' . $token . 'not found'); throw new OCSNotFoundException(); - } catch (ExpiredTokenException $e) { + } catch (ExpiredTokenException) { $this->logger->debug('COOL-Federation-Initiator: Token ' . $token . ' is expired'); throw new OCSNotFoundException(); } @@ -132,10 +112,10 @@ public function initiatorUser($token): DataResponse { 'displayName' => $user->getDisplayName(), 'avatar' => $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $wopi->getEditorUid(), 'size' => WopiController::WOPI_AVATAR_SIZE]) ]); - } catch (UnknownTokenException $e) { + } catch (UnknownTokenException) { $this->logger->debug('COOL-Federation-Initiator-User: Token ' . $token . 'not found'); throw new OCSNotFoundException(); - } catch (ExpiredTokenException $e) { + } catch (ExpiredTokenException) { $this->logger->debug('COOL-Federation-Initiator-User: Token ' . $token . ' is expired.'); throw new OCSNotFoundException(); } diff --git a/lib/Controller/OCSController.php b/lib/Controller/OCSController.php index b9d15d6008..edbbfd7820 100644 --- a/lib/Controller/OCSController.php +++ b/lib/Controller/OCSController.php @@ -30,56 +30,23 @@ use Psr\Log\LoggerInterface; class OCSController extends \OCP\AppFramework\OCSController { - /** @var IRootFolder */ - private $rootFolder; - - /** @var string */ - private $userId; - - /** @var DirectMapper */ - private $directMapper; - - /** @var IURLGenerator */ - private $urlGenerator; - - /** @var TemplateManager */ - private $manager; - - /** @var TokenManager */ - private $tokenManager; - - /** @var IManager */ - private $shareManager; - - /** @var FederationService */ - private $federationService; - - /** @var LoggerInterface */ - private $logger; - - public function __construct(string $appName, + /** + * @param string $userId + */ + public function __construct( + string $appName, IRequest $request, - IRootFolder $rootFolder, - $userId, - DirectMapper $directMapper, - IURLGenerator $urlGenerator, - TemplateManager $manager, - TokenManager $tokenManager, - IManager $shareManager, - FederationService $federationService, - LoggerInterface $logger + private IRootFolder $rootFolder, + private $userId, + private DirectMapper $directMapper, + private IURLGenerator $urlGenerator, + private TemplateManager $manager, + private TokenManager $tokenManager, + private IManager $shareManager, + private FederationService $federationService, + private LoggerInterface $logger, ) { parent::__construct($appName, $request); - - $this->rootFolder = $rootFolder; - $this->userId = $userId; - $this->directMapper = $directMapper; - $this->urlGenerator = $urlGenerator; - $this->manager = $manager; - $this->tokenManager = $tokenManager; - $this->shareManager = $shareManager; - $this->federationService = $federationService; - $this->logger = $logger; } /** @@ -111,7 +78,7 @@ public function createDirect($fileId) { 'token' => $direct->getToken() ]) ]); - } catch (NotFoundException $e) { + } catch (NotFoundException) { throw new OCSNotFoundException(); } } @@ -128,7 +95,7 @@ public function createPublic( string $shareToken, ?string $host = null, string $path = '', - ?string $password = null + ?string $password = null, ): DataResponse { if ($host) { $remoteCollabora = $this->federationService->getRemoteCollaboraURL($host); @@ -174,7 +141,7 @@ public function createPublic( try { $share = $this->shareManager->getShareByToken($shareToken); - } catch (ShareNotFound $ex) { + } catch (ShareNotFound) { $response = new DataResponse([], HTTP::STATUS_NOT_FOUND); $response->throttle(); return $response; @@ -216,11 +183,11 @@ public function createPublicFromInitiator( string $initiatorToken, string $shareToken, string $path = '', - ?string $password = null + ?string $password = null, ): DataResponse { try { $share = $this->shareManager->getShareByToken($shareToken); - } catch (ShareNotFound $ex) { + } catch (ShareNotFound) { $response = new DataResponse([], HTTP::STATUS_NOT_FOUND); $response->throttle(); return $response; @@ -261,11 +228,11 @@ public function updateGuestName(string $access_token, string $guestName): DataRe try { $this->tokenManager->updateGuestName($access_token, $guestName); return new DataResponse([], Http::STATUS_OK); - } catch (UnknownTokenException $e) { + } catch (UnknownTokenException) { $response = new DataResponse([], Http::STATUS_FORBIDDEN); $response->throttle(); return $response; - } catch (ExpiredTokenException $e) { + } catch (ExpiredTokenException) { $response = new DataResponse([], Http::STATUS_UNAUTHORIZED); $response->throttle(); return $response; @@ -318,7 +285,7 @@ public function createFromTemplate($path, $template) { 'token' => $direct->getToken() ]) ]); - } catch (NotFoundException $e) { + } catch (NotFoundException) { throw new OCSNotFoundException(); } catch (\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index d2eebe3a57..e2134b47b4 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -43,7 +43,8 @@ class SettingsController extends Controller { 'application/vnd.ms-opentype', ]; - public function __construct($appName, + public function __construct( + $appName, IRequest $request, private IL10N $l10n, private AppConfig $appConfig, @@ -54,7 +55,7 @@ public function __construct($appName, private DemoService $demoService, private FontService $fontService, private LoggerInterface $logger, - private ?string $userId + private ?string $userId, ) { parent::__construct($appName, $request); } @@ -120,7 +121,7 @@ public function setSettings( ?string $use_groups, ?string $doc_format, ?string $external_apps, - ?string $canonical_webroot + ?string $canonical_webroot, ): JSONResponse { if ($wopi_url !== null) { $this->appConfig->setAppValue('wopi_url', $wopi_url); @@ -242,7 +243,7 @@ public function setPersonalSettings($templateFolder, if ($templateFolder !== null) { try { $this->config->setUserValue($this->userId, 'richdocuments', 'templateFolder', $templateFolder); - } catch (PreConditionNotMetException $e) { + } catch (PreConditionNotMetException) { $message = $this->l10n->t('Error when saving'); $status = 'error'; } @@ -250,7 +251,7 @@ public function setPersonalSettings($templateFolder, if ($zoteroAPIKeyInput !== null) { try { $this->config->setUserValue($this->userId, 'richdocuments', 'zoteroAPIKey', $zoteroAPIKeyInput); - } catch (PreConditionNotMetException $e) { + } catch (PreConditionNotMetException) { $message = $this->l10n->t('Error when saving'); $status = 'error'; } @@ -295,9 +296,7 @@ public function getFontNames() { public function getJsonFontList() { $files = $this->fontService->getFontFiles(); $etags = array_map( - static function (ISimpleFile $f) { - return $f->getETag(); - }, + static fn (ISimpleFile $f) => $f->getETag(), $files ); $etag = md5(implode(',', $etags)); @@ -335,7 +334,7 @@ public function getFontFile(string $name) { Http::STATUS_OK, ['Content-Type' => $fontFile->getMimeType(), 'Etag' => $etag] ); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new DataDisplayResponse('', Http::STATUS_NOT_FOUND); } } @@ -357,7 +356,7 @@ public function getFontFileOverview(string $name): DataDisplayResponse { Http::STATUS_OK, ['Content-Type' => 'image/png'] ); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new DataDisplayResponse('', Http::STATUS_NOT_FOUND); } } diff --git a/lib/Controller/TargetController.php b/lib/Controller/TargetController.php index 72e067d4d4..281ab1552d 100644 --- a/lib/Controller/TargetController.php +++ b/lib/Controller/TargetController.php @@ -36,7 +36,7 @@ public function getTargets(string $path): DataResponse { try { $file = $this->getFile($path); return new DataResponse($this->fileTargetService->getFileTargets($file)); - } catch (NotFoundException $e) { + } catch (NotFoundException) { } return new DataResponse('File not found', Http::STATUS_NOT_FOUND); @@ -54,7 +54,7 @@ public function getPreview(string $path, string $target): Response { Http::STATUS_OK, ['Content-Type' => 'image/png'] ); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new DataResponse('File not found', Http::STATUS_NOT_FOUND); } } @@ -71,7 +71,7 @@ private function getFile(string $path): File { } return $file; - } catch (NotFoundException|NotPermittedException|NoUserException $e) { + } catch (NotFoundException|NotPermittedException|NoUserException) { throw new NotFoundException(); } } diff --git a/lib/Controller/TemplateFieldController.php b/lib/Controller/TemplateFieldController.php index 0f604b82b8..69945d3153 100644 --- a/lib/Controller/TemplateFieldController.php +++ b/lib/Controller/TemplateFieldController.php @@ -33,7 +33,7 @@ public function extractFields(int $fileId): DataResponse { $fields = $this->templateFieldService->extractFields($fileId); return new DataResponse($fields, Http::STATUS_OK); - } catch (\Exception $e) { + } catch (\Exception) { return new DataResponse(['Unable to extract fields from given file'], Http::STATUS_INTERNAL_SERVER_ERROR); } } @@ -54,7 +54,7 @@ public function fillFields(int $fileId, array $fields = [], ?string $destination } return new DataResponse([], Http::STATUS_OK); - } catch (\Exception $e) { + } catch (\Exception) { return new DataResponse(['Unable to fill fields into the given file'], Http::STATUS_INTERNAL_SERVER_ERROR); } } diff --git a/lib/Controller/TemplatesController.php b/lib/Controller/TemplatesController.php index e05343e84a..6d90f489f2 100644 --- a/lib/Controller/TemplatesController.php +++ b/lib/Controller/TemplatesController.php @@ -26,12 +26,6 @@ use Psr\Log\LoggerInterface; class TemplatesController extends Controller { - private IL10N $l10n; - private TemplateManager $manager; - private IPreview $preview; - private IMimeTypeDetector $mimeTypeDetector; - private LoggerInterface $logger; - /** @var int Max template size */ private $maxSize = 20 * 1024 * 1024; @@ -44,23 +38,19 @@ class TemplatesController extends Controller { * @param TemplateManager $manager * @param IPreview $preview */ - public function __construct($appName, + public function __construct( + $appName, IRequest $request, - IL10N $l10n, - TemplateManager $manager, - IPreview $preview, - IMimeTypeDetector $mimeTypeDetector, - LoggerInterface $logger + private IL10N $l10n, + private TemplateManager $manager, + private IPreview $preview, + private IMimeTypeDetector $mimeTypeDetector, + private LoggerInterface $logger, ) { parent::__construct($appName, $request); $this->appName = $appName; $this->request = $request; - $this->l10n = $l10n; - $this->manager = $manager; - $this->preview = $preview; - $this->mimeTypeDetector = $mimeTypeDetector; - $this->logger = $logger; } /** @@ -91,7 +81,7 @@ public function getPreview($fileId, try { $template = $this->manager->get($fileId); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new DataResponse([], Http::STATUS_NOT_FOUND); } @@ -171,7 +161,7 @@ public function delete($fileId) { ['data' => ['status' => 'success']], Http::STATUS_NO_CONTENT ); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new JSONResponse( ['data' => ['message' => $this->l10n->t('Template not found')]], Http::STATUS_NOT_FOUND @@ -208,9 +198,9 @@ private function fetchPreview( $response->cacheFor(3600 * 24); return $response; - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new DataResponse([], Http::STATUS_NOT_FOUND); - } catch (\InvalidArgumentException $e) { + } catch (\InvalidArgumentException) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } } diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index a075a2bc83..25e0f71046 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -82,7 +82,7 @@ public function __construct( private IEncryptionManager $encryptionManager, private IGroupManager $groupManager, private ILockManager $lockManager, - private IEventDispatcher $eventDispatcher + private IEventDispatcher $eventDispatcher, ) { parent::__construct($appName, $request); } @@ -109,10 +109,7 @@ public function checkFileInfo($fileId, $access_token) { if (!($file instanceof File)) { throw new NotFoundException('No valid file found for ' . $fileId); } - } catch (NotFoundException $e) { - $this->logger->debug($e->getMessage(), ['exception' => $e]); - return new JSONResponse([], Http::STATUS_FORBIDDEN); - } catch (UnknownTokenException $e) { + } catch (NotFoundException|UnknownTokenException $e) { $this->logger->debug($e->getMessage(), ['exception' => $e]); return new JSONResponse([], Http::STATUS_FORBIDDEN); } catch (ExpiredTokenException $e) { @@ -188,9 +185,7 @@ public function checkFileInfo($fileId, $access_token) { 'email' => $email, ]; $watermarkTemplate = $this->appConfig->getAppValue('watermark_text'); - $response['WatermarkText'] = preg_replace_callback('/{(.+?)}/', function ($matches) use ($replacements) { - return $replacements[$matches[1]]; - }, $watermarkTemplate); + $response['WatermarkText'] = preg_replace_callback('/{(.+?)}/', fn ($matches) => $replacements[$matches[1]], $watermarkTemplate); } $user = $this->userManager->get($wopi->getEditorUid()); @@ -463,9 +458,7 @@ public function putFile($fileId, if ($freespace >= 0 && $contentLength > $freespace) { throw new \Exception('Not enough storage'); } - $this->wrappedFilesystemOperation($wopi, function () use ($file, $content) { - return $file->putContent($content); - }); + $this->wrappedFilesystemOperation($wopi, fn () => $file->putContent($content)); } catch (LockedException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); return new JSONResponse(['message' => 'File locked'], Http::STATUS_INTERNAL_SERVER_ERROR); @@ -566,9 +559,9 @@ public function postFile(string $fileId, string $access_token): JSONResponse { $suggested = mb_convert_encoding($suggested, 'utf-8', 'utf-7') . '.' . $file->getExtension(); - if (strpos($suggested, '.') === 0) { + if (str_starts_with($suggested, '.')) { $path = dirname($file->getPath()) . '/New File' . $suggested; - } elseif (strpos($suggested, '/') !== 0) { + } elseif (!str_starts_with($suggested, '/')) { $path = dirname($file->getPath()) . '/' . $suggested; } else { $path = $userFolder->getPath() . $suggested; @@ -592,7 +585,7 @@ public function postFile(string $fileId, string $access_token): JSONResponse { $this->getFileForWopiToken($wopi), ILock::TYPE_APP, Application::APPNAME - ), function () use (&$file, $path) { + ), function () use (&$file, $path): void { $file = $file->move($path); }); } else { @@ -632,10 +625,8 @@ public function postFile(string $fileId, string $access_token): JSONResponse { $this->userScopeService->setFilesystemScope($wopi->getEditorUid()); try { - $this->wrappedFilesystemOperation($wopi, function () use ($file, $content) { - return $file->putContent($content); - }); - } catch (LockedException $e) { + $this->wrappedFilesystemOperation($wopi, fn () => $file->putContent($content)); + } catch (LockedException) { return new JSONResponse(['message' => 'File locked'], Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -666,7 +657,7 @@ private function lock(Wopi $wopi, string $lock): JSONResponse { Application::APPNAME )); return new JSONResponse(); - } catch (NoLockProviderException|PreConditionNotMetException $e) { + } catch (NoLockProviderException|PreConditionNotMetException) { return new JSONResponse([], Http::STATUS_BAD_REQUEST); } catch (OwnerLockedException $e) { // If a file is manually locked by a user we want to all this user to still perform a WOPI lock and write @@ -675,7 +666,7 @@ private function lock(Wopi $wopi, string $lock): JSONResponse { } return new JSONResponse([], Http::STATUS_LOCKED); - } catch (\Exception $e) { + } catch (\Exception) { return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } @@ -688,14 +679,14 @@ private function unlock(Wopi $wopi, string $lock): JSONResponse { Application::APPNAME )); return new JSONResponse(); - } catch (NoLockProviderException|PreConditionNotMetException $e) { + } catch (NoLockProviderException|PreConditionNotMetException) { $locks = $this->lockManager->getLocks($wopi->getFileid()); $canWriteThroughLock = count($locks) > 0 && $locks[0]->getType() === ILock::TYPE_USER && $locks[0]->getOwner() !== $wopi->getEditorUid() ? false : true; if ($canWriteThroughLock) { return new JSONResponse(); } return new JSONResponse([], Http::STATUS_BAD_REQUEST); - } catch (\Exception $e) { + } catch (\Exception) { return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } @@ -708,11 +699,11 @@ private function refreshLock(Wopi $wopi, string $lock): JSONResponse { Application::APPNAME )); return new JSONResponse(); - } catch (NoLockProviderException|PreConditionNotMetException $e) { + } catch (NoLockProviderException|PreConditionNotMetException) { return new JSONResponse([], Http::STATUS_BAD_REQUEST); - } catch (OwnerLockedException $e) { + } catch (OwnerLockedException) { return new JSONResponse([], Http::STATUS_LOCKED); - } catch (\Exception $e) { + } catch (\Exception) { return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } @@ -729,7 +720,7 @@ private function getLock(Wopi $wopi, string $lock): JSONResponse { * @throws ShareNotFound */ protected function wrappedFilesystemOperation(Wopi $wopi, callable $filesystemOperation): void { - $retryOperation = function () use ($filesystemOperation) { + $retryOperation = function () use ($filesystemOperation): void { $this->retryOperation($filesystemOperation); }; try { @@ -738,7 +729,7 @@ protected function wrappedFilesystemOperation(Wopi $wopi, callable $filesystemOp ILock::TYPE_APP, Application::APPNAME ), $retryOperation); - } catch (NoLockProviderException $e) { + } catch (NoLockProviderException) { $retryOperation(); } } @@ -798,9 +789,7 @@ private function getFileForWopiToken(Wopi $wopi) { // Workaround to always open files with edit permissions if multiple occurrences of // the same file id are in the user home, ideally we should also track the path of the file when opening - usort($files, function (Node $a, Node $b) { - return ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE); - }); + usort($files, fn (Node $a, Node $b) => ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE)); return array_shift($files); } @@ -808,7 +797,7 @@ private function getFileForWopiToken(Wopi $wopi) { private function getShareForWopiToken(Wopi $wopi): ?IShare { try { return $wopi->getShare() ? $this->shareManager->getShareByToken($wopi->getShare()) : null; - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { } return null; @@ -857,7 +846,7 @@ private function isMasterKeyEnabled(): bool { try { $util = \OC::$server->query(\OCA\Encryption\Util::class); return $util->isMasterKeyEnabled(); - } catch (QueryException $e) { + } catch (QueryException) { // No encryption module enabled return false; } diff --git a/lib/Db/AssetMapper.php b/lib/Db/AssetMapper.php index 928c3b0470..e755577f57 100644 --- a/lib/Db/AssetMapper.php +++ b/lib/Db/AssetMapper.php @@ -17,14 +17,12 @@ class AssetMapper extends QBMapper { /** @var int Lifetime of a token is 10 minutes */ public const TOKEN_TTL = 600; - private ISecureRandom $random; - private ITimeFactory $time; - - public function __construct(IDBConnection $db, ISecureRandom $random, ITimeFactory $timeFactory) { + public function __construct( + IDBConnection $db, + private ISecureRandom $random, + private ITimeFactory $time, + ) { parent::__construct($db, 'richdocuments_assets', Asset::class); - - $this->random = $random; - $this->time = $timeFactory; } /** @@ -61,7 +59,7 @@ public function getAssetByToken(string $token): Asset { } return $asset; - } catch (\Exception $e) { + } catch (\Exception) { } throw new DoesNotExistException('No asset for token found'); diff --git a/lib/Db/DirectMapper.php b/lib/Db/DirectMapper.php index c3347fe7a0..aba0ff5406 100644 --- a/lib/Db/DirectMapper.php +++ b/lib/Db/DirectMapper.php @@ -17,16 +17,12 @@ class DirectMapper extends QBMapper { /** @var int Lifetime of a token is 10 minutes */ public const TOKEN_TTL = 600; - protected ISecureRandom $random; - protected ITimeFactory $timeFactory; - - public function __construct(IDBConnection $db, - ISecureRandom $random, - ITimeFactory $timeFactory) { + public function __construct( + IDBConnection $db, + protected ISecureRandom $random, + protected ITimeFactory $timeFactory, + ) { parent::__construct($db, 'richdocuments_direct', Direct::class); - - $this->random = $random; - $this->timeFactory = $timeFactory; } /** @@ -66,7 +62,7 @@ public function getByToken(string $token): Direct { } return $direct; - } catch (\Exception $e) { + } catch (\Exception) { } throw new DoesNotExistException('No asset for token found'); diff --git a/lib/Db/Wopi.php b/lib/Db/Wopi.php index d97ea1b78e..14d12f3071 100644 --- a/lib/Db/Wopi.php +++ b/lib/Db/Wopi.php @@ -168,7 +168,7 @@ public function jsonSerialize() { $reflection = new \ReflectionClass($this); $json = []; foreach ($properties as $property => $value) { - if (strpos($property, '_') !== 0 && $reflection->hasProperty($property)) { + if (!str_starts_with($property, '_') && $reflection->hasProperty($property)) { $propertyReflection = $reflection->getProperty($property); if (!$propertyReflection->isPrivate()) { $json[$property] = $this->getter($property); diff --git a/lib/Db/WopiMapper.php b/lib/Db/WopiMapper.php index de1f640c58..ebb472206c 100644 --- a/lib/Db/WopiMapper.php +++ b/lib/Db/WopiMapper.php @@ -17,29 +17,14 @@ /** @template-extends QBMapper */ class WopiMapper extends QBMapper { - /** @var ISecureRandom */ - private $random; - - /** @var LoggerInterface */ - private $logger; - - /** @var ITimeFactory */ - private $timeFactory; - - /** @var AppConfig */ - private $appConfig; - - public function __construct(IDBConnection $db, - ISecureRandom $random, - LoggerInterface $logger, - ITimeFactory $timeFactory, - AppConfig $appConfig) { + public function __construct( + IDBConnection $db, + private ISecureRandom $random, + private LoggerInterface $logger, + private ITimeFactory $timeFactory, + private AppConfig $appConfig, + ) { parent::__construct($db, 'richdocuments_wopi', Wopi::class); - - $this->random = $random; - $this->logger = $logger; - $this->timeFactory = $timeFactory; - $this->appConfig = $appConfig; } /** @@ -106,7 +91,7 @@ public function generateInitiatorToken($uid, $remoteServer) { */ public function getPathForToken( #[\SensitiveParameter] - $token + $token, ): Wopi { return $this->getWopiForToken($token); } @@ -123,7 +108,7 @@ public function getPathForToken( */ public function getWopiForToken( #[\SensitiveParameter] - string $token + string $token, ): Wopi { $qb = $this->db->getQueryBuilder(); $qb->select('*') diff --git a/lib/Events/BeforeFederationRedirectEvent.php b/lib/Events/BeforeFederationRedirectEvent.php index c40e6c3373..3cb4bb08a4 100644 --- a/lib/Events/BeforeFederationRedirectEvent.php +++ b/lib/Events/BeforeFederationRedirectEvent.php @@ -9,20 +9,20 @@ use OCP\Files\Node; class BeforeFederationRedirectEvent extends Event { - /** @var Node */ - private $node; - /** @var string */ - private $relativePath; /** @var string|null */ private $redirectUrl = null; - /** @var string */ - private $remote; - public function __construct($node, $relativePath, $remote) { + /** + * @param Node $node + * @param string $relativePath + * @param string $remote + */ + public function __construct( + private $node, + private $relativePath, + private $remote, + ) { parent::__construct(); - $this->node = $node; - $this->relativePath = $relativePath; - $this->remote = $remote; } public function getRelativePath() { diff --git a/lib/Events/DocumentOpenedEvent.php b/lib/Events/DocumentOpenedEvent.php index 554cc0c0bc..9e758f5469 100644 --- a/lib/Events/DocumentOpenedEvent.php +++ b/lib/Events/DocumentOpenedEvent.php @@ -11,12 +11,10 @@ use OCP\Files\Node; class DocumentOpenedEvent extends \OCP\EventDispatcher\Event { - private ?string $userId; - private Node $node; - - public function __construct(?string $userId, Node $node) { - $this->userId = $userId; - $this->node = $node; + public function __construct( + private ?string $userId, + private Node $node, + ) { } public function getUserId(): ?string { diff --git a/lib/Helper.php b/lib/Helper.php index 50ba5dc5b1..76272faa86 100644 --- a/lib/Helper.php +++ b/lib/Helper.php @@ -10,11 +10,12 @@ use OCP\Files\Folder; class Helper { - /** @var string|null */ - private $userId; - - public function __construct($userId) { - $this->userId = $userId; + /** + * @param string|null $userId + */ + public function __construct( + private $userId, + ) { } /** @@ -38,7 +39,7 @@ public static function parseFileId(string $fileId) { throw new \Exception('$fileId has not the expected format'); } - if (strpos($fileId, '-') !== false) { + if (str_contains($fileId, '-')) { [$fileId, $templateId] = explode('/', $fileId); } diff --git a/lib/Listener/BeforeFetchPreviewListener.php b/lib/Listener/BeforeFetchPreviewListener.php index 0adf48053c..e0a6924460 100644 --- a/lib/Listener/BeforeFetchPreviewListener.php +++ b/lib/Listener/BeforeFetchPreviewListener.php @@ -24,16 +24,12 @@ /** @template-implements IEventListener */ class BeforeFetchPreviewListener implements IEventListener { - private PermissionManager $permissionManager; - private IUserSession $userSession; - private IRequest $request; - private IManager $shareManager; - - public function __construct(PermissionManager $permissionManager, IUserSession $userSession, IRequest $request, IManager $shareManager) { - $this->permissionManager = $permissionManager; - $this->userSession = $userSession; - $this->request = $request; - $this->shareManager = $shareManager; + public function __construct( + private PermissionManager $permissionManager, + private IUserSession $userSession, + private IRequest $request, + private IManager $shareManager, + ) { } public function handle(Event $event): void { @@ -56,7 +52,7 @@ public function handle(Event $event): void { // Get different share for public previews as the share from the node is only set for mounted shares try { $share = $shareToken ? $this->shareManager->getShareByToken($shareToken) : $share; - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { } $userId = $this->userSession->getUser() ? $this->userSession->getUser()->getUID() : null; diff --git a/lib/Listener/BeforeGetTemplatesListener.php b/lib/Listener/BeforeGetTemplatesListener.php index 359687a374..6d9e5d4d4d 100644 --- a/lib/Listener/BeforeGetTemplatesListener.php +++ b/lib/Listener/BeforeGetTemplatesListener.php @@ -15,7 +15,7 @@ /** @template-implements IEventListener */ class BeforeGetTemplatesListener implements IEventListener { public function __construct( - private TemplateFieldService $templateFieldService + private TemplateFieldService $templateFieldService, ) { } @@ -24,7 +24,7 @@ public function handle(Event $event): void { return; } - foreach($event->getTemplates() as $template) { + foreach ($event->getTemplates() as $template) { $templateFileId = $template->jsonSerialize()['fileid']; $fields = $this->templateFieldService->extractFields($templateFileId); diff --git a/lib/Listener/BeforeTemplateRenderedListener.php b/lib/Listener/BeforeTemplateRenderedListener.php index 7b4ff3a050..ca20eb9d7a 100644 --- a/lib/Listener/BeforeTemplateRenderedListener.php +++ b/lib/Listener/BeforeTemplateRenderedListener.php @@ -14,10 +14,9 @@ /** @template-implements IEventListener */ class BeforeTemplateRenderedListener implements IEventListener { - private CapabilitiesService $capabilitiesService; - - public function __construct(CapabilitiesService $capabilitiesService) { - $this->capabilitiesService = $capabilitiesService; + public function __construct( + private CapabilitiesService $capabilitiesService, + ) { } public function handle(Event $event): void { diff --git a/lib/Listener/LoadViewerListener.php b/lib/Listener/LoadViewerListener.php index ae79dd8a05..aec47c6fde 100644 --- a/lib/Listener/LoadViewerListener.php +++ b/lib/Listener/LoadViewerListener.php @@ -20,17 +20,11 @@ /** @template-implements IEventListener */ class LoadViewerListener implements IEventListener { - /** @var PermissionManager */ - private $permissionManager; - /** @var InitialStateService */ - private $initialStateService; - - private ?string $userId = null; - - public function __construct(PermissionManager $permissionManager, InitialStateService $initialStateService, ?string $userId) { - $this->permissionManager = $permissionManager; - $this->initialStateService = $initialStateService; - $this->userId = $userId; + public function __construct( + private PermissionManager $permissionManager, + private InitialStateService $initialStateService, + private ?string $userId, + ) { } public function handle(Event $event): void { diff --git a/lib/Listener/ShareLinkListener.php b/lib/Listener/ShareLinkListener.php index 4b8b9c23fc..b4346c923f 100644 --- a/lib/Listener/ShareLinkListener.php +++ b/lib/Listener/ShareLinkListener.php @@ -21,14 +21,10 @@ /** @template-implements IEventListener */ class ShareLinkListener implements \OCP\EventDispatcher\IEventListener { - /** @var PermissionManager */ - private $permissionManager; - /** @var InitialStateService */ - private $initialStateService; - - public function __construct(PermissionManager $permissionManager, InitialStateService $initialStateService) { - $this->permissionManager = $permissionManager; - $this->initialStateService = $initialStateService; + public function __construct( + private PermissionManager $permissionManager, + private InitialStateService $initialStateService, + ) { } public function handle(Event $event): void { diff --git a/lib/Middleware/WOPIMiddleware.php b/lib/Middleware/WOPIMiddleware.php index 81b00688e4..de5aa2322f 100644 --- a/lib/Middleware/WOPIMiddleware.php +++ b/lib/Middleware/WOPIMiddleware.php @@ -32,7 +32,7 @@ public function __construct( private IConfig $config, private IRequest $request, private WopiMapper $wopiMapper, - private LoggerInterface $logger + private LoggerInterface $logger, ) { } diff --git a/lib/Migration/InstallDefaultFonts.php b/lib/Migration/InstallDefaultFonts.php index 4bcb477759..602859cc8c 100644 --- a/lib/Migration/InstallDefaultFonts.php +++ b/lib/Migration/InstallDefaultFonts.php @@ -11,7 +11,10 @@ use OCP\Migration\IRepairStep; class InstallDefaultFonts implements IRepairStep { - public function __construct(private IConfig $config, private FontService $fontService) { + public function __construct( + private IConfig $config, + private FontService $fontService, + ) { } public function getName(): string { diff --git a/lib/PermissionManager.php b/lib/PermissionManager.php index 3beb9baa85..49f0a79eaa 100644 --- a/lib/PermissionManager.php +++ b/lib/PermissionManager.php @@ -19,27 +19,14 @@ use OCP\SystemTag\ISystemTagObjectMapper; class PermissionManager { - private AppConfig $appConfig; - private IConfig $config; - private IGroupManager $groupManager; - private IUserManager $userManager; - private IUserSession $userSession; - private ISystemTagObjectMapper $systemTagObjectMapper; - public function __construct( - AppConfig $appConfig, - IConfig $config, - IGroupManager $groupManager, - IUserManager $userManager, - IUserSession $userSession, - ISystemTagObjectMapper $systemTagObjectMapper + private AppConfig $appConfig, + private IConfig $config, + private IGroupManager $groupManager, + private IUserManager $userManager, + private IUserSession $userSession, + private ISystemTagObjectMapper $systemTagObjectMapper, ) { - $this->appConfig = $appConfig; - $this->config = $config; - $this->groupManager = $groupManager; - $this->userManager = $userManager; - $this->userSession = $userSession; - $this->systemTagObjectMapper = $systemTagObjectMapper; } private function userMatchesGroupList(?string $userId = null, ?array $groupList = []): bool { diff --git a/lib/Service/CachedRequestService.php b/lib/Service/CachedRequestService.php index 9c71247ac9..14610241d1 100644 --- a/lib/Service/CachedRequestService.php +++ b/lib/Service/CachedRequestService.php @@ -107,7 +107,7 @@ private function getAppDataFolder(): ISimpleFolder { $appData = $this->appDataFactory->get(Application::APPNAME); try { $folder = $appData->getFolder('remoteData'); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $folder = $appData->newFolder('remoteData'); } return $folder; @@ -147,7 +147,7 @@ private function isProxyStarting(): bool { return true; } } - } catch (\Exception $e) { + } catch (\Exception) { // ignore } } diff --git a/lib/Service/DemoService.php b/lib/Service/DemoService.php index bf6511f17c..ffad1225fa 100644 --- a/lib/Service/DemoService.php +++ b/lib/Service/DemoService.php @@ -10,18 +10,10 @@ use OCP\ICache; class DemoService { - /** - * @var ICache - */ - private $cache; - /** - * @var IClientService - */ - private $clientService; - - public function __construct(ICache $cache, IClientService $clientService) { - $this->cache = $cache; - $this->clientService = $clientService; + public function __construct( + private ICache $cache, + private IClientService $clientService, + ) { } public function fetchDemoServers($refresh = false) { @@ -34,7 +26,7 @@ public function fetchDemoServers($refresh = false) { try { $response = $client->get($demoServerList); $servers = json_decode($response->getBody(), true)['servers'] ?? []; - } catch (\Exception $e) { + } catch (\Exception) { $servers = []; } $this->cache->set('richdocuments-demo', json_encode($servers)); diff --git a/lib/Service/FederationService.php b/lib/Service/FederationService.php index 617d64dec3..1ef612bde3 100644 --- a/lib/Service/FederationService.php +++ b/lib/Service/FederationService.php @@ -32,34 +32,22 @@ class FederationService { /** @var ICache */ private $cache; - /** @var IClientService */ - private $clientService; - /** @var LoggerInterface */ - private $logger; /** @var TrustedServers */ private $trustedServers; - /** @var AppConfig */ - private $appConfig; - /** @var TokenManager */ - private $tokenManager; - /** @var IRequest */ - private $request; - /** @var IURLGenerator */ - private $urlGenerator; - - public function __construct(ICacheFactory $cacheFactory, IClientService $clientService, LoggerInterface $logger, TokenManager $tokenManager, AppConfig $appConfig, IRequest $request, IURLGenerator $urlGenerator) { + + public function __construct( + ICacheFactory $cacheFactory, + private IClientService $clientService, + private LoggerInterface $logger, + private TokenManager $tokenManager, + private AppConfig $appConfig, + private IRequest $request, + private IURLGenerator $urlGenerator, + ) { $this->cache = $cacheFactory->createDistributed('richdocuments_remote/'); - $this->clientService = $clientService; - $this->logger = $logger; - $this->tokenManager = $tokenManager; - $this->appConfig = $appConfig; - $this->request = $request; - $this->urlGenerator = $urlGenerator; try { $this->trustedServers = \OC::$server->get(\OCA\Federation\TrustedServers::class); - } catch (NotFoundExceptionInterface $e) { - } catch (ContainerExceptionInterface $e) { - } catch (AutoloadNotAllowedException $e) { + } catch (NotFoundExceptionInterface|ContainerExceptionInterface|AutoloadNotAllowedException) { } } @@ -68,9 +56,7 @@ public function getTrustedServers(): array { return []; } - return array_map(function (array $server) { - return $server['url']; - }, $this->trustedServers->getServers()); + return array_map(fn (array $server) => $server['url'], $this->trustedServers->getServers()); } /** @@ -80,7 +66,7 @@ public function getTrustedServers(): array { */ public function getRemoteCollaboraURL($remote) { // If no protocol is provided we default to https - if (strpos($remote, 'http://') !== 0 && strpos($remote, 'https://') !== 0) { + if (!str_starts_with($remote, 'http://') && !str_starts_with($remote, 'https://')) { $remote = 'https://' . $remote; } @@ -106,7 +92,7 @@ public function getRemoteCollaboraURL($remote) { } public function isTrustedRemote($domainWithPort) { - if (strpos($domainWithPort, 'http://') === 0 || strpos($domainWithPort, 'https://') === 0) { + if (str_starts_with($domainWithPort, 'http://') || str_starts_with($domainWithPort, 'https://')) { $port = parse_url($domainWithPort, PHP_URL_PORT); $domainWithPort = parse_url($domainWithPort, PHP_URL_HOST) . ($port ? ':' . $port : ''); } @@ -126,9 +112,7 @@ public function isTrustedRemote($domainWithPort) { if (!is_string($trusted)) { break; } - $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function ($v) { - return preg_quote($v, '/'); - }, explode('*', $trusted))) . '$/i'; + $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(fn ($v) => preg_quote($v, '/'), explode('*', $trusted))) . '$/i'; if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { return true; } diff --git a/lib/Service/FontService.php b/lib/Service/FontService.php index 5122235adf..621697b1f1 100644 --- a/lib/Service/FontService.php +++ b/lib/Service/FontService.php @@ -18,32 +18,18 @@ class FontService { private const INVALIDATE_FONT_LIST_CACHE_AFTER_SECONDS = 3600; - - /** - * @var IAppData - */ - private $appData; /** * @var \OCP\ICache */ private $cache; - /** - * @var IURLGenerator - */ - private $url; - /** - * @var IConfig - */ - private $config; - public function __construct(IAppData $appData, + public function __construct( + private IAppData $appData, ICacheFactory $cacheFactory, - IURLGenerator $url, - IConfig $config) { - $this->appData = $appData; + private IURLGenerator $url, + private IConfig $config, + ) { $this->cache = $cacheFactory->createDistributed(Application::APPNAME); - $this->url = $url; - $this->config = $config; } /** @@ -53,7 +39,7 @@ public function __construct(IAppData $appData, private function getFontAppDataDir(): ISimpleFolder { try { return $this->appData->getFolder('fonts'); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return $this->appData->newFolder('fonts'); } } @@ -65,7 +51,7 @@ private function getFontAppDataDir(): ISimpleFolder { private function getFontOverviewAppDataDir(): ISimpleFolder { try { return $this->appData->getFolder('font-overviews'); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return $this->appData->newFolder('font-overviews'); } } @@ -93,9 +79,7 @@ public function getFontFileNames(): array { if ($cachedNames === null) { $files = $this->getFontFiles(); $cachedNames = array_map( - static function (ISimpleFile $f) { - return $f->getName(); - }, + static fn (ISimpleFile $f) => $f->getName(), $files ); $this->cache->set($cacheKey, $cachedNames, self::INVALIDATE_FONT_LIST_CACHE_AFTER_SECONDS); @@ -113,12 +97,10 @@ static function (ISimpleFile $f) { public function getFontList(array $fontFiles): array { $url = $this->url; $list = array_map( - static function (ISimpleFile $f) use ($url) { - return [ - 'uri' => $url->linkToRouteAbsolute(Application::APPNAME . '.settings.getFontFile', ['name' => $f->getName()]), - 'stamp' => $f->getETag(), - ]; - }, + static fn (ISimpleFile $f) => [ + 'uri' => $url->linkToRouteAbsolute(Application::APPNAME . '.settings.getFontFile', ['name' => $f->getName()]), + 'stamp' => $f->getETag(), + ], $fontFiles ); @@ -220,7 +202,7 @@ private function generateFontOverview(ISimpleFile $fontFile): void { imagepng($im, $imageFileResource); imagedestroy($im); } - } catch (\Exception|\Throwable $e) { + } catch (\Exception|\Throwable) { // do nothing if there was any kind of error during overview generation // the /apps/richdocuments/settings/fonts/FILE_NAME/overview request will fail with 404 // in the UI and display a fallback message diff --git a/lib/Service/PdfService.php b/lib/Service/PdfService.php index 261cfc2cfd..2499e783d5 100644 --- a/lib/Service/PdfService.php +++ b/lib/Service/PdfService.php @@ -15,7 +15,7 @@ class PdfService { public function __construct( - private LoggerInterface $logger + private LoggerInterface $logger, ) { } diff --git a/lib/Service/RemoteService.php b/lib/Service/RemoteService.php index d476bf7680..06937d373b 100644 --- a/lib/Service/RemoteService.php +++ b/lib/Service/RemoteService.php @@ -24,7 +24,7 @@ public function fetchTargets($file): array { $client = $this->clientService->newClient(); try { $response = $client->put( - $this->appConfig->getCollaboraUrlInternal(). '/cool/extract-link-targets', + $this->appConfig->getCollaboraUrlInternal() . '/cool/extract-link-targets', $this->getRequestOptionsForFile($file) ); } catch (Exception $e) { @@ -46,7 +46,7 @@ public function fetchTargets($file): array { public function fetchTargetThumbnail(File $file, string $target): ?string { $client = $this->clientService->newClient(); try { - $response = $client->put($this->appConfig->getCollaboraUrlInternal(). '/cool/get-thumbnail', $this->getRequestOptionsForFile($file, $target)); + $response = $client->put($this->appConfig->getCollaboraUrlInternal() . '/cool/get-thumbnail', $this->getRequestOptionsForFile($file, $target)); return (string)$response->getBody(); } catch (Exception $e) { $this->logger->info('Failed to fetch target thumbnail', ['exception' => $e]); diff --git a/lib/Service/UserScopeService.php b/lib/Service/UserScopeService.php index 1d278c9685..d622443d26 100644 --- a/lib/Service/UserScopeService.php +++ b/lib/Service/UserScopeService.php @@ -14,7 +14,7 @@ class UserScopeService { public function __construct( private IUserSession $userSession, - private IUserManager $userManager + private IUserManager $userManager, ) { } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 3cd692532a..9c99946772 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -24,7 +24,7 @@ public function __construct( private CapabilitiesService $capabilitiesService, private DemoService $demoService, private FontService $fontService, - private InitialStateService $initialStateService + private InitialStateService $initialStateService, ) { } diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 03c544597c..bd0af6753d 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -13,23 +13,12 @@ use OCP\Settings\ISettings; class Personal implements ISettings { - /** @var IConfig Config */ - private $config; - - /** @var CapabilitiesService */ - private $capabilitiesService; - - /** @var InitialStateService */ - private $initialState; - - /** @var string */ - private $userId; - - public function __construct(IConfig $config, CapabilitiesService $capabilitiesService, InitialStateService $initialStateService, $userId) { - $this->config = $config; - $this->capabilitiesService = $capabilitiesService; - $this->initialState = $initialStateService; - $this->userId = $userId; + public function __construct( + private IConfig $config, + private CapabilitiesService $capabilitiesService, + private InitialStateService $initialState, + private ?string $userId, + ) { } /** @psalm-suppress InvalidNullableReturnType */ diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php index d48a7b2e5d..5d7db05f3b 100644 --- a/lib/Settings/Section.php +++ b/lib/Settings/Section.php @@ -12,17 +12,11 @@ use OCP\Settings\IIconSection; class Section implements IIconSection { - /** @var IURLGenerator */ - private $url; - /** @var CapabilitiesService */ - private $capabilitites; - /** @var IL10N */ - private $l10n; - - public function __construct(IURLGenerator $url, CapabilitiesService $capabilities, IL10N $l10n) { - $this->url = $url; - $this->capabilitites = $capabilities; - $this->l10n = $l10n; + public function __construct( + private IURLGenerator $url, + private CapabilitiesService $capabilitites, + private IL10N $l10n, + ) { } public function getID() { diff --git a/lib/Template/CollaboraTemplateProvider.php b/lib/Template/CollaboraTemplateProvider.php index b889d3a4ca..b9f48ebd9c 100644 --- a/lib/Template/CollaboraTemplateProvider.php +++ b/lib/Template/CollaboraTemplateProvider.php @@ -21,7 +21,7 @@ class CollaboraTemplateProvider implements ICustomTemplateProvider { public function __construct( private TemplateManager $templateManager, private IURLGenerator $urlGenerator, - private ITemplateManager $coreTemplateManager + private ITemplateManager $coreTemplateManager, ) { } @@ -57,7 +57,7 @@ private function isSameUserTemplateFolder(): bool { $internalPath = $userTemplatesFolder->getInternalPath(); $userTemplatePath = mb_strpos($internalPath, 'files/') === 0 ? mb_substr($internalPath, 5): $internalPath; return $this->coreTemplateManager->getTemplatePath() === $userTemplatePath; - } catch (NotFoundException $e) { + } catch (NotFoundException) { } return false; } diff --git a/lib/TemplateManager.php b/lib/TemplateManager.php index bc6b578a96..b1709b3ebd 100644 --- a/lib/TemplateManager.php +++ b/lib/TemplateManager.php @@ -27,27 +27,6 @@ class TemplateManager { /** @var string */ protected $userId; - /** @var IConfig */ - private $config; - - /** @var IURLGenerator */ - private $urlGenerator; - - /** @var IRootFolder */ - private $rootFolder; - - /** @var IL10N */ - private $l; - - /** @var IDBConnection */ - private $db; - - /** @var IAppData */ - private $appData; - - /** @var LoggerInterface */ - private $logger; - /** Accepted templates mime types */ public const MIMES_DOCUMENTS = [ 'application/vnd.oasis.opendocument.text-template', @@ -91,22 +70,15 @@ class TemplateManager { public function __construct( ?string $userId, - IConfig $config, - IAppData $appData, - IURLGenerator $urlGenerator, - IRootFolder $rootFolder, - IL10N $l, - IDBConnection $connection, - LoggerInterface $logger + private IConfig $config, + private IAppData $appData, + private IURLGenerator $urlGenerator, + private IRootFolder $rootFolder, + private IL10N $l, + private IDBConnection $db, + private LoggerInterface $logger, ) { $this->userId = $userId; - $this->config = $config; - $this->rootFolder = $rootFolder; - $this->urlGenerator = $urlGenerator; - $this->db = $connection; - $this->logger = $logger; - $this->appData = $appData; - $this->l = $l; } private function ensureAppDataFolders() { @@ -117,12 +89,12 @@ private function ensureAppDataFolders() { */ try { $this->appData->getFolder('templates'); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $this->appData->newFolder('templates'); } try { $this->appData->getFolder('empty_templates'); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $this->appData->newFolder('empty_templates'); } } @@ -185,21 +157,13 @@ private function filterTemplates($templates, $type = null) { } public function getTemplateTypeForExtension(string $extension): ?string { - switch ($extension) { - case 'odt': - case 'docx': - return 'document'; - case 'ods': - case 'xlsx': - return 'spreadsheet'; - case 'odp': - case 'pptx': - return 'presentation'; - case 'odg': - return 'drawing'; - } - - return null; + return match ($extension) { + 'odt', 'docx' => 'document', + 'ods', 'xlsx' => 'spreadsheet', + 'odp', 'pptx' => 'presentation', + 'odg' => 'drawing', + default => null, + }; } public function getEmpty($type = null) { @@ -234,7 +198,7 @@ public function updateEmptyTemplates() { try { $folder = $this->getEmptyTemplateDir(); $folder->delete(); - } catch (NotFoundException $e) { + } catch (NotFoundException) { } $this->appData->newFolder('empty_templates'); $this->getEmpty(); @@ -262,13 +226,9 @@ public function getSystemFormatted($type = null) { $empty = $this->getEmpty($type); $system = $this->getSystem($type); - $emptyFormatted = array_map(function (File $file) { - return $this->formatEmpty($file); - }, $empty); + $emptyFormatted = array_map(fn (File $file) => $this->formatEmpty($file), $empty); - $systemFormatted = array_map(function (File $file) { - return $this->formatNodeReturn($file); - }, $system); + $systemFormatted = array_map(fn (File $file) => $this->formatNodeReturn($file), $system); return array_merge($emptyFormatted, $systemFormatted); } @@ -288,7 +248,7 @@ public function getUser($type = null) { $templateFiles = $templateDir->getDirectoryListing(); return $this->filterTemplates($templateFiles, $type); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return []; } } @@ -303,9 +263,7 @@ public function getUserFormatted($type) { $templates = $this->getUser($type); - return array_map(function (File $file) { - return $this->formatNodeReturn($file); - }, $templates); + return array_map(fn (File $file) => $this->formatNodeReturn($file), $templates); } /** @@ -354,7 +312,7 @@ public function add($templateName, $templateFile) { try { $template = $folder->get($templateName); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $template = $folder->newFile($templateName); } $template->putContent($templateFile); @@ -416,7 +374,7 @@ public function getUserTemplateDir() { // fallback to default template dir try { $templateDir = $userFolder->get('Templates'); - } catch (NotFoundException $e) { + } catch (NotFoundException) { throw new NotFoundException('Template directory not found'); } } diff --git a/lib/WOPI/Parser.php b/lib/WOPI/Parser.php index 8c654a34cb..f34edf9dee 100644 --- a/lib/WOPI/Parser.php +++ b/lib/WOPI/Parser.php @@ -13,7 +13,7 @@ class Parser { public function __construct( private DiscoveryService $discoveryService, - private LoggerInterface $logger + private LoggerInterface $logger, ) { } diff --git a/rector.php b/rector.php new file mode 100644 index 0000000000..7842d94900 --- /dev/null +++ b/rector.php @@ -0,0 +1,23 @@ +withPaths([ + __DIR__ . '/appinfo', + __DIR__ . '/lib', + __DIR__ . '/tests', + ]) + ->withPhpSets(php81: true) + ->withTypeCoverageLevel(0) + ->withSets([ + // NextcloudSets::NEXTCLOUD_30, + ]); diff --git a/tests/OCA/Richdocuments/Listener/AddFeaturePolicyListenerTest.php b/tests/OCA/Richdocuments/Listener/AddFeaturePolicyListenerTest.php index c358558b06..b7be8fccbd 100644 --- a/tests/OCA/Richdocuments/Listener/AddFeaturePolicyListenerTest.php +++ b/tests/OCA/Richdocuments/Listener/AddFeaturePolicyListenerTest.php @@ -51,7 +51,7 @@ private function getMergedPolicy(): \OC\Security\FeaturePolicy\FeaturePolicy { $eventDispatcher = $this->createMock(IEventDispatcher::class); $eventDispatcher->expects(self::once()) ->method('dispatchTyped') - ->willReturnCallback(function ($event) { + ->willReturnCallback(function ($event): void { $this->featurePolicyListener->handle($event); }); $manager = new FeaturePolicyManager($eventDispatcher); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 738e1e2e01..cf8552eeea 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,9 +8,9 @@ define('PHPUNIT_RUN', 1); } -require_once __DIR__.'/../../../lib/base.php'; +require_once __DIR__ . '/../../../lib/base.php'; -if (!class_exists('\PHPUnit\Framework\TestCase')) { +if (!class_exists(\PHPUnit\Framework\TestCase::class)) { require_once('PHPUnit/Autoload.php'); } \OC_App::loadApp('richdocuments'); diff --git a/tests/features/bootstrap/ApiContext.php b/tests/features/bootstrap/ApiContext.php index 465b971312..acb27eb10d 100644 --- a/tests/features/bootstrap/ApiContext.php +++ b/tests/features/bootstrap/ApiContext.php @@ -71,7 +71,7 @@ public function userFillsInFieldsOfWithValuesAsTo($user, $source, ?string $conve ]; } - $this->serverContext->sendOCSRequest('POST', 'apps/richdocuments/api/v1/template/fields/fill/' . $fileId . '?' + $this->serverContext->sendOCSRequest('POST', 'apps/richdocuments/api/v1/template/fields/fill/' . $fileId . '?' . ($convert ? '&convert=' . $convert : '') . ($target ? '&destination=' . $target : ''), ['fields' => $formData]); diff --git a/tests/features/bootstrap/DirectContext.php b/tests/features/bootstrap/DirectContext.php index 47d9995ac4..a2c8bb96c7 100644 --- a/tests/features/bootstrap/DirectContext.php +++ b/tests/features/bootstrap/DirectContext.php @@ -112,9 +112,9 @@ private function handleDirectEditingLink() { $redirects = $response->getHeader('X-Guzzle-Redirect-History'); $lastServer = array_pop($redirects); if ($lastServer) { - $currentServer = parse_url($lastServer, PHP_URL_SCHEME) . '://'. parse_url($lastServer, PHP_URL_HOST) . ( + $currentServer = parse_url($lastServer, PHP_URL_SCHEME) . '://' . parse_url($lastServer, PHP_URL_HOST) . ( parse_url($lastServer, PHP_URL_PORT) ? ':' . parse_url($lastServer, PHP_URL_PORT) : '' - ). '/'; + ) . '/'; } $contents = $response->getBody()->getContents(); @@ -128,7 +128,7 @@ private function handleDirectEditingLink() { Assert::assertNotEmpty($initialState['document']['fileId']); Assert::assertNotEmpty($initialState['document']['token']); - $currentServer = $currentServer ?? $this->serverContext->getBaseUrl(); + $currentServer ??= $this->serverContext->getBaseUrl(); $this->wopiContext->setWopiParameters($currentServer, $initialState['document']['fileId'], $initialState['document']['token']); Assert::assertEquals(200, $response->getStatusCode()); diff --git a/tests/features/bootstrap/RichDocumentsContext.php b/tests/features/bootstrap/RichDocumentsContext.php index b5b32cb294..786e5b3669 100644 --- a/tests/features/bootstrap/RichDocumentsContext.php +++ b/tests/features/bootstrap/RichDocumentsContext.php @@ -65,9 +65,9 @@ public function userOpens($user, $file) { $redirects = $result->getHeader('X-Guzzle-Redirect-History'); $lastServer = array_pop($redirects); if ($lastServer) { - $this->currentServer = parse_url($lastServer, PHP_URL_SCHEME) . '://'. parse_url($lastServer, PHP_URL_HOST) . ( + $this->currentServer = parse_url($lastServer, PHP_URL_SCHEME) . '://' . parse_url($lastServer, PHP_URL_HOST) . ( parse_url($lastServer, PHP_URL_PORT) ? ':' . parse_url($lastServer, PHP_URL_PORT) : '' - ). '/'; + ) . '/'; } $this->extractRichdocumentsFrontendContext($result); @@ -87,7 +87,7 @@ public function generateTokenWithApi($user, $fileId, ?string $shareToken = null, $response = $this->serverContext->getOCSResponse(); - $this->fileId = $fileId . '_ocfake'; + $this->fileId = $fileId . '_ocfake'; $this->fileIds[] = $this->fileId; $this->wopiToken = $response['token']; $this->wopiContext->setWopiParameters($this->currentServer, $this->fileId, $this->wopiToken); @@ -192,9 +192,9 @@ public function userCreatesANewFileFromATemplate($user, $file) { $redirects = $result->getHeader('X-Guzzle-Redirect-History'); $lastServer = array_pop($redirects); if ($lastServer) { - $this->currentServer = parse_url($lastServer, PHP_URL_SCHEME) . '://'. parse_url($lastServer, PHP_URL_HOST) . ( + $this->currentServer = parse_url($lastServer, PHP_URL_SCHEME) . '://' . parse_url($lastServer, PHP_URL_HOST) . ( parse_url($lastServer, PHP_URL_PORT) ? ':' . parse_url($lastServer, PHP_URL_PORT) : '' - ). '/'; + ) . '/'; } $this->extractRichdocumentsFrontendContext($result); diff --git a/tests/lib/Listener/AddContentSecurityPolicyListenerTest.php b/tests/lib/Listener/AddContentSecurityPolicyListenerTest.php index f9787882c7..67577ef83f 100644 --- a/tests/lib/Listener/AddContentSecurityPolicyListenerTest.php +++ b/tests/lib/Listener/AddContentSecurityPolicyListenerTest.php @@ -72,7 +72,7 @@ private function getMergedPolicy(): ContentSecurityPolicy { $eventDispatcher = $this->createMock(IEventDispatcher::class); $eventDispatcher->expects(self::once()) ->method('dispatchTyped') - ->willReturnCallback(function ($event) { + ->willReturnCallback(function ($event): void { $this->listener->handle($event); }); $manager = new ContentSecurityPolicyManager($eventDispatcher); @@ -191,7 +191,7 @@ public function testHandleMerged() { $eventDispatcher = $this->createMock(IEventDispatcher::class); $eventDispatcher->expects(self::once()) ->method('dispatchTyped') - ->willReturnCallback(function (AddContentSecurityPolicyEvent $event) { + ->willReturnCallback(function (AddContentSecurityPolicyEvent $event): void { $otherPolicy = new EmptyContentSecurityPolicy(); $otherPolicy->addAllowedFrameDomain('external.example.com'); $otherPolicy->addAllowedFormActionDomain('external.example.com'); @@ -203,7 +203,7 @@ public function testHandleMerged() { $policy = $manager->getDefaultPolicy(); - self::assertArrayUnordered(["'self'", 'external.example.com', 'http://public', 'nc:'], $policy->getAllowedFrameDomains(), 'Domains are equal', 0.0, 10, true); + self::assertArrayUnordered(["'self'", 'external.example.com', 'http://public', 'nc:'], $policy->getAllowedFrameDomains(), 'Domains are equal'); self::assertArrayUnordered(["'self'", 'external.example.com', 'http://public'], $policy->getAllowedFormActionDomains()); }