From c95b5179c9e1118a397b703d8031a04ce5b85564 Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 10:57:23 +0800 Subject: [PATCH 01/14] feat(cs): update cs config --- .php-cs-fixer.dist.php | 1 + 1 file changed, 1 insertion(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f7bbdd8..529762c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,6 +10,7 @@ $config ->getFinder() ->ignoreVCSIgnored(true) + ->notPath('dev-environment') ->notPath('build') ->notPath('l10n') ->notPath('src') From e8876a1a135a4f3e22b66a416eaa53ade126e750 Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 10:57:38 +0800 Subject: [PATCH 02/14] feat(cs): update composer deps --- composer.json | 10 +- composer.lock | 2135 ++----------------------------------------------- 2 files changed, 68 insertions(+), 2077 deletions(-) diff --git a/composer.json b/composer.json index 7180be6..162d2b4 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,12 @@ "ext-curl": "*" }, "require-dev": { - "nextcloud/coding-standard": "^0.5.0", - "christophwurst/nextcloud": "^22", - "ext-fileinfo": "*" + "nextcloud/coding-standard": "^1.3.2", + "ext-fileinfo": "*", + "friendsofphp/php-cs-fixer": "*" + }, + "scripts": { + "cs:check": "./vendor/php-cs-fixer/shim/php-cs-fixer.phar fix --dry-run --diff", + "cs:fix": "./vendor/php-cs-fixer/shim/php-cs-fixer.phar fix" } } diff --git a/composer.lock b/composer.lock index e9b6cd9..7ec96b0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,145 +4,36 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "eb0300c3b09e41a72f2b682cc5c6eab9", + "content-hash": "9a0365504a1790b1f04538b1f0ddd13d", "packages": [], "packages-dev": [ { - "name": "christophwurst/nextcloud", - "version": "v22.1.1", + "name": "kubawerlos/php-cs-fixer-custom-fixers", + "version": "v3.22.0", "source": { "type": "git", - "url": "https://github.com/ChristophWurst/nextcloud_composer.git", - "reference": "8bb086cd016128b5ef8353662fd1852db3248d1e" + "url": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers.git", + "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/8bb086cd016128b5ef8353662fd1852db3248d1e", - "reference": "8bb086cd016128b5ef8353662fd1852db3248d1e", + "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/8701394f0c7cd450ac4fa577d24589122c1d5d5e", + "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e", "shasum": "" }, "require": { - "php": "^7.3 || ~8.0.0", - "psr/container": "^1.0", - "psr/event-dispatcher": "^1.0", - "psr/log": "^1.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "23.0.0-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "AGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Christoph Wurst", - "email": "christoph@winzerhof-wurst.at" - } - ], - "description": "Composer package containing Nextcloud's public API (classes, interfaces)", - "time": "2021-11-11T14:01:42+00:00" - }, - { - "name": "composer/pcre", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/composer/pcre.git", - "reference": "67a32d7d6f9f560b726ab25a061b38ff3a80c560" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/67a32d7d6f9f560b726ab25a061b38ff3a80c560", - "reference": "67a32d7d6f9f560b726ab25a061b38ff3a80c560", - "shasum": "" - }, - "require": { - "php": "^5.3.2 || ^7.0 || ^8.0" - }, - "require-dev": { - "phpstan/phpstan": "^1.3", - "phpstan/phpstan-strict-rules": "^1.1", - "symfony/phpunit-bridge": "^4.2 || ^5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\Pcre\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "PCRE wrapping library that offers type-safe preg_* replacements.", - "keywords": [ - "PCRE", - "preg", - "regex", - "regular expression" - ], - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2022-01-21T20:24:37+00:00" - }, - { - "name": "composer/semver", - "version": "3.3.1", - "source": { - "type": "git", - "url": "https://github.com/composer/semver.git", - "reference": "5d8e574bb0e69188786b8ef77d43341222a41a71" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/5d8e574bb0e69188786b8ef77d43341222a41a71", - "reference": "5d8e574bb0e69188786b8ef77d43341222a41a71", - "shasum": "" - }, - "require": { - "php": "^5.3.2 || ^7.0 || ^8.0" + "ext-filter": "*", + "ext-tokenizer": "*", + "friendsofphp/php-cs-fixer": "^3.61.1", + "php": "^7.4 || ^8.0" }, "require-dev": { - "phpstan/phpstan": "^1.4", - "symfony/phpunit-bridge": "^4.2 || ^5" + "phpunit/phpunit": "^9.6.4 || ^10.5.29" }, "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.x-dev" - } - }, "autoload": { "psr-4": { - "Composer\\Semver\\": "src" + "PhpCsFixerCustomFixers\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -151,136 +42,40 @@ ], "authors": [ { - "name": "Nils Adermann", - "email": "naderman@naderman.de", - "homepage": "http://www.naderman.de" - }, - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - }, - { - "name": "Rob Bast", - "email": "rob.bast@gmail.com", - "homepage": "http://robbast.nl" - } - ], - "description": "Semver library that offers utilities, version constraint parsing and validation.", - "keywords": [ - "semantic", - "semver", - "validation", - "versioning" - ], - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" + "name": "Kuba Werłos", + "email": "werlos@gmail.com" } ], - "time": "2022-03-16T11:22:07+00:00" - }, - { - "name": "composer/xdebug-handler", - "version": "2.0.5", - "source": { - "type": "git", - "url": "https://github.com/composer/xdebug-handler.git", - "reference": "9e36aeed4616366d2b690bdce11f71e9178c579a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/9e36aeed4616366d2b690bdce11f71e9178c579a", - "reference": "9e36aeed4616366d2b690bdce11f71e9178c579a", - "shasum": "" - }, - "require": { - "composer/pcre": "^1", - "php": "^5.3.2 || ^7.0 || ^8.0", - "psr/log": "^1 || ^2 || ^3" - }, - "require-dev": { - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-strict-rules": "^1.1", - "symfony/phpunit-bridge": "^4.2 || ^5.0 || ^6.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Composer\\XdebugHandler\\": "src" - } + "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" }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "John Stevenson", - "email": "john-stevenson@blueyonder.co.uk" - } - ], - "description": "Restarts a process without Xdebug.", - "keywords": [ - "Xdebug", - "performance" - ], - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2022-02-24T20:20:32+00:00" + "time": "2024-08-16T20:44:35+00:00" }, { - "name": "doctrine/annotations", - "version": "1.13.2", + "name": "nextcloud/coding-standard", + "version": "v1.3.2", "source": { "type": "git", - "url": "https://github.com/doctrine/annotations.git", - "reference": "5b668aef16090008790395c02c893b1ba13f7e08" + "url": "https://github.com/nextcloud/coding-standard.git", + "reference": "9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/5b668aef16090008790395c02c893b1ba13f7e08", - "reference": "5b668aef16090008790395c02c893b1ba13f7e08", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d", + "reference": "9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d", "shasum": "" }, "require": { - "doctrine/lexer": "1.*", - "ext-tokenizer": "*", - "php": "^7.1 || ^8.0", - "psr/cache": "^1 || ^2 || ^3" - }, - "require-dev": { - "doctrine/cache": "^1.11 || ^2.0", - "doctrine/coding-standard": "^6.0 || ^8.1", - "phpstan/phpstan": "^0.12.20", - "phpunit/phpunit": "^7.5 || ^8.0 || ^9.1.5", - "symfony/cache": "^4.4 || ^5.2" + "kubawerlos/php-cs-fixer-custom-fixers": "^3.22", + "php": "^7.3|^8.0", + "php-cs-fixer/shim": "^3.17" }, "type": "library", "autoload": { "psr-4": { - "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + "Nextcloud\\CodingStandard\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -289,189 +84,48 @@ ], "authors": [ { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at" } ], - "description": "Docblock Annotations Parser", - "homepage": "https://www.doctrine-project.org/projects/annotations.html", - "keywords": [ - "annotations", - "docblock", - "parser" - ], - "time": "2021-08-05T19:00:23+00:00" - }, - { - "name": "doctrine/lexer", - "version": "1.2.3", - "source": { - "type": "git", - "url": "https://github.com/doctrine/lexer.git", - "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/c268e882d4dbdd85e36e4ad69e02dc284f89d229", - "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "require-dev": { - "doctrine/coding-standard": "^9.0", - "phpstan/phpstan": "^1.3", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.11" - }, - "type": "library", - "autoload": { - "psr-4": { - "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" - } + "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.3.2" }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", - "homepage": "https://www.doctrine-project.org/projects/lexer.html", - "keywords": [ - "annotations", - "docblock", - "lexer", - "parser", - "php" - ], - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer", - "type": "tidelift" - } - ], - "time": "2022-02-28T11:07:21+00:00" + "time": "2024-10-14T16:49:05+00:00" }, { - "name": "friendsofphp/php-cs-fixer", - "version": "v2.19.3", + "name": "php-cs-fixer/shim", + "version": "v3.65.0", "source": { "type": "git", - "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "75ac86f33fab4714ea5a39a396784d83ae3b5ed8" + "url": "https://github.com/PHP-CS-Fixer/shim.git", + "reference": "4983ec79b9dee926695ac324ea6e8d291935525d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/75ac86f33fab4714ea5a39a396784d83ae3b5ed8", - "reference": "75ac86f33fab4714ea5a39a396784d83ae3b5ed8", + "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/4983ec79b9dee926695ac324ea6e8d291935525d", + "reference": "4983ec79b9dee926695ac324ea6e8d291935525d", "shasum": "" }, "require": { - "composer/semver": "^1.4 || ^2.0 || ^3.0", - "composer/xdebug-handler": "^1.2 || ^2.0", - "doctrine/annotations": "^1.2", "ext-json": "*", "ext-tokenizer": "*", - "php": "^5.6 || ^7.0 || ^8.0", - "php-cs-fixer/diff": "^1.3", - "symfony/console": "^3.4.43 || ^4.1.6 || ^5.0", - "symfony/event-dispatcher": "^3.0 || ^4.0 || ^5.0", - "symfony/filesystem": "^3.0 || ^4.0 || ^5.0", - "symfony/finder": "^3.0 || ^4.0 || ^5.0", - "symfony/options-resolver": "^3.0 || ^4.0 || ^5.0", - "symfony/polyfill-php70": "^1.0", - "symfony/polyfill-php72": "^1.4", - "symfony/process": "^3.0 || ^4.0 || ^5.0", - "symfony/stopwatch": "^3.0 || ^4.0 || ^5.0" + "php": "^7.4 || ^8.0" }, - "require-dev": { - "justinrainbow/json-schema": "^5.0", - "keradus/cli-executor": "^1.4", - "mikey179/vfsstream": "^1.6", - "php-coveralls/php-coveralls": "^2.4.2", - "php-cs-fixer/accessible-object": "^1.0", - "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2", - "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1", - "phpspec/prophecy-phpunit": "^1.1 || ^2.0", - "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.13 || ^9.5", - "phpunitgoodpractices/polyfill": "^1.5", - "phpunitgoodpractices/traits": "^1.9.1", - "sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1", - "symfony/phpunit-bridge": "^5.2.1", - "symfony/yaml": "^3.0 || ^4.0 || ^5.0" + "replace": { + "friendsofphp/php-cs-fixer": "self.version" }, "suggest": { "ext-dom": "For handling output formats in XML", - "ext-mbstring": "For handling non-UTF8 characters.", - "php-cs-fixer/phpunit-constraint-isidenticalstring": "For IsIdenticalString constraint.", - "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "For XmlMatchesXsd constraint.", - "symfony/polyfill-mbstring": "When enabling `ext-mbstring` is not possible." + "ext-mbstring": "For handling non-UTF8 characters." }, "bin": [ - "php-cs-fixer" + "php-cs-fixer", + "php-cs-fixer.phar" ], "type": "application", - "extra": { - "branch-alias": { - "dev-master": "2.19-dev" - } - }, - "autoload": { - "psr-4": { - "PhpCsFixer\\": "src/" - }, - "classmap": [ - "tests/Test/AbstractFixerTestCase.php", - "tests/Test/AbstractIntegrationCaseFactory.php", - "tests/Test/AbstractIntegrationTestCase.php", - "tests/Test/Assert/AssertTokensTrait.php", - "tests/Test/IntegrationCase.php", - "tests/Test/IntegrationCaseFactory.php", - "tests/Test/IntegrationCaseFactoryInterface.php", - "tests/Test/InternalIntegrationCaseFactory.php", - "tests/Test/IsIdenticalConstraint.php", - "tests/Test/TokensWithObservedTransformers.php", - "tests/TestCase.php" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" @@ -487,1690 +141,23 @@ } ], "description": "A tool to automatically fix PHP code style", - "funding": [ - { - "url": "https://github.com/keradus", - "type": "github" - } - ], - "time": "2021-11-15T17:17:55+00:00" - }, - { - "name": "nextcloud/coding-standard", - "version": "v0.5.0", - "source": { - "type": "git", - "url": "https://github.com/nextcloud/coding-standard.git", - "reference": "742ed895ae76c10daf95e08488cfb3f554199f40" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/742ed895ae76c10daf95e08488cfb3f554199f40", - "reference": "742ed895ae76c10daf95e08488cfb3f554199f40", - "shasum": "" - }, - "require": { - "friendsofphp/php-cs-fixer": "^2.17", - "php": "^7.2|^8.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Nextcloud\\CodingStandard\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christoph Wurst", - "email": "christoph@winzerhof-wurst.at" - } - ], - "description": "Nextcloud coding standards for the php cs fixer", - "time": "2021-01-11T14:15:58+00:00" - }, - { - "name": "php-cs-fixer/diff", - "version": "v1.3.1", - "source": { - "type": "git", - "url": "https://github.com/PHP-CS-Fixer/diff.git", - "reference": "dbd31aeb251639ac0b9e7e29405c1441907f5759" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/diff/zipball/dbd31aeb251639ac0b9e7e29405c1441907f5759", - "reference": "dbd31aeb251639ac0b9e7e29405c1441907f5759", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0", - "symfony/process": "^3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "SpacePossum" - } - ], - "description": "sebastian/diff v2 backport support for PHP5.6", - "homepage": "https://github.com/PHP-CS-Fixer", - "keywords": [ - "diff" - ], - "time": "2020-10-14T08:39:05+00:00" - }, - { - "name": "psr/cache", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/cache.git", - "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", - "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" + "support": { + "issues": "https://github.com/PHP-CS-Fixer/shim/issues", + "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.65.0" }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Cache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for caching libraries", - "keywords": [ - "cache", - "psr", - "psr-6" - ], - "time": "2016-08-06T20:24:11+00:00" - }, - { - "name": "psr/container", - "version": "1.1.2", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", - "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", - "shasum": "" - }, - "require": { - "php": ">=7.4.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "time": "2021-11-05T16:50:12+00:00" - }, - { - "name": "psr/event-dispatcher", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/event-dispatcher.git", - "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0", - "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0", - "shasum": "" - }, - "require": { - "php": ">=7.2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\EventDispatcher\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Standard interfaces for event handling.", - "keywords": [ - "events", - "psr", - "psr-14" - ], - "time": "2019-01-08T18:20:26+00:00" - }, - { - "name": "psr/log", - "version": "1.1.4", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2021-05-03T11:20:27+00:00" - }, - { - "name": "symfony/console", - "version": "v5.4.5", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "d8111acc99876953f52fe16d4c50eb60940d49ad" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/d8111acc99876953f52fe16d4c50eb60940d49ad", - "reference": "d8111acc99876953f52fe16d4c50eb60940d49ad", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.9", - "symfony/polyfill-php80": "^1.16", - "symfony/service-contracts": "^1.1|^2|^3", - "symfony/string": "^5.1|^6.0" - }, - "conflict": { - "psr/log": ">=3", - "symfony/dependency-injection": "<4.4", - "symfony/dotenv": "<5.1", - "symfony/event-dispatcher": "<4.4", - "symfony/lock": "<4.4", - "symfony/process": "<4.4" - }, - "provide": { - "psr/log-implementation": "1.0|2.0" - }, - "require-dev": { - "psr/log": "^1|^2", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/event-dispatcher": "^4.4|^5.0|^6.0", - "symfony/lock": "^4.4|^5.0|^6.0", - "symfony/process": "^4.4|^5.0|^6.0", - "symfony/var-dumper": "^4.4|^5.0|^6.0" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/lock": "", - "symfony/process": "" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Eases the creation of beautiful and testable command line interfaces", - "homepage": "https://symfony.com", - "keywords": [ - "cli", - "command line", - "console", - "terminal" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-02-24T12:45:35+00:00" - }, - { - "name": "symfony/deprecation-contracts", - "version": "v2.5.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8", - "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-07-12T14:48:14+00:00" - }, - { - "name": "symfony/event-dispatcher", - "version": "v5.4.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "dec8a9f58d20df252b9cd89f1c6c1530f747685d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/dec8a9f58d20df252b9cd89f1c6c1530f747685d", - "reference": "dec8a9f58d20df252b9cd89f1c6c1530f747685d", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/event-dispatcher-contracts": "^2|^3", - "symfony/polyfill-php80": "^1.16" - }, - "conflict": { - "symfony/dependency-injection": "<4.4" - }, - "provide": { - "psr/event-dispatcher-implementation": "1.0", - "symfony/event-dispatcher-implementation": "2.0" - }, - "require-dev": { - "psr/log": "^1|^2|^3", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/error-handler": "^4.4|^5.0|^6.0", - "symfony/expression-language": "^4.4|^5.0|^6.0", - "symfony/http-foundation": "^4.4|^5.0|^6.0", - "symfony/service-contracts": "^1.1|^2|^3", - "symfony/stopwatch": "^4.4|^5.0|^6.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", - "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-01-02T09:53:40+00:00" - }, - { - "name": "symfony/event-dispatcher-contracts", - "version": "v2.5.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "66bea3b09be61613cd3b4043a65a8ec48cfa6d2a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/66bea3b09be61613cd3b4043a65a8ec48cfa6d2a", - "reference": "66bea3b09be61613cd3b4043a65a8ec48cfa6d2a", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "psr/event-dispatcher": "^1" - }, - "suggest": { - "symfony/event-dispatcher-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\EventDispatcher\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to dispatching event", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-07-12T14:48:14+00:00" - }, - { - "name": "symfony/filesystem", - "version": "v5.4.6", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "d53a45039974952af7f7ebc461ccdd4295e29440" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/d53a45039974952af7f7ebc461ccdd4295e29440", - "reference": "d53a45039974952af7f7ebc461ccdd4295e29440", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8", - "symfony/polyfill-php80": "^1.16" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Filesystem\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides basic utilities for the filesystem", - "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-03-02T12:42:23+00:00" - }, - { - "name": "symfony/finder", - "version": "v5.4.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "231313534dded84c7ecaa79d14bc5da4ccb69b7d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/231313534dded84c7ecaa79d14bc5da4ccb69b7d", - "reference": "231313534dded84c7ecaa79d14bc5da4ccb69b7d", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-php80": "^1.16" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Finder\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Finds files and directories via an intuitive fluent interface", - "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-01-26T16:34:36+00:00" - }, - { - "name": "symfony/options-resolver", - "version": "v5.4.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/options-resolver.git", - "reference": "cc1147cb11af1b43f503ac18f31aa3bec213aba8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/cc1147cb11af1b43f503ac18f31aa3bec213aba8", - "reference": "cc1147cb11af1b43f503ac18f31aa3bec213aba8", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-php73": "~1.0", - "symfony/polyfill-php80": "^1.16" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\OptionsResolver\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides an improved replacement for the array_replace PHP function", - "homepage": "https://symfony.com", - "keywords": [ - "config", - "configuration", - "options" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-01-02T09:53:40+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "30885182c981ab175d4d034db0f6f469898070ab" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab", - "reference": "30885182c981ab175d4d034db0f6f469898070ab", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "provide": { - "ext-ctype": "*" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-10-20T20:35:02+00:00" - }, - { - "name": "symfony/polyfill-intl-grapheme", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "81b86b50cf841a64252b439e738e97f4a34e2783" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/81b86b50cf841a64252b439e738e97f4a34e2783", - "reference": "81b86b50cf841a64252b439e738e97f4a34e2783", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "suggest": { - "ext-intl": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Intl\\Grapheme\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for intl's grapheme_* functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "grapheme", - "intl", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-11-23T21:10:46+00:00" - }, - { - "name": "symfony/polyfill-intl-normalizer", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8", - "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "suggest": { - "ext-intl": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Intl\\Normalizer\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for intl's Normalizer class and related functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "intl", - "normalizer", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-02-19T12:13:01+00:00" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825", - "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "provide": { - "ext-mbstring": "*" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-11-30T18:21:41+00:00" - }, - { - "name": "symfony/polyfill-php70", - "version": "v1.20.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php70.git", - "reference": "5f03a781d984aae42cebd18e7912fa80f02ee644" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/5f03a781d984aae42cebd18e7912fa80f02ee644", - "reference": "5f03a781d984aae42cebd18e7912fa80f02ee644", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "metapackage", - "extra": { - "branch-alias": { - "dev-main": "1.20-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-10-23T14:02:19+00:00" - }, - { - "name": "symfony/polyfill-php72", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "9a142215a36a3888e30d0a9eeea9766764e96976" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/9a142215a36a3888e30d0a9eeea9766764e96976", - "reference": "9a142215a36a3888e30d0a9eeea9766764e96976", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php72\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-05-27T09:17:38+00:00" - }, - { - "name": "symfony/polyfill-php73", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/cc5db0e22b3cb4111010e48785a97f670b350ca5", - "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-06-05T21:20:04+00:00" - }, - { - "name": "symfony/polyfill-php80", - "version": "v1.25.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "4407588e0d3f1f52efb65fbe92babe41f37fe50c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/4407588e0d3f1f52efb65fbe92babe41f37fe50c", - "reference": "4407588e0d3f1f52efb65fbe92babe41f37fe50c", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-03-04T08:16:47+00:00" - }, - { - "name": "symfony/process", - "version": "v5.4.5", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "95440409896f90a5f85db07a32b517ecec17fa4c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/95440409896f90a5f85db07a32b517ecec17fa4c", - "reference": "95440409896f90a5f85db07a32b517ecec17fa4c", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.16" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Executes commands in sub-processes", - "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-01-30T18:16:22+00:00" - }, - { - "name": "symfony/service-contracts", - "version": "v2.5.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/service-contracts.git", - "reference": "1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc", - "reference": "1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "psr/container": "^1.1", - "symfony/deprecation-contracts": "^2.1" - }, - "conflict": { - "ext-psr": "<1.1|>=2" - }, - "suggest": { - "symfony/service-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\Service\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to writing services", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-11-04T16:48:04+00:00" - }, - { - "name": "symfony/stopwatch", - "version": "v5.4.5", - "source": { - "type": "git", - "url": "https://github.com/symfony/stopwatch.git", - "reference": "4d04b5c24f3c9a1a168a131f6cbe297155bc0d30" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/4d04b5c24f3c9a1a168a131f6cbe297155bc0d30", - "reference": "4d04b5c24f3c9a1a168a131f6cbe297155bc0d30", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/service-contracts": "^1|^2|^3" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Stopwatch\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides a way to profile code", - "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-02-18T16:06:09+00:00" - }, - { - "name": "symfony/string", - "version": "v5.4.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/string.git", - "reference": "92043b7d8383e48104e411bc9434b260dbeb5a10" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/92043b7d8383e48104e411bc9434b260dbeb5a10", - "reference": "92043b7d8383e48104e411bc9434b260dbeb5a10", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-intl-grapheme": "~1.0", - "symfony/polyfill-intl-normalizer": "~1.0", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php80": "~1.15" - }, - "conflict": { - "symfony/translation-contracts": ">=3.0" - }, - "require-dev": { - "symfony/error-handler": "^4.4|^5.0|^6.0", - "symfony/http-client": "^4.4|^5.0|^6.0", - "symfony/translation-contracts": "^1.1|^2", - "symfony/var-exporter": "^4.4|^5.0|^6.0" - }, - "type": "library", - "autoload": { - "files": [ - "Resources/functions.php" - ], - "psr-4": { - "Symfony\\Component\\String\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way", - "homepage": "https://symfony.com", - "keywords": [ - "grapheme", - "i18n", - "string", - "unicode", - "utf-8", - "utf8" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-01-02T09:53:40+00:00" + "time": "2024-11-25T00:39:41+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "1.1.0" + "platform": { + "ext-curl": "*" + }, + "platform-dev": { + "ext-fileinfo": "*" + }, + "plugin-api-version": "2.6.0" } From 4bd53e1d41ef50b6490bcbcdfbdc0331a3383103 Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 10:57:48 +0800 Subject: [PATCH 03/14] feat(cs): gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 29cf1b7..2372cdf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /build /dev-environment js/nextcloud-swarm-plugin*.* -/.php_cs.cache +/.php-cs-fixer.cache # Package Manages /node_modules From 48b5eb3a7858040278816c2d3d7822e63499056e Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 10:58:11 +0800 Subject: [PATCH 04/14] feat(cs): add pipeline --- .github/workflows/cs-fixer.yml | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/cs-fixer.yml diff --git a/.github/workflows/cs-fixer.yml b/.github/workflows/cs-fixer.yml new file mode 100644 index 0000000..7021251 --- /dev/null +++ b/.github/workflows/cs-fixer.yml @@ -0,0 +1,45 @@ +name: Code Style Fixer + +on: + pull_request: + branches: + - 'stage' + types: + - opened + - synchronize + - reopened + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.3" + tools: composer + + - name: Install dependencies + run: composer install + + - name: Run code fixer + run: vendor/bin/php-cs-fixer fix + + - name: Check for fix changes + run: | + if [[ -n "$(git status --porcelain)" ]]; then + echo "Fix changes detected"; + git config user.name "${{ github.actor }}"; + git config user.email "${{ github.actor }}@users.noreply.github.com"; + git commit -am "chore: code style fix"; + else + echo "No fix changes detected"; + fi + + - name: Push changes + if: success() + run: git push From 3fe02aad521de1603fadd27a0521b3895b1e93d1 Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 10:58:22 +0800 Subject: [PATCH 05/14] feat(cs): code style --- lib/AppInfo/AppConstants.php | 1 + lib/AppInfo/Application.php | 12 +- lib/Auth/License.php | 9 +- lib/Backend/BeeSwarm.php | 18 +- lib/Controller/BeeController.php | 40 ++-- lib/Controller/SettingsController.php | 35 ++-- lib/Db/SwarmFile.php | 6 +- lib/Db/SwarmFileMapper.php | 61 +++--- lib/Exception/SwarmException.php | 6 +- lib/Migration/Version0001Date202204071430.php | 4 +- lib/Migration/Version0002Date202409251430.php | 4 +- lib/Migration/Version0003Date202401101430.php | 18 +- lib/Migration/Version0004Date202410131430.php | 29 ++- lib/Migration/Version0005Date202411081430.php | 22 +- lib/Notification/Notifier.php | 19 +- lib/Sabre/PostPlugin.php | 40 ++-- lib/Sabre/PropfindPlugin.php | 46 ++--- lib/Service/EthswarmService.php | 3 +- lib/Service/NotificationService.php | 35 ++-- lib/Storage/BeeSwarm.php | 189 +++++++----------- lib/Storage/BeeSwarmTrait.php | 53 ++--- lib/Utils/Curl.php | 42 ++-- lib/Utils/Env.php | 12 +- 23 files changed, 306 insertions(+), 398 deletions(-) diff --git a/lib/AppInfo/AppConstants.php b/lib/AppInfo/AppConstants.php index eb6d268..19a7370 100644 --- a/lib/AppInfo/AppConstants.php +++ b/lib/AppInfo/AppConstants.php @@ -1,4 +1,5 @@ setIdentifier('access:key') ->setScheme(self::SCHEME_ACCESS_KEY) ->setText($l->t('License')) ->addParameters([ (new DefinitionParameter(self::SCHEME_ACCESS_KEY, $l->t('Access Key'))) - ->setTooltip($l->t("License Access Key")) + ->setTooltip($l->t('License Access Key')) ->setType(DefinitionParameter::VALUE_PASSWORD), ]); } diff --git a/lib/Backend/BeeSwarm.php b/lib/Backend/BeeSwarm.php index ee41c2f..fc3eee1 100755 --- a/lib/Backend/BeeSwarm.php +++ b/lib/Backend/BeeSwarm.php @@ -1,4 +1,5 @@ l = $l; $this->appName = $appName; $this->config = $config; @@ -74,20 +73,19 @@ public function __construct(string $appName, IL10N $l, IConfig $config, LoggerIn ->setText($l->t('HejBit-Swarm')) ->addParameters([ (new DefinitionParameter(self::OPTION_HOST_URL, $l->t('Server URL'))) - ->setTooltip($l->t("License Server URL")), + ->setTooltip($l->t('License Server URL')), ])->addAuthScheme(License::SCHEME_ACCESS_KEY); } /** * {@inheritdoc} */ - public function validateStorageDefinition(StorageConfig $storage): bool - { + public function validateStorageDefinition(StorageConfig $storage): bool { $result = true; // access key if (!$storage->getBackendOption(License::SCHEME_ACCESS_KEY)) { - $this->logger->warning("access key not set"); + $this->logger->warning('access key not set'); $result = false; } @@ -97,7 +95,7 @@ public function validateStorageDefinition(StorageConfig $storage): bool $host = 'https://' . $host; } if (!filter_var($host, FILTER_VALIDATE_URL)) { - $this->logger->warning("invalid url"); + $this->logger->warning('invalid url'); $result = false; } diff --git a/lib/Controller/BeeController.php b/lib/Controller/BeeController.php index 2c970db..1a19a73 100755 --- a/lib/Controller/BeeController.php +++ b/lib/Controller/BeeController.php @@ -26,12 +26,12 @@ namespace OCA\Files_External_Ethswarm\Controller; +use OCA\Files_External_Ethswarm\Settings\Admin; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; use OCP\IConfig; use OCP\IRequest; -use OCA\Files_External_Ethswarm\Settings\Admin; -use OCP\AppFramework\Http\DataResponse; -use OCP\AppFramework\Http; class BeeController extends Controller { @@ -65,19 +65,19 @@ public function __construct( * Create a new postage batch stamp * @return \DataResponse */ - public function createPostageBatch(): DataResponse { - if ($this->request->getParam("postageBatch")) { - $postageBatch = json_decode($this->request->getParam("postageBatch"), true); + public function createPostageBatch(): DataResponse { + if ($this->request->getParam('postageBatch')) { + $postageBatch = json_decode($this->request->getParam('postageBatch'), true); - $response_data = $this->admin->buyPostageStamp($postageBatch["amount"],$postageBatch["depth"],$postageBatch["mount_urloptions"]); + $response_data = $this->admin->buyPostageStamp($postageBatch['amount'], $postageBatch['depth'], $postageBatch['mount_urloptions']); - if (isset($response_data["batchID"])) { - return new DataResponse(array('batchID' => $response_data["batchID"]), Http::STATUS_OK); - } else if (isset($response_data["message"])) { - return new DataResponse(array('msg' => $response_data["message"]), $response_data["code"]); + if (isset($response_data['batchID'])) { + return new DataResponse(['batchID' => $response_data['batchID']], Http::STATUS_OK); + } elseif (isset($response_data['message'])) { + return new DataResponse(['msg' => $response_data['message']], $response_data['code']); } } - return new DataResponse(array('msg' => "Error in request"), Http::STATUS_CONFLICT); + return new DataResponse(['msg' => 'Error in request'], Http::STATUS_CONFLICT); } /** @@ -87,16 +87,16 @@ public function createPostageBatch(): DataResponse { * @return \DataResponse */ public function topUpBatch(): DataResponse { - if ($this->request->getParam("postageBatch")) { - $postageBatch = json_decode($this->request->getParam("postageBatch"), true); + if ($this->request->getParam('postageBatch')) { + $postageBatch = json_decode($this->request->getParam('postageBatch'), true); - $response_data = $this->admin->topUpPostageStamp($postageBatch["activeBatchId"],$postageBatch["topUpValue"],$postageBatch["mount_urloptions"]); - if (isset($response_data["batchID"])) { - return new DataResponse(array('batchID' => $response_data["batchID"]), Http::STATUS_OK); - } else if (isset($response_data["message"])) { - return new DataResponse(array('msg' => $response_data["message"]), $response_data["code"]); + $response_data = $this->admin->topUpPostageStamp($postageBatch['activeBatchId'], $postageBatch['topUpValue'], $postageBatch['mount_urloptions']); + if (isset($response_data['batchID'])) { + return new DataResponse(['batchID' => $response_data['batchID']], Http::STATUS_OK); + } elseif (isset($response_data['message'])) { + return new DataResponse(['msg' => $response_data['message']], $response_data['code']); } } - return new DataResponse(array('msg' => "Error in request"), Http::STATUS_CONFLICT); + return new DataResponse(['msg' => 'Error in request'], Http::STATUS_CONFLICT); } } diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 19b2d0f..df5f6f4 100755 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -26,17 +26,11 @@ namespace OCA\Files_External_Ethswarm\Controller; -use OC; -use OCA\Files_External\Service\DBConfigService; -use OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External_Ethswarm\AppInfo\AppConstants; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\DataResponse; use OCP\IConfig; use OCP\IRequest; -class SettingsController extends Controller -{ +class SettingsController extends Controller { /** @var string */ protected $appName; @@ -50,11 +44,10 @@ class SettingsController extends Controller * @param IRequest $request */ public function __construct( - string $appName, - IConfig $config, - IRequest $request - ) - { + string $appName, + IConfig $config, + IRequest $request, + ) { parent::__construct($appName, $request); $this->config = $config; } @@ -62,12 +55,11 @@ public function __construct( /** * Set the storage config settings */ - public function admin(): void - { - if ($this->request->getParam("storageconfig")) { - $this->config->setAppValue($this->appName, "storageconfig", $this->request->getParam("storageconfig")); + public function admin(): void { + if ($this->request->getParam('storageconfig')) { + $this->config->setAppValue($this->appName, 'storageconfig', $this->request->getParam('storageconfig')); } else { - $this->config->setAppValue($this->appName, "storageconfig", ""); + $this->config->setAppValue($this->appName, 'storageconfig', ''); } } @@ -76,12 +68,11 @@ public function admin(): void * @NoAdminRequired * Save the storage config settings */ - public function save(): void - { - if ($this->request->getParam("storageconfig")) { - $this->config->setAppValue($this->appName, "storageconfig", $this->request->getParam("storageconfig")); + public function save(): void { + if ($this->request->getParam('storageconfig')) { + $this->config->setAppValue($this->appName, 'storageconfig', $this->request->getParam('storageconfig')); } else { - $this->config->setAppValue($this->appName, "storageconfig", ""); + $this->config->setAppValue($this->appName, 'storageconfig', ''); } } } diff --git a/lib/Db/SwarmFile.php b/lib/Db/SwarmFile.php index d4770be..2faa43e 100755 --- a/lib/Db/SwarmFile.php +++ b/lib/Db/SwarmFile.php @@ -52,8 +52,7 @@ * @method void setToken(string $token) * @method int getToken() */ -class SwarmFile extends Entity -{ +class SwarmFile extends Entity { /** @var int|null */ protected $fileId; @@ -88,8 +87,7 @@ class SwarmFile extends Entity /** @var string */ protected $token; - public function __construct() - { + public function __construct() { $this->addType('fileId', 'int'); $this->addType('name', 'string'); $this->addType('swarmReference', 'string'); diff --git a/lib/Db/SwarmFileMapper.php b/lib/Db/SwarmFileMapper.php index f2f076c..3135dbb 100755 --- a/lib/Db/SwarmFileMapper.php +++ b/lib/Db/SwarmFileMapper.php @@ -30,18 +30,16 @@ use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\QBMapper; use OCP\DB\Exception; -use OCP\IDBConnection; use OCP\Files\IMimeTypeLoader; +use OCP\IDBConnection; /** * @template-extends QBMapper */ -class SwarmFileMapper extends QBMapper -{ +class SwarmFileMapper extends QBMapper { public const TABLE_NAME = 'files_swarm'; - public function __construct(IDBConnection $db) - { + public function __construct(IDBConnection $db) { parent::__construct($db, self::TABLE_NAME); } @@ -49,8 +47,7 @@ public function __construct(IDBConnection $db) * @return SwarmFile[] * @throws Exception */ - public function findAll(string $fileId): array - { + public function findAll(string $fileId): array { $qb = $this->db->getQueryBuilder(); $select = $qb @@ -70,8 +67,7 @@ public function findAll(string $fileId): array * @throws Exception * @throws MultipleObjectsReturnedException */ - public function find(string $name, int $storage): SwarmFile - { + public function find(string $name, int $storage): SwarmFile { $qb = $this->db->getQueryBuilder(); $select = $qb @@ -89,8 +85,7 @@ public function find(string $name, int $storage): SwarmFile * @return int * @throws Exception */ - public function findExists(string $name, int $storage): int - { + public function findExists(string $name, int $storage): int { $qb = $this->db->getQueryBuilder(); $select = $qb @@ -108,11 +103,10 @@ public function findExists(string $name, int $storage): int * @return SwarmFile * @throws Exception */ - public function createDirectory(string $path, int $storage, string $token): SwarmFile - { + public function createDirectory(string $path, int $storage, string $token): SwarmFile { $swarm = new SwarmFile(); $swarm->setName($path); - $swarm->setMimeType(OC::$server->get(IMimeTypeLoader::class)->getId("httpd/unix-directory")); + $swarm->setMimeType(OC::$server->get(IMimeTypeLoader::class)->getId('httpd/unix-directory')); $swarm->setSize(1); $swarm->setStorageMtime(time()); $swarm->setStorage($storage); @@ -125,17 +119,16 @@ public function createDirectory(string $path, int $storage, string $token): Swar * @return SwarmFile * @throws Exception */ - public function createFile(array $data): SwarmFile - { + public function createFile(array $data): SwarmFile { $swarm = new SwarmFile(); - $swarm->setName($data["name"]); - $swarm->setSwarmReference($data["reference"]); - $swarm->setSwarmTag($data["etag"]); - $swarm->setMimetype($data["mimetype"]); - $swarm->setSize($data["size"]); - $swarm->setStorageMtime($data["storage_mtime"]); - $swarm->setStorage($data["storage"]); - $swarm->setToken($data["token"]); + $swarm->setName($data['name']); + $swarm->setSwarmReference($data['reference']); + $swarm->setSwarmTag($data['etag']); + $swarm->setMimetype($data['mimetype']); + $swarm->setSize($data['size']); + $swarm->setStorageMtime($data['storage_mtime']); + $swarm->setStorage($data['storage']); + $swarm->setToken($data['token']); return $this->insert($swarm); } @@ -147,10 +140,9 @@ public function createFile(array $data): SwarmFile * @return array * @throws Exception|MultipleObjectsReturnedException */ - public function getPathTree(string $path, int $storage, bool $incSelf = true, bool $recursive = true): array - { + public function getPathTree(string $path, int $storage, bool $incSelf = true, bool $recursive = true): array { // Get files from directory tree based on path parameter - $dir = array(); + $dir = []; if ($incSelf) { try { $dir[] = $this->find($path, $storage); @@ -158,8 +150,9 @@ public function getPathTree(string $path, int $storage, bool $incSelf = true, bo } } - if ($path !== '') + if ($path !== '') { $path .= '/'; + } $qb = $this->db->getQueryBuilder(); $select = $qb @@ -167,8 +160,9 @@ public function getPathTree(string $path, int $storage, bool $incSelf = true, bo ->from($this->getTableName()) ->where($qb->expr()->like('name', $qb->createNamedParameter($this->db->escapeLikeParameter($path) . '%'), $qb::PARAM_STR)) ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))); - if (!$recursive) + if (!$recursive) { $select->andWhere($qb->expr()->notLike('name', $qb->createNamedParameter($this->db->escapeLikeParameter($path) . '%/%'), $qb::PARAM_STR)); + } return array_merge($dir, $this->findEntities($select)); } @@ -179,8 +173,7 @@ public function getPathTree(string $path, int $storage, bool $incSelf = true, bo * @return int * @throws Exception */ - public function updatePath(string $path1, string $path2, int $storage): int - { + public function updatePath(string $path1, string $path2, int $storage): int { $qb = $this->db->getQueryBuilder(); $qb ->update($this->getTableName()) @@ -195,8 +188,7 @@ public function updatePath(string $path1, string $path2, int $storage): int * @return SwarmFile[] * @throws Exception */ - public function findAllWithToken(string $token): array - { + public function findAllWithToken(string $token): array { $qb = $this->db->getQueryBuilder(); $select = $qb @@ -214,8 +206,7 @@ public function findAllWithToken(string $token): array * @return void * @throws \OCP\DB\Exception */ - public function updateStorageIds(string $token, int $storageId): void - { + public function updateStorageIds(string $token, int $storageId): void { foreach ($this->findAllWithToken($token) as $swarmFile) { $swarmFile->setStorage($storageId); $this->update($swarmFile); diff --git a/lib/Exception/SwarmException.php b/lib/Exception/SwarmException.php index 7ac1c6a..55b45e9 100644 --- a/lib/Exception/SwarmException.php +++ b/lib/Exception/SwarmException.php @@ -4,10 +4,8 @@ use Exception; -class SwarmException extends Exception -{ - public function __construct($message, $code = 0, Exception $previous = null) - { +class SwarmException extends Exception { + public function __construct($message, $code = 0, ?Exception $previous = null) { parent::__construct($message, $code, $previous); } } diff --git a/lib/Migration/Version0001Date202204071430.php b/lib/Migration/Version0001Date202204071430.php index 1f32d4d..e5f5180 100755 --- a/lib/Migration/Version0001Date202204071430.php +++ b/lib/Migration/Version0001Date202204071430.php @@ -27,12 +27,12 @@ use Closure; use OCP\DB\ISchemaWrapper; +use OCP\DB\Types; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -use OCP\DB\Types; class Version0001Date202204071430 extends SimpleMigrationStep { - public const _TABLENAME = "files_swarm"; + public const _TABLENAME = 'files_swarm'; /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` diff --git a/lib/Migration/Version0002Date202409251430.php b/lib/Migration/Version0002Date202409251430.php index 6ee82fe..4e9fe5b 100644 --- a/lib/Migration/Version0002Date202409251430.php +++ b/lib/Migration/Version0002Date202409251430.php @@ -27,12 +27,12 @@ use Closure; use OCP\DB\ISchemaWrapper; +use OCP\DB\Types; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -use OCP\DB\Types; class Version0002Date202409251430 extends SimpleMigrationStep { - public const _TABLENAME = "files_swarm"; + public const _TABLENAME = 'files_swarm'; /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` diff --git a/lib/Migration/Version0003Date202401101430.php b/lib/Migration/Version0003Date202401101430.php index 9cb9cfa..5991c78 100644 --- a/lib/Migration/Version0003Date202401101430.php +++ b/lib/Migration/Version0003Date202401101430.php @@ -27,13 +27,11 @@ use Closure; use OCP\DB\ISchemaWrapper; -use OCP\Migration\IOutput; -use OCP\Migration\SimpleMigrationStep; -use OCP\DB\Types; -use OCP\Files\IMimeTypeLoader; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Files\IMimeTypeLoader; use OCP\IDBConnection; - +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; class Version0003Date202401101430 extends SimpleMigrationStep { @@ -77,12 +75,12 @@ private function getCurrentPluginVersion() { $qb = $this->db->getQueryBuilder(); $result = $qb->select('configvalue') - ->from('appconfig') - ->where($qb->expr()->eq('appid', $qb->createNamedParameter('files_external_ethswarm'))) - ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('installed_version'))) - ->executeQuery(); + ->from('appconfig') + ->where($qb->expr()->eq('appid', $qb->createNamedParameter('files_external_ethswarm'))) + ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('installed_version'))) + ->executeQuery(); $version = $result->fetchOne(); - return $version; + return $version; } } diff --git a/lib/Migration/Version0004Date202410131430.php b/lib/Migration/Version0004Date202410131430.php index b36f177..0b7a04f 100644 --- a/lib/Migration/Version0004Date202410131430.php +++ b/lib/Migration/Version0004Date202410131430.php @@ -27,11 +27,9 @@ use Closure; use OCP\DB\ISchemaWrapper; +use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -use OCP\DB\Types; -use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IDBConnection; class Version0004Date202410131430 extends SimpleMigrationStep { private $db; @@ -56,9 +54,9 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $resultNI = $qb->select('numeric_id') - ->from('storages') - ->where($qb->expr()->like('id', $qb->createNamedParameter('ethswarm::https:%'))) - ->executeQuery(); + ->from('storages') + ->where($qb->expr()->like('id', $qb->createNamedParameter('ethswarm::https:%'))) + ->executeQuery(); // This migration step only runs if there is a license that contains the api_url (previous verion of plugin) while ($row = $resultNI->fetch()) { @@ -67,24 +65,25 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array // This is assuming we only have one folder with Hejbit Plug (also true on the previous version of the plugin) $qb = $this->db->getQueryBuilder(); $result = $qb->select('mount_id') - ->from('external_mounts') - ->where($qb->expr()->eq('storage_backend', $qb->createNamedParameter('files_external_ethswarm'))) - ->executeQuery(); + ->from('external_mounts') + ->where($qb->expr()->eq('storage_backend', $qb->createNamedParameter('files_external_ethswarm'))) + ->executeQuery(); $mountid = $result->fetchOne(); $qb = $this->db->getQueryBuilder(); $result = $qb->select('value') - ->from('external_config','m') - ->where($qb->expr()->eq('m.mount_id', $qb->createNamedParameter($mountid))) - ->andWhere($qb->expr()->eq('m.key', $qb->createNamedParameter('access_key'))) - ->executeQuery(); + ->from('external_config', 'm') + ->where($qb->expr()->eq('m.mount_id', $qb->createNamedParameter($mountid))) + ->andWhere($qb->expr()->eq('m.key', $qb->createNamedParameter('access_key'))) + ->executeQuery(); $key = $result->fetchOne(); $updateQb = $this->db->getQueryBuilder(); $result = $updateQb->update('storages') - ->set('id', $updateQb->createNamedParameter('ethswarm::'.$key)) + ->set('id', $updateQb->createNamedParameter('ethswarm::' . $key)) ->where($updateQb->expr()->eq('numeric_id', $updateQb->createNamedParameter($numeric_id))) ->executeStatement(); } - }} + } +} diff --git a/lib/Migration/Version0005Date202411081430.php b/lib/Migration/Version0005Date202411081430.php index 0ee9353..c7d70e4 100644 --- a/lib/Migration/Version0005Date202411081430.php +++ b/lib/Migration/Version0005Date202411081430.php @@ -27,15 +27,14 @@ use Closure; use OCP\DB\ISchemaWrapper; -use OCP\Migration\IOutput; -use OCP\Migration\SimpleMigrationStep; use OCP\DB\Types; -use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; class Version0005Date202411081430 extends SimpleMigrationStep { private $db; - public const _TABLENAME = "files_swarm"; + public const _TABLENAME = 'files_swarm'; public function __construct(IDBConnection $db) { @@ -71,9 +70,9 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array // Get all the numeric_id's of the swarm storages $resultNI = $gqbNI->select('numeric_id', 'id') - ->from('storages') - ->where($gqbNI->expr()->like('id', $gqbNI->createNamedParameter('ethswarm::%'))) - ->executeQuery(); + ->from('storages') + ->where($gqbNI->expr()->like('id', $gqbNI->createNamedParameter('ethswarm::%'))) + ->executeQuery(); while ($row = $resultNI->fetch()) { // Get all the files on each swarm storage @@ -83,9 +82,10 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $updateQb = $this->db->getQueryBuilder(); $result = $updateQb->update(self::_TABLENAME) - ->set('token', $updateQb->createNamedParameter($token_id)) - ->where($updateQb->expr()->eq('storage', $updateQb->createNamedParameter($numeric_id))) - ->executeStatement(); + ->set('token', $updateQb->createNamedParameter($token_id)) + ->where($updateQb->expr()->eq('storage', $updateQb->createNamedParameter($numeric_id))) + ->executeStatement(); } - }} + } +} diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index a86472f..47eaff6 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -1,4 +1,5 @@ factory = $factory; $this->url = $urlGenerator; } @@ -73,14 +74,14 @@ public function prepare(\OCP\Notification\INotification $notification, string $l // for a list of defined objects and their parameters. $parameters = $notification->getSubjectParameters(); $notification->setRichSubject($l->t('Your file \'{filename}\' was decentralized.'), - [ - 'filename' => [ - 'type' => 'file', - 'id' => '', - 'name' => basename($parameters['path']), - 'path' => $parameters['path'], - ], - ]); + [ + 'filename' => [ + 'type' => 'file', + 'id' => '', + 'name' => basename($parameters['path']), + 'path' => $parameters['path'], + ], + ]); // Set the plain text subject automatically $this->setParsedSubjectFromRichSubject($notification); diff --git a/lib/Sabre/PostPlugin.php b/lib/Sabre/PostPlugin.php index 5a4b9c3..fbb53ce 100644 --- a/lib/Sabre/PostPlugin.php +++ b/lib/Sabre/PostPlugin.php @@ -1,35 +1,32 @@ EthswarmService = $service; } - public function initialize(Server $server) - { + public function initialize(Server $server) { $this->server = $server; $this->server->on('method:POST', [$this, 'httpPost']); } - public function httpPost(RequestInterface $request, ResponseInterface $response) - { + public function httpPost(RequestInterface $request, ResponseInterface $response) { $action = $request->getRawServerValue('HTTP_HEJBIT_ACTION') ?? null; if ($action === 'hide') { @@ -52,9 +49,8 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $response->setHeader('Content-Length', '0'); return false; - } - else if ($action === 'unhide') { - $path = $request->getPath(); + } elseif ($action === 'unhide') { + $path = $request->getPath(); $node = $this->server->tree->getNodeForPath($path); if (($node instanceof \OCA\DAV\Connector\Sabre\File)) { $storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId(); @@ -71,15 +67,15 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $response->setHeader('Content-Length', '0'); return false; - } - // No Hejbit-action, allow other plugins to handle the request - else if ($action === null) { - return true; - } - // Invalid Hejbit-action, throw exception - else { - $exMessage = 'There was no plugin in the system that was willing to handle a POST method with this action > '.$action.'.'; - throw new \Sabre\DAV\Exception\NotImplemented($exMessage); - } + } + // No Hejbit-action, allow other plugins to handle the request + elseif ($action === null) { + return true; + } + // Invalid Hejbit-action, throw exception + else { + $exMessage = 'There was no plugin in the system that was willing to handle a POST method with this action > ' . $action . '.'; + throw new \Sabre\DAV\Exception\NotImplemented($exMessage); + } } } diff --git a/lib/Sabre/PropfindPlugin.php b/lib/Sabre/PropfindPlugin.php index 5794984..09b6159 100755 --- a/lib/Sabre/PropfindPlugin.php +++ b/lib/Sabre/PropfindPlugin.php @@ -1,4 +1,5 @@ getFileInfo()->getinternalPath(); $mountpoint = $node->getFileInfo()->getMountPoint()->getStorageId(); - if (!str_starts_with($mountpoint, "ethswarm")) { - return ""; + if (!str_starts_with($mountpoint, 'ethswarm')) { + return ''; } $class = $this->EthswarmService; - $propFind->handle(self::ETHSWARM_FILEREF, function () use ($class, $storageid, $filename) - { + $propFind->handle(self::ETHSWARM_FILEREF, function () use ($class, $storageid, $filename) { return $class->getSwarmRef($filename, $storageid); }); - if($class->getVisiblity($filename, $storageid)==1){ - $propFind->set("{http://nextcloud.org/ns}hidden","false",200); - } - else{ - $propFind->set("{http://nextcloud.org/ns}hidden","true",200); + if ($class->getVisiblity($filename, $storageid) == 1) { + $propFind->set('{http://nextcloud.org/ns}hidden', 'false', 200); + } else { + $propFind->set('{http://nextcloud.org/ns}hidden', 'true', 200); } - $propFind->handle(self::ETHSWARM_NODE, function () use ($class, $storageid, $filename) - { - return "true"; + $propFind->handle(self::ETHSWARM_NODE, function () use ($class, $storageid, $filename) { + return 'true'; }); } @@ -84,24 +82,22 @@ public function propFind(PropFind $propFind, INode $node) { $filename = $node->getFileInfo()->getinternalPath(); $mountpoint = $node->getFileInfo()->getMountPoint()->getStorageId(); - if (!str_starts_with($mountpoint, "ethswarm")) { - return ""; + if (!str_starts_with($mountpoint, 'ethswarm')) { + return ''; } $class = $this->EthswarmService; - $propFind->handle(self::ETHSWARM_NODE, function () use ($class, $storageid, $filename) - { - return "true"; + $propFind->handle(self::ETHSWARM_NODE, function () use ($class, $storageid, $filename) { + return 'true'; }); - if ($filename === "") { - return ""; + if ($filename === '') { + return ''; } - if($class->getVisiblity($filename, $storageid)==1){ - $propFind->set("{http://nextcloud.org/ns}hidden","false",200); - } - else{ - $propFind->set("{http://nextcloud.org/ns}hidden","true",200); + if ($class->getVisiblity($filename, $storageid) == 1) { + $propFind->set('{http://nextcloud.org/ns}hidden', 'false', 200); + } else { + $propFind->set('{http://nextcloud.org/ns}hidden', 'true', 200); } diff --git a/lib/Service/EthswarmService.php b/lib/Service/EthswarmService.php index 585b22d..28ab974 100755 --- a/lib/Service/EthswarmService.php +++ b/lib/Service/EthswarmService.php @@ -1,4 +1,5 @@ notificationManager = $notificationManager; - $this->userManager = $userManager; + public function __construct(IManager $notificationManager, IUserManager $userManager, IUserSession $userSession) { + $this->notificationManager = $notificationManager; + $this->userManager = $userManager; $this->userSession = $userSession; - } + } - public function sendTemporaryNotification($subject, $path) { - // Create a notification - $notification = $this->notificationManager->createNotification(); - $notification->setApp(AppConstants::APP_NAME); + public function sendTemporaryNotification($subject, $path) { + // Create a notification + $notification = $this->notificationManager->createNotification(); + $notification->setApp(AppConstants::APP_NAME); $userId = $this->userSession->getUser()->getUID(); - $notification->setUser($userId); - $notification->setSubject($subject, ['path' => $path]); - $notification->setObject('temporary', $userId); // Marks the notification as temporary + $notification->setUser($userId); + $notification->setSubject($subject, ['path' => $path]); + $notification->setObject('temporary', $userId); // Marks the notification as temporary $notification->setDateTime(new \DateTime()); - // Send the notification - $this->notificationManager->notify($notification); - } + // Send the notification + $this->notificationManager->notify($notification); + } } diff --git a/lib/Storage/BeeSwarm.php b/lib/Storage/BeeSwarm.php index 880c473..a5455cf 100755 --- a/lib/Storage/BeeSwarm.php +++ b/lib/Storage/BeeSwarm.php @@ -1,4 +1,5 @@ getMountId(); $this->config = OC::$server->get(IConfig::class); - $configSettings = $this->config->getAppValue(AppConstants::APP_NAME, "storageconfig", ""); //default + $configSettings = $this->config->getAppValue(AppConstants::APP_NAME, 'storageconfig', ''); //default $mounts = json_decode($configSettings, true); if (is_array($mounts)) { $mountIds = array_column($mounts, 'mount_id'); $key = array_search($mountId, $mountIds); if (!empty($key) || $key === 0) { - $this->isEncrypted = $mounts[$key]['encrypt'] === "1"; + $this->isEncrypted = $mounts[$key]['encrypt'] === '1'; } } } @@ -158,8 +156,7 @@ public function __construct($params) /** * @inheritDoc */ - public function getId(): string - { + public function getId(): string { return $this->id; } @@ -167,8 +164,7 @@ public function getId(): string * @inheritDoc * @throws Exception */ - public function test(): bool - { + public function test(): bool { if (!$this->checkConnection()) { return false; } @@ -183,8 +179,7 @@ public function test(): bool * @inheritDoc * @throws Exception */ - public function copy($source, $target): bool - { + public function copy($source, $target): bool { try { // Get the source file from the mapper $sourceFile = $this->fileMapper->find($source, $this->storageId); @@ -198,14 +193,14 @@ public function copy($source, $target): bool // Prepare the data for the new file $copyData = []; - $copyData["name"] = $target; - $copyData["reference"] = $sourceFile->getSwarmReference(); - $copyData["etag"] = null; - $copyData["mimetype"] = $sourceFile->getMimetype(); - $copyData["size"] = $sourceFile->getSize(); - $copyData["storage_mtime"] = time(); - $copyData["storage"] = $this->storageId; - $copyData["token"] = $this->token; + $copyData['name'] = $target; + $copyData['reference'] = $sourceFile->getSwarmReference(); + $copyData['etag'] = null; + $copyData['mimetype'] = $sourceFile->getMimetype(); + $copyData['size'] = $sourceFile->getSize(); + $copyData['storage_mtime'] = time(); + $copyData['storage'] = $this->storageId; + $copyData['token'] = $this->token; // Create the new file entry in the mapper $newFile = $this->fileMapper->createFile($copyData); @@ -227,8 +222,7 @@ public function copy($source, $target): bool /** * @return void */ - public function add_root_folder_cache(): void - { + public function add_root_folder_cache(): void { $fileData = [ 'storage' => $this->storageId, 'path' => '', @@ -250,8 +244,7 @@ public function add_root_folder_cache(): void * @param SwarmFile $file * @return bool */ - public function add_file_cache(SwarmFile $file): bool - { + public function add_file_cache(SwarmFile $file): bool { $fileData = [ 'storage' => $file->getStorage(), 'path' => $file->getName(), @@ -265,10 +258,11 @@ public function add_file_cache(SwarmFile $file): bool 'mtime' => $file->getStorageMtime(), ]; - if ($file->getMimetype() == $this->mimeTypeHandler->getId('httpd/unix-directory')) + if ($file->getMimetype() == $this->mimeTypeHandler->getId('httpd/unix-directory')) { $fileData['permissions'] = (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE); - else + } else { $fileData['permissions'] = (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE - Constants::PERMISSION_UPDATE); + } $this->cacheHandler->put($fileData['path'], $fileData); return true; @@ -277,8 +271,7 @@ public function add_file_cache(SwarmFile $file): bool /** * @throws Exception */ - public function add_token_files_cache(): void - { + public function add_token_files_cache(): void { foreach ($this->fileMapper->findAllWithToken($this->token) as $file) { $this->add_file_cache($file); } @@ -289,8 +282,7 @@ public function add_token_files_cache(): void * @inheritDoc * @throws Exception */ - public function file_exists($path): bool - { + public function file_exists($path): bool { if ($path === '' || $path === '/' || $path === '.') { // Return true always the creation of the root folder return true; @@ -305,8 +297,7 @@ public function file_exists($path): bool /** * @inheritDoc */ - public function filemtime($path): int - { + public function filemtime($path): int { return 0; } @@ -314,8 +305,7 @@ public function filemtime($path): int * @inheritDoc * @throws Exception */ - public function stat($path): bool|array - { + public function stat($path): bool|array { $data = $this->getMetaData($path); if ($data['mimetype'] === 'httpd/unix-directory') { return false; @@ -329,16 +319,14 @@ public function stat($path): bool|array /** * @inheritDoc */ - public function getETag($path): ?string - { + public function getETag($path): ?string { return null; } /** * @inheritDoc */ - public function needsPartFile(): bool - { + public function needsPartFile(): bool { return false; } @@ -346,8 +334,7 @@ public function needsPartFile(): bool * @inheritDoc * @throws Exception */ - public function mkdir($path): bool - { + public function mkdir($path): bool { $this->fileMapper->createDirectory($path, $this->storageId, $this->token); return true; } @@ -355,8 +342,7 @@ public function mkdir($path): bool /** * @inheritDoc */ - public function rmdir($path): void - { + public function rmdir($path): void { // TODO: Implement rmdir() method. } @@ -364,8 +350,7 @@ public function rmdir($path): void * @inheritDoc * @throws Exception */ - public function rename($source, $target): bool - { + public function rename($source, $target): bool { $rows = $this->fileMapper->getPathTree($source, $this->storageId); foreach ($rows as $row) { $oldPath = $row->getName(); @@ -378,8 +363,7 @@ public function rename($source, $target): bool /** * @inheritDoc */ - public function opendir($path): bool - { + public function opendir($path): bool { return true; } @@ -387,8 +371,7 @@ public function opendir($path): bool * * @inheritDoc * @throws Exception */ - public function is_dir($path): bool - { + public function is_dir($path): bool { return $this->getMetaData($path)['mimetype'] === 'httpd/unix-directory'; } @@ -396,8 +379,7 @@ public function is_dir($path): bool * @inheritDoc * @throws Exception */ - public function is_file($path): bool - { + public function is_file($path): bool { return $this->getMetaData($path)['mimetype'] !== 'httpd/unix-directory'; } @@ -405,40 +387,35 @@ public function is_file($path): bool * @inheritDoc * @throws Exception */ - public function filetype($path): string - { + public function filetype($path): string { return $this->is_file($path) ? 'file' : 'dir'; } /** * @inheritDoc */ - public function getPermissions($path = null): int - { + public function getPermissions($path = null): int { return (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE - Constants::PERMISSION_UPDATE); } /** * @inheritDoc */ - public function free_space($path): float|false|int - { + public function free_space($path): float|false|int { return FileInfo::SPACE_UNLIMITED; } /** * @inheritDoc */ - public function hasUpdated($path, $time): bool - { + public function hasUpdated($path, $time): bool { return true; } /** * @inheritDoc */ - public function isLocal(): bool - { + public function isLocal(): bool { // the common implementation returns a temporary file by // default, which is not local return false; @@ -447,48 +424,42 @@ public function isLocal(): bool /** * @inheritDoc */ - public function setMountOptions(array $options): void - { + public function setMountOptions(array $options): void { // TODO: Implement setMountOptions() method. } /** * @inheritDoc */ - public function getMountOption($name, $default = null): ?string - { + public function getMountOption($name, $default = null): ?string { return $this->mountOptions[$name] ?? $default; } /** * @inheritDoc */ - public function verifyPath($path, $fileName) - { + public function verifyPath($path, $fileName) { } /** * @inheritDoc */ - public function isCreatable($path): bool - { + public function isCreatable($path): bool { return true; } /** * @inheritDoc */ - public function isUpdatable($path): bool - { + public function isUpdatable($path): bool { return true; } /** * @inheritDoc */ - public function unlink($path): bool - { + public function unlink($path): bool { return true; } @@ -496,8 +467,7 @@ public function unlink($path): bool * @inheritDoc * @throws Exception */ - public function fopen($path, $mode) - { + public function fopen($path, $mode) { if ($path === '' || $path === '/' || $path === '.') { return false; } @@ -528,8 +498,7 @@ public function fopen($path, $mode) /** * @inheritDoc */ - public function touch($path, $mtime = null): bool - { + public function touch($path, $mtime = null): bool { return true; } @@ -537,8 +506,7 @@ public function touch($path, $mtime = null): bool * @inheritDoc * @throws Exception */ - public function file_get_contents($path): string|false - { + public function file_get_contents($path): string|false { $swarmFile = $this->fileMapper->find($path, $this->storageId); $reference = $swarmFile->getSwarmReference(); return stream_get_contents($this->downloadSwarm($reference)); @@ -547,8 +515,7 @@ public function file_get_contents($path): string|false /** * @inheritDoc */ - public function file_put_contents($path, $data): int|float|false - { + public function file_put_contents($path, $data): int|float|false { // TODO: Implement file_put_contents() method. return parent::file_put_contents($path, $data); } @@ -556,8 +523,7 @@ public function file_put_contents($path, $data): int|float|false /** * @inheritDoc */ - public function getDirectDownload($path): array|bool - { + public function getDirectDownload($path): array|bool { // TODO: Implement getDirectDownload() method. return parent::getDirectDownload($path); } @@ -573,8 +539,7 @@ public function getCache($path = '', $storage = null) * @inheritDoc * @throws Exception */ - public function getMetaData($path): ?array - { + public function getMetaData($path): ?array { $data = []; // If not in swarm table, assume it's a folder $exists = $this->fileMapper->findExists($path, $this->storageId) !== 0; @@ -600,10 +565,11 @@ public function getMetaData($path): ?array $swarmFile = $this->fileMapper->find($path, $this->storageId); // Set mimetype as a string, get by using its ID (int) $mimeTypeId = $swarmFile->getMimetype(); - if ($mimeTypeId == $this->mimeTypeHandler->getId('httpd/unix-directory')) + if ($mimeTypeId == $this->mimeTypeHandler->getId('httpd/unix-directory')) { $data['permissions'] = (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE); - else + } else { $data['permissions'] = (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE - Constants::PERMISSION_UPDATE); + } $data['name'] = basename($path); //TODO: Test $data['mimetype'] = $this->mimeTypeHandler->getMimetypeById($mimeTypeId); $data['mtime'] = time(); @@ -619,10 +585,9 @@ public function getMetaData($path): ?array * @inheritDoc * @throws Exception */ - public function getDirectoryContent($directory): Traversable - { + public function getDirectoryContent($directory): Traversable { $rows = $this->fileMapper->getPathTree($directory, $this->storageId, false, false); - $content = array_map(fn($val) => $this->getMetaData($val->getName()), $rows); + $content = array_map(fn ($val) => $this->getMetaData($val->getName()), $rows); return new ArrayIterator($content); } @@ -631,8 +596,7 @@ public function getDirectoryContent($directory): Traversable * @param resource $stream * @return string */ - protected function createTempFile($stream): string - { + protected function createTempFile($stream): string { $extension = ''; $tmpFile = $this->tempManager->getTemporaryFile($extension); $target = fopen($tmpFile, 'w'); @@ -645,12 +609,11 @@ protected function createTempFile($stream): string * @inheritDoc * @throws Exception */ - public function writeStream(string $path, $stream, int $size = null): int - { + public function writeStream(string $path, $stream, ?int $size = null): int { // save stream to temp file $tmpFile = $this->createTempFile($stream); $tmpFileSize = (file_exists($tmpFile) ? filesize($tmpFile) : -1); - $mimetype = str_ends_with(strtolower($path), '.md') ? "text/markdown" : mime_content_type($tmpFile); + $mimetype = str_ends_with(strtolower($path), '.md') ? 'text/markdown' : mime_content_type($tmpFile); try { $reference = $this->uploadSwarm($path, $tmpFile, $mimetype); @@ -662,20 +625,20 @@ public function writeStream(string $path, $stream, int $size = null): int // save to swarm table $uploadFiles = [ - "name" => $path, - "permissions" => (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE - Constants::PERMISSION_UPDATE), - "mimetype" => $this->mimeTypeHandler->getId($mimetype), - "mtime" => time(), - "storage_mtime" => time(), - "size" => $tmpFileSize, - "etag" => null, - "reference" => $reference, - "storage" => $this->storageId, - "token" => $this->token, + 'name' => $path, + 'permissions' => (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE - Constants::PERMISSION_UPDATE), + 'mimetype' => $this->mimeTypeHandler->getId($mimetype), + 'mtime' => time(), + 'storage_mtime' => time(), + 'size' => $tmpFileSize, + 'etag' => null, + 'reference' => $reference, + 'storage' => $this->storageId, + 'token' => $this->token, ]; $this->fileMapper->createFile($uploadFiles); - $this->notificationService->sendTemporaryNotification("swarm-fileupload", $path); + $this->notificationService->sendTemporaryNotification('swarm-fileupload', $path); // TODO: Read back from swarm to return filesize? return $tmpFileSize; diff --git a/lib/Storage/BeeSwarmTrait.php b/lib/Storage/BeeSwarmTrait.php index 428a799..1889366 100755 --- a/lib/Storage/BeeSwarmTrait.php +++ b/lib/Storage/BeeSwarmTrait.php @@ -1,4 +1,5 @@ validateParams($params); $this->api_url = $params[BeeSwarm::OPTION_HOST_URL]; @@ -60,8 +59,7 @@ protected function parseParams($params): void * @return void * @throws StorageBadConfigException */ - private function validateParams(array &$params): void - { + private function validateParams(array &$params): void { if (!$params[BeeSwarm::OPTION_HOST_URL] || !$params[License::SCHEME_ACCESS_KEY]) { throw new StorageBadConfigException('Creating ' . self::class . ' storage failed, required parameters not set'); } @@ -78,14 +76,14 @@ private function validateParams(array &$params): void * @throws CurlException * @throws SwarmException */ - private function getUploadLink(): string - { + private function getUploadLink(): string { $endpoint = $this->api_url . '/api/upload'; $curl = new Curl($endpoint, authorization: $this->access_key); $response = $curl->exec(true); - if (!$curl->isResponseSuccessful()) + if (!$curl->isResponseSuccessful()) { throw new SwarmException('Failed to connect to HejBit: ' . $response['message']); + } return $response['url']; } @@ -96,14 +94,14 @@ private function getUploadLink(): string * @throws CurlException * @throws SwarmException */ - private function getDownloadLink(string $reference): string - { + private function getDownloadLink(string $reference): string { $endpoint = $this->api_url . '/api/download'; $curl = new Curl($endpoint, authorization: $this->access_key); $response = $curl->exec(true); - if (!$curl->isResponseSuccessful()) + if (!$curl->isResponseSuccessful()) { throw new SwarmException('Failed to connect to HejBit: ' . $response['message']); + } return $response['url'] . DIRECTORY_SEPARATOR . $reference; } @@ -115,14 +113,13 @@ private function getDownloadLink(string $reference): string * @return string * @throws SwarmException|CurlException */ - private function uploadSwarm(string $path, string $tempFile, string $mimetype): string - { + private function uploadSwarm(string $path, string $tempFile, string $mimetype): string { if ($this->isVersion(self::INFRASTRUCTURE_VERSION_GATEWAY)) { return $this->uploadSwarmV1($path, $tempFile, $mimetype); } $curl = new Curl($this->getUploadLink(), [ - CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => [ 'file' => new CURLFile($tempFile, $mimetype, basename($path)), ], @@ -141,8 +138,7 @@ private function uploadSwarm(string $path, string $tempFile, string $mimetype): * @return resource * @throws SwarmException|CurlException */ - private function downloadSwarm(string $reference) - { + private function downloadSwarm(string $reference) { if ($this->isVersion(self::INFRASTRUCTURE_VERSION_GATEWAY)) { return $this->downloadSwarmV1($reference); } @@ -166,8 +162,7 @@ private function downloadSwarm(string $reference) * @return bool * @throws SwarmException|CurlException */ - private function checkConnection(): bool - { + private function checkConnection(): bool { if ($this->isVersion(self::INFRASTRUCTURE_VERSION_GATEWAY)) { return $this->checkConnectionV1(); } @@ -187,8 +182,7 @@ private function checkConnection(): bool * @param int $version * @return bool */ - public function isVersion(int $version = self::INFRASTRUCTURE_VERSION_GATEWAY): bool - { + public function isVersion(int $version = self::INFRASTRUCTURE_VERSION_GATEWAY): bool { return match ($version) { self::INFRASTRUCTURE_VERSION_GATEWAY => $this->api_url === 'https://license.hejbit.com', self::INFRASTRUCTURE_VERSION_HEJBIT => $this->api_url !== 'https://license.hejbit.com', @@ -200,8 +194,7 @@ public function isVersion(int $version = self::INFRASTRUCTURE_VERSION_GATEWAY): * @return bool * @throws CurlException */ - private function checkConnectionV1(): bool - { + private function checkConnectionV1(): bool { $endpoint = $this->api_url . DIRECTORY_SEPARATOR . 'readiness'; $curl = new Curl($endpoint); @@ -218,8 +211,7 @@ private function checkConnectionV1(): bool * @return resource * @throws CurlException|SwarmException */ - private function downloadSwarmV1(string $reference) - { + private function downloadSwarmV1(string $reference) { $endpoint = $this->api_url . DIRECTORY_SEPARATOR . 'bzz' . DIRECTORY_SEPARATOR . $reference . DIRECTORY_SEPARATOR; $curl = new Curl($endpoint, [ @@ -251,14 +243,13 @@ private function downloadSwarmV1(string $reference) * @return array|string * @throws CurlException|SwarmException */ - private function uploadSwarmV1(string $path, string $tempFile, string $mimetype): array|string - { + private function uploadSwarmV1(string $path, string $tempFile, string $mimetype): array|string { $endpoint = $this->api_url . DIRECTORY_SEPARATOR . 'bzz'; - $params = "?name=" . urlencode(basename($path)); + $params = '?name=' . urlencode(basename($path)); $curl = new Curl($endpoint . $params, [ CURLOPT_PUT => true, - CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POST => true, CURLOPT_INFILE => fopen($tempFile, 'r'), CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, @@ -271,10 +262,10 @@ private function uploadSwarmV1(string $path, string $tempFile, string $mimetype) $curl->setAuthorization($this->access_key, CURLAUTH_ANY); $result = $curl->exec(true); - $reference = (isset($result["reference"]) ? $result['reference'] : null); + $reference = (isset($result['reference']) ? $result['reference'] : null); if (!isset($reference)) { - throw new SwarmException("Failed to upload file to " . $this->id . ": " . $result['message']); + throw new SwarmException('Failed to upload file to ' . $this->id . ': ' . $result['message']); } return $reference; } diff --git a/lib/Utils/Curl.php b/lib/Utils/Curl.php index b754426..246ea95 100644 --- a/lib/Utils/Curl.php +++ b/lib/Utils/Curl.php @@ -5,8 +5,7 @@ use CurlHandle; use Safe\Exceptions\CurlException; -class Curl -{ +class Curl { private const DEFAULT_OPTIONS = [ CURLOPT_MAXREDIRS => 10, CURLOPT_FOLLOWLOCATION => true, @@ -28,8 +27,7 @@ class Curl * @param array $headers * @param string|null $authorization */ - public function __construct(string $url, array $options = [], array $headers = [], ?string $authorization = null) - { + public function __construct(string $url, array $options = [], array $headers = [], ?string $authorization = null) { $this->url = $url; $this->options = $options + self::getDefaultOptions(); $this->headers = $headers; @@ -41,16 +39,14 @@ public function __construct(string $url, array $options = [], array $headers = [ /** * @return array */ - private static function getDefaultOptions(): array - { + private static function getDefaultOptions(): array { return self::checkSSLOption() + self::DEFAULT_OPTIONS; } /** * @return bool[] */ - private static function checkSSLOption(): array - { + private static function checkSSLOption(): array { return [ CURLOPT_SSL_VERIFYHOST => !Env::isDevelopment(), CURLOPT_SSL_VERIFYPEER => !Env::isDevelopment(), @@ -61,8 +57,7 @@ private static function checkSSLOption(): array * initializes a curl handler * @return void */ - private function init(): void - { + private function init(): void { $this->handler = curl_init(); curl_setopt($this->handler, CURLOPT_URL, $this->url); } @@ -73,8 +68,7 @@ private function init(): void * @param array $options * @return void */ - private function setOptions(array $options = []): void - { + private function setOptions(array $options = []): void { $options = self::getDefaultOptions() + $this->options + $options; curl_setopt_array($this->handler, $options); } @@ -83,8 +77,7 @@ private function setOptions(array $options = []): void * @param array $headers * @return void */ - private function setHeaders(array $headers = []): void - { + private function setHeaders(array $headers = []): void { $headers = $this->headers + $headers; if ($this->authorization) { $headers[] = match ($this->authorizationType) { @@ -102,13 +95,13 @@ private function setHeaders(array $headers = []): void * @param int $authorizationType * @return void */ - public function setAuthorization(?string $authorization, int $authorizationType = CURLAUTH_BEARER): void - { + public function setAuthorization(?string $authorization, int $authorizationType = CURLAUTH_BEARER): void { $this->authorization = $authorization; if (!$authorization) { $this->authorizationType = CURLAUTH_NONE; - } else + } else { $this->authorizationType = $authorizationType; + } } /** @@ -118,8 +111,7 @@ public function setAuthorization(?string $authorization, int $authorizationType * @return string|array * @throws CurlException */ - public function exec(bool $array = false): string|array - { + public function exec(bool $array = false): string|array { $this->setOptions(); $this->setHeaders(); $response = curl_exec($this->handler); @@ -133,8 +125,7 @@ public function exec(bool $array = false): string|array * @param int|null $option * @return mixed */ - public function getInfo(?int $option = null): mixed - { + public function getInfo(?int $option = null): mixed { return curl_getinfo($this->handler, $option); } @@ -144,8 +135,7 @@ public function getInfo(?int $option = null): mixed * @return void * @throws CurlException */ - private function checkResponse(): void - { + private function checkResponse(): void { if (curl_errno($this->handler) !== 0) { curl_close($this->handler); throw new CurlException(curl_error($this->handler)); @@ -156,10 +146,10 @@ private function checkResponse(): void * @return bool * @throws CurlException */ - public function isResponseSuccessful(): bool - { - if ($this->getInfo(CURLINFO_HTTP_CODE) === 0) + public function isResponseSuccessful(): bool { + if ($this->getInfo(CURLINFO_HTTP_CODE) === 0) { throw new CurlException('Curl handler has not been executed'); + } return $this->getInfo(CURLINFO_HTTP_CODE) === 200 || $this->getInfo(CURLINFO_HTTP_CODE) === 201; } diff --git a/lib/Utils/Env.php b/lib/Utils/Env.php index 11f12b5..95b6945 100644 --- a/lib/Utils/Env.php +++ b/lib/Utils/Env.php @@ -2,14 +2,12 @@ namespace OCA\Files_External_Ethswarm\Utils; -class Env -{ +class Env { /** * @param string $name * @return string */ - public static function get(string $name): string - { + public static function get(string $name): string { return getenv($name); } @@ -18,16 +16,14 @@ public static function get(string $name): string * @param string $value * @return bool */ - public static function set(string $name, string $value): bool - { + public static function set(string $name, string $value): bool { return putenv($name . '=' . $value); } /** * @return bool */ - public static function isDevelopment(): bool - { + public static function isDevelopment(): bool { return self::get('ENV') === 'development'; } } From 86a2c7ec6b4118e3d67e5d5762b9b5dc4a8f0f10 Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 11:33:10 +0800 Subject: [PATCH 06/14] perf(cs): update pipeline - refactor: changed name to Lint - add: auto commit action - add: fast fail - update: install only cs-fixer dep --- .github/workflows/cs-fixer.yml | 45 ---------------------------------- .github/workflows/lint.yml | 36 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 45 deletions(-) delete mode 100644 .github/workflows/cs-fixer.yml create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/cs-fixer.yml b/.github/workflows/cs-fixer.yml deleted file mode 100644 index 7021251..0000000 --- a/.github/workflows/cs-fixer.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Code Style Fixer - -on: - pull_request: - branches: - - 'stage' - types: - - opened - - synchronize - - reopened - -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "8.3" - tools: composer - - - name: Install dependencies - run: composer install - - - name: Run code fixer - run: vendor/bin/php-cs-fixer fix - - - name: Check for fix changes - run: | - if [[ -n "$(git status --porcelain)" ]]; then - echo "Fix changes detected"; - git config user.name "${{ github.actor }}"; - git config user.email "${{ github.actor }}@users.noreply.github.com"; - git commit -am "chore: code style fix"; - else - echo "No fix changes detected"; - fi - - - name: Push changes - if: success() - run: git push diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b06f40e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,36 @@ +name: Lint + +on: + pull_request: + branches: + - stage + types: + - opened + - synchronize + - reopened + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.3" + tools: composer + + - name: Install php-cs-fixer + run: composer require --dev friendsofphp/php-cs-fixer + + - name: Run php-cs-fixer + run: vendor/bin/php-cs-fixer fix + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 From ed29cad379acb55b2fbe3321fef8a60a74b6638e Mon Sep 17 00:00:00 2001 From: mahiarirani Date: Sat, 28 Dec 2024 03:33:43 +0000 Subject: [PATCH 07/14] Apply automatic changes --- templates/admin-settings.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/templates/admin-settings.php b/templates/admin-settings.php index 51e01e2..feb5077 100644 --- a/templates/admin-settings.php +++ b/templates/admin-settings.php @@ -30,17 +30,17 @@
@@ -80,5 +80,5 @@ - +
From 4fafae68f45283a1e12c59beea8f6ec3f5ae6c7d Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 11:36:59 +0800 Subject: [PATCH 08/14] feat(cs): update auto commit - update: commit message --- .github/workflows/lint.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b06f40e..12cf4e9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -34,3 +34,8 @@ jobs: - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "chore: fix code style" + commit_options: "--no-verify" + commit_user_name: "GitHub Actions" + commit_user_email: "github-actions[bot]@users.noreply.github.com" From 22f891365ebc87fff8f793a7dc81471e9bc69277 Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 13:21:49 +0800 Subject: [PATCH 09/14] feat(cs): enable PSR12 and PhpCsFixer rules - add: extend NC rules - chore: lint new rules - fix: OC PSR4 detection - add: global imports - add: trailing comma in arrays and etc --- .php-cs-fixer.dist.php | 20 +- appinfo/routes.php | 3 - composer.json | 1 + lib/AppInfo/AppConstants.php | 5 +- lib/AppInfo/Application.php | 18 +- lib/Auth/License.php | 11 +- lib/Backend/BeeSwarm.php | 30 +-- lib/Controller/BeeController.php | 24 +- lib/Controller/SettingsController.php | 12 +- lib/Db/SwarmFile.php | 56 +++-- lib/Db/SwarmFileMapper.php | 67 ++---- lib/Migration/Version0001Date202204071430.php | 14 +- lib/Migration/Version0002Date202409251430.php | 15 +- lib/Migration/Version0003Date202401101430.php | 30 +-- lib/Migration/Version0004Date202410131430.php | 30 ++- lib/Migration/Version0005Date202411081430.php | 24 +- lib/Notification/Notifier.php | 48 ++-- lib/Sabre/PostPlugin.php | 26 ++- lib/Sabre/PropfindPlugin.php | 23 +- lib/Service/EthswarmService.php | 16 +- lib/Service/NotificationService.php | 7 +- lib/Storage/BeeSwarm.php | 221 +++++++----------- lib/Storage/BeeSwarmTrait.php | 104 ++++----- lib/Utils/Curl.php | 124 ++++------ lib/Utils/Env.php | 16 +- templates/admin-settings.php | 29 ++- templates/vue-admin-settings.php | 5 +- 27 files changed, 398 insertions(+), 581 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 529762c..acc4889 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -4,10 +4,28 @@ require_once './vendor/autoload.php'; -use Nextcloud\CodingStandard\Config; +use Nextcloud\CodingStandard\Config as Base; +use PhpCsFixer\Runner\Parallel\ParallelConfig; + +class Config extends Base { + public function getRules(array $rules = []): array + { + return [ + ...parent::getRules(), // Nextcloud Standard Rules + '@PSR12' => true, + '@PhpCsFixer' => true, + 'global_namespace_import' => [ + 'import_classes' => true, + ], + 'trailing_comma_in_multiline' => ['elements' => ['arguments', 'arrays', 'match', 'parameters']], + ]; + } +} $config = new Config(); $config + ->setParallelConfig(new ParallelConfig(8)) + ->setRiskyAllowed(true) ->getFinder() ->ignoreVCSIgnored(true) ->notPath('dev-environment') diff --git a/appinfo/routes.php b/appinfo/routes.php index bc08da5..1843905 100755 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,7 +19,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ return ['routes' => [ [ diff --git a/composer.json b/composer.json index 162d2b4..f047e90 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "autoload-dev": { "psr-4": { + "OC\\": "dev-environment/nextcloud_source/lib/", "OCP\\": "dev-environment/nextcloud_source/lib/public/", "OCA\\Files_External\\": "dev-environment/nextcloud_source/apps/files_external/lib/", "OCA\\Files_External_Ethswarm\\": "lib/" diff --git a/lib/AppInfo/AppConstants.php b/lib/AppInfo/AppConstants.php index 19a7370..36b54d1 100644 --- a/lib/AppInfo/AppConstants.php +++ b/lib/AppInfo/AppConstants.php @@ -1,11 +1,10 @@ - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -20,8 +19,8 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ + namespace OCA\Files_External_Ethswarm\AppInfo; class AppConstants { diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index e8fd72f..1fd388e 100755 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -2,9 +2,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -19,7 +17,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ declare(strict_types=1); @@ -40,22 +37,16 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Util; -/** - * @package OCA\Files_external_beeswarm\AppInfo - */ class Application extends App implements IBootstrap, IBackendProvider, IAuthMechanismProvider { - public function __construct(array $urlParams = []) { parent::__construct(AppConstants::APP_NAME, $urlParams); } - /** - * @{inheritdoc} - */ public function getBackends() { $container = $this->getContainer(); + return [ - $container->query(BeeSwarm::class) + $container->query(BeeSwarm::class), ]; } @@ -82,11 +73,9 @@ public function boot(IBootContext $context): void { }); $this->getAuthMechanisms(); - } - public function registerEventsScripts(IEventDispatcher $dispatcher) { - } + public function registerEventsScripts(IEventDispatcher $dispatcher) {} public function register(IRegistrationContext $context): void { // Register AddContentSecurityPolicyEvent for CSPListener class listenser here @@ -95,6 +84,7 @@ public function register(IRegistrationContext $context): void { public function getAuthMechanisms() { $container = $this->getContainer(); + return [ // AuthMechanism::BASIC HTTP mechanisms $container->get(License::class), diff --git a/lib/Auth/License.php b/lib/Auth/License.php index 21f271a..194b9e1 100755 --- a/lib/Auth/License.php +++ b/lib/Auth/License.php @@ -2,9 +2,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -19,7 +17,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Auth; @@ -29,15 +26,12 @@ use OCP\IL10N; /** - * Basic Http Authentication + * Basic Http Authentication. */ class License extends AuthMechanism { /** @const string */ public const SCHEME_ACCESS_KEY = 'access_key'; - /** - * @param IL10N $l - */ public function __construct(IL10N $l) { $this ->setIdentifier('access:key') @@ -47,6 +41,7 @@ public function __construct(IL10N $l) { (new DefinitionParameter(self::SCHEME_ACCESS_KEY, $l->t('Access Key'))) ->setTooltip($l->t('License Access Key')) ->setType(DefinitionParameter::VALUE_PASSWORD), - ]); + ]) + ; } } diff --git a/lib/Backend/BeeSwarm.php b/lib/Backend/BeeSwarm.php index fc3eee1..d3d4193 100755 --- a/lib/Backend/BeeSwarm.php +++ b/lib/Backend/BeeSwarm.php @@ -2,9 +2,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -19,7 +17,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Backend; @@ -35,31 +32,18 @@ use Psr\Log\LoggerInterface; class BeeSwarm extends Backend { - /** @var IL10N */ - private IL10N $l; + /** @const string */ + public const OPTION_HOST_URL = 'host_url'; - /** @var string */ protected string $appName; + private IL10N $l; - /** @var IConfig */ private IConfig $config; - /** @var LoggerInterface */ private LoggerInterface $logger; - /** @var GlobalStoragesService */ private GlobalStoragesService $globalStoragesService; - /** @const string */ - public const OPTION_HOST_URL = 'host_url'; - - /** - * @param string $appName - * @param IL10N $l - * @param IConfig $config - * @param LoggerInterface $logger - * @param GlobalStoragesService $globalStoragesService - */ public function __construct(string $appName, IL10N $l, IConfig $config, LoggerInterface $logger, GlobalStoragesService $globalStoragesService) { $this->l = $l; $this->appName = $appName; @@ -74,12 +58,10 @@ public function __construct(string $appName, IL10N $l, IConfig $config, LoggerIn ->addParameters([ (new DefinitionParameter(self::OPTION_HOST_URL, $l->t('Server URL'))) ->setTooltip($l->t('License Server URL')), - ])->addAuthScheme(License::SCHEME_ACCESS_KEY); + ])->addAuthScheme(License::SCHEME_ACCESS_KEY) + ; } - /** - * {@inheritdoc} - */ public function validateStorageDefinition(StorageConfig $storage): bool { $result = true; @@ -92,7 +74,7 @@ public function validateStorageDefinition(StorageConfig $storage): bool { // server url $host = $storage->getBackendOption(self::OPTION_HOST_URL); if (!preg_match('/^https?:\/\//i', $host)) { - $host = 'https://' . $host; + $host = 'https://'.$host; } if (!filter_var($host, FILTER_VALIDATE_URL)) { $this->logger->warning('invalid url'); diff --git a/lib/Controller/BeeController.php b/lib/Controller/BeeController.php index 1a19a73..a82fcd0 100755 --- a/lib/Controller/BeeController.php +++ b/lib/Controller/BeeController.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2023, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,7 +19,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Controller; @@ -34,20 +31,15 @@ use OCP\IRequest; class BeeController extends Controller { + /** @var string */ + protected $appName; /** @var Admin */ private $admin; - /** @var string */ - protected $appName; - /** @var IConfig */ private $config; - /** - * @param IConfig $config - * @param IRequest $request - */ public function __construct( string $appName, IConfig $config, @@ -61,8 +53,10 @@ public function __construct( /** * @NoCSRFRequired + * * @NoAdminRequired * Create a new postage batch stamp + * * @return \DataResponse */ public function createPostageBatch(): DataResponse { @@ -73,17 +67,21 @@ public function createPostageBatch(): DataResponse { if (isset($response_data['batchID'])) { return new DataResponse(['batchID' => $response_data['batchID']], Http::STATUS_OK); - } elseif (isset($response_data['message'])) { + } + if (isset($response_data['message'])) { return new DataResponse(['msg' => $response_data['message']], $response_data['code']); } } + return new DataResponse(['msg' => 'Error in request'], Http::STATUS_CONFLICT); } /** * @NoCSRFRequired + * * @NoAdminRequired * Top up an existing batch stamp based on the batchID + * * @return \DataResponse */ public function topUpBatch(): DataResponse { @@ -93,10 +91,12 @@ public function topUpBatch(): DataResponse { $response_data = $this->admin->topUpPostageStamp($postageBatch['activeBatchId'], $postageBatch['topUpValue'], $postageBatch['mount_urloptions']); if (isset($response_data['batchID'])) { return new DataResponse(['batchID' => $response_data['batchID']], Http::STATUS_OK); - } elseif (isset($response_data['message'])) { + } + if (isset($response_data['message'])) { return new DataResponse(['msg' => $response_data['message']], $response_data['code']); } } + return new DataResponse(['msg' => 'Error in request'], Http::STATUS_CONFLICT); } } diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index df5f6f4..4c99320 100755 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,7 +19,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Controller; @@ -31,18 +28,12 @@ use OCP\IRequest; class SettingsController extends Controller { - /** @var string */ protected $appName; /** @var IConfig */ private $config; - /** - * @param string $appName - * @param IConfig $config - * @param IRequest $request - */ public function __construct( string $appName, IConfig $config, @@ -53,7 +44,7 @@ public function __construct( } /** - * Set the storage config settings + * Set the storage config settings. */ public function admin(): void { if ($this->request->getParam('storageconfig')) { @@ -65,6 +56,7 @@ public function admin(): void { /** * @NoCSRFRequired + * * @NoAdminRequired * Save the storage config settings */ diff --git a/lib/Db/SwarmFile.php b/lib/Db/SwarmFile.php index 2faa43e..88fe1af 100755 --- a/lib/Db/SwarmFile.php +++ b/lib/Db/SwarmFile.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,7 +19,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Db; @@ -29,41 +26,40 @@ use OCP\AppFramework\Db\Entity; /** - * @method void setFileId(int $fileId) - * @method int getFileId() - * @method void setName(string $name) - * @method string getName() - * @method void setSwarmReference(string $swarmReference) - * @method string|null getSwarmReference() - * @method void setSwarmTag(string $tag) - * @method string|null getSwarmTag() - * @method void setMimetype(int $mimetype) - * @method int getMimetype() - * @method void setSize(int $size) - * @method string getSize() - * @method void setStorageMtime(int $mtime) - * @method int getStorageMtime() - * @method void setEncryptionKey(string $encryptionKey) - * @method string getEncryptionKey() - * @method void setStorage(int $storage) - * @method int|null getStorage() - * @method void setVisibility(int $visibility) - * @method int getVisibility() - * @method void setToken(string $token) - * @method int getToken() + * @method void setFileId(int $fileId) + * @method int getFileId() + * @method void setName(string $name) + * @method string getName() + * @method void setSwarmReference(string $swarmReference) + * @method null|string getSwarmReference() + * @method void setSwarmTag(string $tag) + * @method null|string getSwarmTag() + * @method void setMimetype(int $mimetype) + * @method int getMimetype() + * @method void setSize(int $size) + * @method string getSize() + * @method void setStorageMtime(int $mtime) + * @method int getStorageMtime() + * @method void setEncryptionKey(string $encryptionKey) + * @method string getEncryptionKey() + * @method void setStorage(int $storage) + * @method null|int getStorage() + * @method void setVisibility(int $visibility) + * @method int getVisibility() + * @method void setToken(string $token) + * @method int getToken() */ class SwarmFile extends Entity { - - /** @var int|null */ + /** @var null|int */ protected $fileId; /** @var string */ protected $name; - /** @var string|null */ + /** @var null|string */ protected $swarmReference; - /** @var string|null */ + /** @var null|string */ protected $swarmTag; /** @var int */ @@ -78,7 +74,7 @@ class SwarmFile extends Entity { /** @var string */ protected $encryptionKey; - /** @var int|null */ + /** @var null|int */ protected $storage; /** @var int */ diff --git a/lib/Db/SwarmFileMapper.php b/lib/Db/SwarmFileMapper.php index 3135dbb..9591e31 100755 --- a/lib/Db/SwarmFileMapper.php +++ b/lib/Db/SwarmFileMapper.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,7 +19,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Db; @@ -45,6 +42,7 @@ public function __construct(IDBConnection $db) { /** * @return SwarmFile[] + * * @throws Exception */ public function findAll(string $fileId): array { @@ -53,16 +51,13 @@ public function findAll(string $fileId): array { $select = $qb ->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('fileId', $qb->createNamedParameter($fileId))); + ->where($qb->expr()->eq('fileId', $qb->createNamedParameter($fileId))) + ; return $this->findEntities($select); } /** - * @param string $name - * @param int $storage - * - * @return SwarmFile * @throws DoesNotExistException * @throws Exception * @throws MultipleObjectsReturnedException @@ -74,15 +69,13 @@ public function find(string $name, int $storage): SwarmFile { ->select('*') ->from($this->getTableName()) ->where($qb->expr()->eq('name', $qb->createNamedParameter($name, $qb::PARAM_STR))) - ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))); + ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))) + ; + return $this->findEntity($select); } /** - * @param string $name - * @param int $storage - * - * @return int * @throws Exception */ public function findExists(string $name, int $storage): int { @@ -92,15 +85,13 @@ public function findExists(string $name, int $storage): int { ->select('id') ->from($this->getTableName()) ->where($qb->expr()->eq('name', $qb->createNamedParameter($name, $qb::PARAM_STR))) - ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))); + ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))) + ; + return count($this->findEntities($select)); } /** - * @param string $path - * @param int $storage - * @param string $token - * @return SwarmFile * @throws Exception */ public function createDirectory(string $path, int $storage, string $token): SwarmFile { @@ -111,12 +102,11 @@ public function createDirectory(string $path, int $storage, string $token): Swar $swarm->setStorageMtime(time()); $swarm->setStorage($storage); $swarm->setToken($token); + return $this->insert($swarm); } /** - * @param array $data - * @return SwarmFile * @throws Exception */ public function createFile(array $data): SwarmFile { @@ -129,15 +119,11 @@ public function createFile(array $data): SwarmFile { $swarm->setStorageMtime($data['storage_mtime']); $swarm->setStorage($data['storage']); $swarm->setToken($data['token']); + return $this->insert($swarm); } /** - * @param string $path - * @param int $storage - * @param bool $incSelf - * @param bool $recursive - * @return array * @throws Exception|MultipleObjectsReturnedException */ public function getPathTree(string $path, int $storage, bool $incSelf = true, bool $recursive = true): array { @@ -150,7 +136,7 @@ public function getPathTree(string $path, int $storage, bool $incSelf = true, bo } } - if ($path !== '') { + if ('' !== $path) { $path .= '/'; } @@ -158,19 +144,17 @@ public function getPathTree(string $path, int $storage, bool $incSelf = true, bo $select = $qb ->select('*') ->from($this->getTableName()) - ->where($qb->expr()->like('name', $qb->createNamedParameter($this->db->escapeLikeParameter($path) . '%'), $qb::PARAM_STR)) - ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))); + ->where($qb->expr()->like('name', $qb->createNamedParameter($this->db->escapeLikeParameter($path).'%'), $qb::PARAM_STR)) + ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))) + ; if (!$recursive) { - $select->andWhere($qb->expr()->notLike('name', $qb->createNamedParameter($this->db->escapeLikeParameter($path) . '%/%'), $qb::PARAM_STR)); + $select->andWhere($qb->expr()->notLike('name', $qb->createNamedParameter($this->db->escapeLikeParameter($path).'%/%'), $qb::PARAM_STR)); } + return array_merge($dir, $this->findEntities($select)); } /** - * @param string $path1 - * @param string $path2 - * @param int $storage - * @return int * @throws Exception */ public function updatePath(string $path1, string $path2, int $storage): int { @@ -179,13 +163,16 @@ public function updatePath(string $path1, string $path2, int $storage): int { ->update($this->getTableName()) ->set('name', $qb->createNamedParameter($path2)) ->where($qb->expr()->eq('name', $qb->createNamedParameter($path1, $qb::PARAM_STR))) - ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))); + ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storage, $qb::PARAM_INT))) + ; $qb->getSQL(); + return $qb->executeStatement(); } /** * @return SwarmFile[] + * * @throws Exception */ public function findAllWithToken(string $token): array { @@ -194,23 +181,19 @@ public function findAllWithToken(string $token): array { $select = $qb ->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))); + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) + ; return $this->findEntities($select); } - /** - * @param string $token - * @param int $storageId - * @return void - * @throws \OCP\DB\Exception + * @throws Exception */ public function updateStorageIds(string $token, int $storageId): void { foreach ($this->findAllWithToken($token) as $swarmFile) { $swarmFile->setStorage($storageId); $this->update($swarmFile); - }; + } } - } diff --git a/lib/Migration/Version0001Date202204071430.php b/lib/Migration/Version0001Date202204071430.php index e5f5180..b45e69c 100755 --- a/lib/Migration/Version0001Date202204071430.php +++ b/lib/Migration/Version0001Date202204071430.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,8 +19,8 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ + namespace OCA\Files_External_Ethswarm\Migration; use Closure; @@ -33,13 +31,13 @@ class Version0001Date202204071430 extends SimpleMigrationStep { public const _TABLENAME = 'files_swarm'; + /** - * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options + * * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); @@ -80,9 +78,9 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op $table->setPrimaryKey(['id']); $table->addIndex(['storage'], 'storage_index'); } + return $schema; } - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { - } + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {} } diff --git a/lib/Migration/Version0002Date202409251430.php b/lib/Migration/Version0002Date202409251430.php index 4e9fe5b..b627dd3 100644 --- a/lib/Migration/Version0002Date202409251430.php +++ b/lib/Migration/Version0002Date202409251430.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,8 +19,8 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ + namespace OCA\Files_External_Ethswarm\Migration; use Closure; @@ -33,13 +31,13 @@ class Version0002Date202409251430 extends SimpleMigrationStep { public const _TABLENAME = 'files_swarm'; + /** - * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options + * * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); @@ -51,11 +49,10 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op 'length' => 8, 'default' => 1, ]); - } + return $schema; } - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { - } + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {} } diff --git a/lib/Migration/Version0003Date202401101430.php b/lib/Migration/Version0003Date202401101430.php index 5991c78..caa5046 100644 --- a/lib/Migration/Version0003Date202401101430.php +++ b/lib/Migration/Version0003Date202401101430.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,11 +19,12 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ + namespace OCA\Files_External_Ethswarm\Migration; use Closure; +use OC; use OCP\DB\ISchemaWrapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\IMimeTypeLoader; @@ -34,41 +33,34 @@ use OCP\Migration\SimpleMigrationStep; class Version0003Date202401101430 extends SimpleMigrationStep { - private $db; - /** @var \OCP\Files\IMimeTypeLoader */ private IMimeTypeLoader $mimeTypeHandler; public function __construct(IDBConnection $db) { $this->db = $db; - $this->mimeTypeHandler = \OC::$server->get(IMimeTypeLoader::class); + $this->mimeTypeHandler = OC::$server->get(IMimeTypeLoader::class); } - /** - * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options + * * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { - - } + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {} - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { $currentVersion = $this->getCurrentPluginVersion(); $mimetype = 'text/markdown'; if (version_compare($currentVersion, '0.5.4', '==')) { - $updateQb = $this->db->getQueryBuilder(); $updateQb->update('files_swarm') ->set('mimetype', $updateQb->createNamedParameter($this->mimeTypeHandler->getId($mimetype), IQueryBuilder::PARAM_INT)) ->where($updateQb->expr()->like('name', $updateQb->createNamedParameter('%.md'))) - ->executeStatement(); + ->executeStatement() + ; } - } private function getCurrentPluginVersion() { @@ -78,9 +70,9 @@ private function getCurrentPluginVersion() { ->from('appconfig') ->where($qb->expr()->eq('appid', $qb->createNamedParameter('files_external_ethswarm'))) ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('installed_version'))) - ->executeQuery(); - $version = $result->fetchOne(); + ->executeQuery() + ; - return $version; + return $result->fetchOne(); } } diff --git a/lib/Migration/Version0004Date202410131430.php b/lib/Migration/Version0004Date202410131430.php index 0b7a04f..57c3a6c 100644 --- a/lib/Migration/Version0004Date202410131430.php +++ b/lib/Migration/Version0004Date202410131430.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,8 +19,8 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ + namespace OCA\Files_External_Ethswarm\Migration; use Closure; @@ -38,25 +36,21 @@ public function __construct(IDBConnection $db) { $this->db = $db; } - /** - * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options + * * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {} - } - - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { $qb = $this->db->getQueryBuilder(); - $resultNI = $qb->select('numeric_id') ->from('storages') ->where($qb->expr()->like('id', $qb->createNamedParameter('ethswarm::https:%'))) - ->executeQuery(); + ->executeQuery() + ; // This migration step only runs if there is a license that contains the api_url (previous verion of plugin) while ($row = $resultNI->fetch()) { @@ -67,7 +61,8 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $result = $qb->select('mount_id') ->from('external_mounts') ->where($qb->expr()->eq('storage_backend', $qb->createNamedParameter('files_external_ethswarm'))) - ->executeQuery(); + ->executeQuery() + ; $mountid = $result->fetchOne(); $qb = $this->db->getQueryBuilder(); @@ -75,15 +70,16 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array ->from('external_config', 'm') ->where($qb->expr()->eq('m.mount_id', $qb->createNamedParameter($mountid))) ->andWhere($qb->expr()->eq('m.key', $qb->createNamedParameter('access_key'))) - ->executeQuery(); + ->executeQuery() + ; $key = $result->fetchOne(); $updateQb = $this->db->getQueryBuilder(); $result = $updateQb->update('storages') - ->set('id', $updateQb->createNamedParameter('ethswarm::' . $key)) + ->set('id', $updateQb->createNamedParameter('ethswarm::'.$key)) ->where($updateQb->expr()->eq('numeric_id', $updateQb->createNamedParameter($numeric_id))) - ->executeStatement(); + ->executeStatement() + ; } - } } diff --git a/lib/Migration/Version0005Date202411081430.php b/lib/Migration/Version0005Date202411081430.php index c7d70e4..09b47d6 100644 --- a/lib/Migration/Version0005Date202411081430.php +++ b/lib/Migration/Version0005Date202411081430.php @@ -4,9 +4,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -21,8 +19,8 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ + namespace OCA\Files_External_Ethswarm\Migration; use Closure; @@ -33,22 +31,19 @@ use OCP\Migration\SimpleMigrationStep; class Version0005Date202411081430 extends SimpleMigrationStep { - private $db; public const _TABLENAME = 'files_swarm'; - + private $db; public function __construct(IDBConnection $db) { $this->db = $db; } - /** - * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options + * * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); $table = $schema->getTable(self::_TABLENAME); @@ -60,19 +55,20 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op 'default' => 'none', ]); $table->addIndex(['token'], 'hejbit_token_index'); - } + return $schema; } - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { $gqbNI = $this->db->getQueryBuilder(); // Get all the numeric_id's of the swarm storages $resultNI = $gqbNI->select('numeric_id', 'id') ->from('storages') ->where($gqbNI->expr()->like('id', $gqbNI->createNamedParameter('ethswarm::%'))) - ->executeQuery(); + ->executeQuery() + ; while ($row = $resultNI->fetch()) { // Get all the files on each swarm storage @@ -84,8 +80,8 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $result = $updateQb->update(self::_TABLENAME) ->set('token', $updateQb->createNamedParameter($token_id)) ->where($updateQb->expr()->eq('storage', $updateQb->createNamedParameter($numeric_id))) - ->executeStatement(); + ->executeStatement() + ; } - } } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 47eaff6..50f37d8 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -1,11 +1,10 @@ - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -20,46 +19,50 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ + namespace OCA\Files_External_Ethswarm\Notification; +use InvalidArgumentException; use OCA\Files_External_Ethswarm\AppInfo\AppConstants; +use OCP\IURLGenerator; +use OCP\L10N\IFactory; +use OCP\Notification\INotification; +use OCP\Notification\INotifier; -class Notifier implements \OCP\Notification\INotifier { +class Notifier implements INotifier { protected $factory; protected $url; - public function __construct(\OCP\L10N\IFactory $factory, - \OCP\IURLGenerator $urlGenerator) { + public function __construct( + IFactory $factory, + IURLGenerator $urlGenerator + ) { $this->factory = $factory; $this->url = $urlGenerator; } /** - * Identifier of the notifier, only use [a-z0-9_] - * @return string + * Identifier of the notifier, only use [a-z0-9_]. */ public function getID(): string { return AppConstants::APP_NAME; } /** - * Human-readable name describing the notifier - * @return string + * Human-readable name describing the notifier. */ public function getName(): string { return $this->factory->get(AppConstants::APP_NAME)->t('Hejbit External Storage'); } /** - * @param \OCP\Notification\INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification */ - public function prepare(\OCP\Notification\INotification $notification, string $languageCode): \OCP\Notification\INotification { - if ($notification->getApp() !== AppConstants::APP_NAME) { + public function prepare(INotification $notification, string $languageCode): INotification { + if (AppConstants::APP_NAME !== $notification->getApp()) { // Not my app => throw - throw new \InvalidArgumentException(); + throw new InvalidArgumentException(); } // Read the language from the notification @@ -73,7 +76,8 @@ public function prepare(\OCP\Notification\INotification $notification, string $l // and https://github.com/nextcloud/server/blob/master/lib/public/RichObjectStrings/Definitions.php // for a list of defined objects and their parameters. $parameters = $notification->getSubjectParameters(); - $notification->setRichSubject($l->t('Your file \'{filename}\' was decentralized.'), + $notification->setRichSubject( + $l->t('Your file \'{filename}\' was decentralized.'), [ 'filename' => [ 'type' => 'file', @@ -81,15 +85,17 @@ public function prepare(\OCP\Notification\INotification $notification, string $l 'name' => basename($parameters['path']), 'path' => $parameters['path'], ], - ]); + ] + ); // Set the plain text subject automatically $this->setParsedSubjectFromRichSubject($notification); + return $notification; default: // Unknown subject => Unknown notification => throw - throw new \InvalidArgumentException(); + throw new InvalidArgumentException(); } } @@ -98,14 +104,12 @@ public function prepare(\OCP\Notification\INotification $notification, string $l * based on the rich subject you set. This is also the default behaviour of the API * since Nextcloud 26, but in case you would like to return simpler or other strings, * this function allows you to take over. - * - * @param \OCP\Notification\INotification $notification */ - protected function setParsedSubjectFromRichSubject(\OCP\Notification\INotification $notification): void { + protected function setParsedSubjectFromRichSubject(INotification $notification): void { $placeholders = $replacements = []; foreach ($notification->getRichSubjectParameters() as $placeholder => $parameter) { - $placeholders[] = '{' . $placeholder . '}'; - if ($parameter['type'] === 'file') { + $placeholders[] = '{'.$placeholder.'}'; + if ('file' === $parameter['type']) { $replacements[] = $parameter['path']; } else { $replacements[] = $parameter['name']; diff --git a/lib/Sabre/PostPlugin.php b/lib/Sabre/PostPlugin.php index fbb53ce..8fcc9e0 100644 --- a/lib/Sabre/PostPlugin.php +++ b/lib/Sabre/PostPlugin.php @@ -4,7 +4,10 @@ namespace OCA\Files_External_Ethswarm\Sabre; +use OCA\DAV\Connector\Sabre\Directory; +use OCA\DAV\Connector\Sabre\File; use OCA\Files_External_Ethswarm\Service\EthswarmService; +use Sabre\DAV\Exception\NotImplemented; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; use Sabre\HTTP\RequestInterface; @@ -29,14 +32,14 @@ public function initialize(Server $server) { public function httpPost(RequestInterface $request, ResponseInterface $response) { $action = $request->getRawServerValue('HTTP_HEJBIT_ACTION') ?? null; - if ($action === 'hide') { + if ('hide' === $action) { $path = $request->getPath(); $node = $this->server->tree->getNodeForPath($path); - if (($node instanceof \OCA\DAV\Connector\Sabre\File)) { + if ($node instanceof File) { $storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId(); $filename = $node->getFileInfo()->getinternalPath(); } - if (($node instanceof \OCA\DAV\Connector\Sabre\Directory)) { + if ($node instanceof Directory) { $storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId(); $filename = $node->getFileInfo()->getinternalPath(); } @@ -49,14 +52,15 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $response->setHeader('Content-Length', '0'); return false; - } elseif ($action === 'unhide') { + } + if ('unhide' === $action) { $path = $request->getPath(); $node = $this->server->tree->getNodeForPath($path); - if (($node instanceof \OCA\DAV\Connector\Sabre\File)) { + if ($node instanceof File) { $storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId(); $filename = $node->getFileInfo()->getinternalPath(); } - if (($node instanceof \OCA\DAV\Connector\Sabre\Directory)) { + if ($node instanceof Directory) { $storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId(); $filename = $node->getFileInfo()->getinternalPath(); } @@ -69,13 +73,13 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) return false; } // No Hejbit-action, allow other plugins to handle the request - elseif ($action === null) { + if (null === $action) { return true; } // Invalid Hejbit-action, throw exception - else { - $exMessage = 'There was no plugin in the system that was willing to handle a POST method with this action > ' . $action . '.'; - throw new \Sabre\DAV\Exception\NotImplemented($exMessage); - } + + $exMessage = 'There was no plugin in the system that was willing to handle a POST method with this action > '.$action.'.'; + + throw new NotImplemented($exMessage); } } diff --git a/lib/Sabre/PropfindPlugin.php b/lib/Sabre/PropfindPlugin.php index 09b6159..c4222e4 100755 --- a/lib/Sabre/PropfindPlugin.php +++ b/lib/Sabre/PropfindPlugin.php @@ -22,8 +22,11 @@ * along with this program. If not, see . * */ + namespace OCA\Files_External_Ethswarm\Sabre; +use OCA\DAV\Connector\Sabre\Directory; +use OCA\DAV\Connector\Sabre\File; use OCA\Files_External_Ethswarm\Service\EthswarmService; use Sabre\DAV\INode; use Sabre\DAV\PropFind; @@ -48,12 +51,10 @@ public function initialize(Server $server) { $this->server = $server; $this->server->on('propFind', [$this, 'propFind']); - - } public function propFind(PropFind $propFind, INode $node) { - if (($node instanceof \OCA\DAV\Connector\Sabre\File)) { + if ($node instanceof File) { $storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId(); $filename = $node->getFileInfo()->getinternalPath(); $mountpoint = $node->getFileInfo()->getMountPoint()->getStorageId(); @@ -66,18 +67,18 @@ public function propFind(PropFind $propFind, INode $node) { return $class->getSwarmRef($filename, $storageid); }); - if ($class->getVisiblity($filename, $storageid) == 1) { + if (1 == $class->getVisiblity($filename, $storageid)) { $propFind->set('{http://nextcloud.org/ns}hidden', 'false', 200); } else { $propFind->set('{http://nextcloud.org/ns}hidden', 'true', 200); } - $propFind->handle(self::ETHSWARM_NODE, function () use ($class, $storageid, $filename) { + $propFind->handle(self::ETHSWARM_NODE, function () { return 'true'; }); } - if (($node instanceof \OCA\DAV\Connector\Sabre\Directory)) { + if ($node instanceof Directory) { $storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId(); $filename = $node->getFileInfo()->getinternalPath(); $mountpoint = $node->getFileInfo()->getMountPoint()->getStorageId(); @@ -87,22 +88,18 @@ public function propFind(PropFind $propFind, INode $node) { } $class = $this->EthswarmService; - $propFind->handle(self::ETHSWARM_NODE, function () use ($class, $storageid, $filename) { + $propFind->handle(self::ETHSWARM_NODE, function () { return 'true'; }); - if ($filename === '') { + if ('' === $filename) { return ''; } - if ($class->getVisiblity($filename, $storageid) == 1) { + if (1 == $class->getVisiblity($filename, $storageid)) { $propFind->set('{http://nextcloud.org/ns}hidden', 'false', 200); } else { $propFind->set('{http://nextcloud.org/ns}hidden', 'true', 200); } - - } - } - } diff --git a/lib/Service/EthswarmService.php b/lib/Service/EthswarmService.php index 28ab974..e676f78 100755 --- a/lib/Service/EthswarmService.php +++ b/lib/Service/EthswarmService.php @@ -21,14 +21,18 @@ * along with this program. If not, see . * */ + namespace OCA\Files_External_Ethswarm\Service; +use OC; use OCA\Files_External_Ethswarm\Db\SwarmFileMapper; use OCP\Files\StorageNotAvailableException; use OCP\IDBConnection; use OCP\IL10N; class EthswarmService { + /** @var IDBConnection */ + protected $dbConnection; /** @var IL10N */ private $l10n; @@ -36,20 +40,16 @@ class EthswarmService { /** @var SwarmFileMapper */ private $filemapper; - /** @var \OCP\IDBConnection */ - protected $dbConnection; - public function __construct(IL10N $l10n) { $this->l10n = $l10n; - $dbConnection = \OC::$server->get(IDBConnection::class); + $dbConnection = OC::$server->get(IDBConnection::class); $this->filemapper = new SwarmFileMapper($dbConnection); } /** - * @param string $filename - * @param int $storageid - * @throws StorageNotAvailableException * @return string + * + * @throws StorageNotAvailableException */ public function getSwarmRef(string $filename, int $storageid) { $swarmFile = $this->filemapper->find($filename, $storageid); @@ -59,12 +59,14 @@ public function getSwarmRef(string $filename, int $storageid) { public function getVisiblity(string $filename, int $storageid) { $swarmFile = $this->filemapper->find($filename, $storageid); + return $swarmFile->getVisibility(); } public function setVisiblity(string $filename, int $storageid, int $visibility) { $swarmFile = $this->filemapper->find($filename, $storageid); $swarmFile->setVisibility($visibility); + return $this->filemapper->update($swarmFile); } diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index 3514e88..3a972a2 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -1,11 +1,10 @@ - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -20,11 +19,11 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Service; +use DateTime; use OCA\Files_External_Ethswarm\AppInfo\AppConstants; use OCP\IUserManager; use OCP\IUserSession; @@ -49,7 +48,7 @@ public function sendTemporaryNotification($subject, $path) { $notification->setUser($userId); $notification->setSubject($subject, ['path' => $path]); $notification->setObject('temporary', $userId); // Marks the notification as temporary - $notification->setDateTime(new \DateTime()); + $notification->setDateTime(new DateTime()); // Send the notification $this->notificationManager->notify($notification); diff --git a/lib/Storage/BeeSwarm.php b/lib/Storage/BeeSwarm.php index a5455cf..cb437e8 100755 --- a/lib/Storage/BeeSwarm.php +++ b/lib/Storage/BeeSwarm.php @@ -2,9 +2,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -19,7 +17,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Storage; @@ -55,59 +52,45 @@ class BeeSwarm extends Common { use BeeSwarmTrait; - /** @var int */ protected int $storageId; - /** @var bool */ + protected IDBConnection $dbConnection; + + protected IL10N $l10n; + + protected string $id; + private bool $isEncrypted; // TODO: remove - /** @var SwarmFileMapper */ private SwarmFileMapper $fileMapper; - /** @var IConfig */ private IConfig $config; - /** @var IDBConnection */ - protected IDBConnection $dbConnection; - - /** @var IL10N */ - protected IL10N $l10n; - - /** @var IMimeTypeLoader */ private IMimeTypeLoader $mimeTypeHandler; - /** @var ITempManager */ private ITempManager $tempManager; - /** @var IMimeTypeDetector */ private IMimeTypeDetector $mimeTypeDetector; - /** @var Cache */ private Cache $cacheHandler; - /** @var NotificationService */ private NotificationService $notificationService; - /** @var string */ - protected string $id; - - /** @var string */ private string $token; - /** @var LoggerInterface */ private LoggerInterface $logger; /** - * @param $params - * @throws StorageBadConfigException + * @param mixed $params * + * @throws StorageBadConfigException */ public function __construct($params) { parent::__construct($params); // Load storage configuration $this->parseParams($params); - $this->id = 'ethswarm::' . $this->access_key; + $this->id = 'ethswarm::'.$this->access_key; $this->storageId = $this->getStorageCache()->getNumericId(); $this->token = $this->getStorageCache()->getStorageId($this->storageId); @@ -140,28 +123,24 @@ public function __construct($params) { $mountId = $storageMount->getMountId(); $this->config = OC::$server->get(IConfig::class); - $configSettings = $this->config->getAppValue(AppConstants::APP_NAME, 'storageconfig', ''); //default + $configSettings = $this->config->getAppValue(AppConstants::APP_NAME, 'storageconfig'); $mounts = json_decode($configSettings, true); if (is_array($mounts)) { $mountIds = array_column($mounts, 'mount_id'); $key = array_search($mountId, $mountIds); - if (!empty($key) || $key === 0) { - $this->isEncrypted = $mounts[$key]['encrypt'] === '1'; + if (!empty($key) || 0 === $key) { + $this->isEncrypted = '1' === $mounts[$key]['encrypt']; } } } $this->cacheHandler = new Cache($this); } - /** - * @inheritDoc - */ public function getId(): string { return $this->id; } /** - * @inheritDoc * @throws Exception */ public function test(): bool { @@ -172,11 +151,14 @@ public function test(): bool { $this->fileMapper->updateStorageIds($this->token, $this->storageId); $this->add_root_folder_cache(); $this->add_token_files_cache(); + return true; } /** - * @inheritDoc + * @param mixed $source + * @param mixed $target + * * @throws Exception */ public function copy($source, $target): bool { @@ -185,9 +167,10 @@ public function copy($source, $target): bool { $sourceFile = $this->fileMapper->find($source, $this->storageId); if (!$sourceFile->getFileId()) { $this->logger->error( - 'copy failed: source file not found in mapper ' . $source, + 'copy failed: source file not found in mapper '.$source, ['app' => AppConstants::APP_NAME] ); + return false; } @@ -207,9 +190,10 @@ public function copy($source, $target): bool { if (!$newFile->getFileId()) { $this->logger->error( - 'copy failed: failed to create new file in mapper ' . $target, + 'copy failed: failed to create new file in mapper '.$target, ['app' => AppConstants::APP_NAME] ); + return false; } @@ -219,9 +203,6 @@ public function copy($source, $target): bool { } } - /** - * @return void - */ public function add_root_folder_cache(): void { $fileData = [ 'storage' => $this->storageId, @@ -240,10 +221,6 @@ public function add_root_folder_cache(): void { $this->cacheHandler->put($fileData['path'], $fileData); } - /** - * @param SwarmFile $file - * @return bool - */ public function add_file_cache(SwarmFile $file): bool { $fileData = [ 'storage' => $file->getStorage(), @@ -265,6 +242,7 @@ public function add_file_cache(SwarmFile $file): bool { } $this->cacheHandler->put($fileData['path'], $fileData); + return true; } @@ -275,79 +253,74 @@ public function add_token_files_cache(): void { foreach ($this->fileMapper->findAllWithToken($this->token) as $file) { $this->add_file_cache($file); } - } /** - * @inheritDoc + * @param mixed $path + * * @throws Exception */ public function file_exists($path): bool { - if ($path === '' || $path === '/' || $path === '.') { + if ('' === $path || '/' === $path || '.' === $path) { // Return true always the creation of the root folder return true; } $exists = $this->fileMapper->findExists($path, $this->storageId); - if ($exists == 0) { + if (0 == $exists) { return false; } + return true; } - /** - * @inheritDoc - */ public function filemtime($path): int { return 0; } /** - * @inheritDoc + * @param mixed $path + * * @throws Exception */ - public function stat($path): bool|array { + public function stat($path): array|bool { $data = $this->getMetaData($path); - if ($data['mimetype'] === 'httpd/unix-directory') { + if ('httpd/unix-directory' === $data['mimetype']) { return false; } + return [ 'mtime' => $data['mtime'], 'size' => $data['size'], ]; } - /** - * @inheritDoc - */ public function getETag($path): ?string { return null; } - /** - * @inheritDoc - */ public function needsPartFile(): bool { return false; } /** - * @inheritDoc + * @param mixed $path + * * @throws Exception */ public function mkdir($path): bool { $this->fileMapper->createDirectory($path, $this->storageId, $this->token); + return true; } - /** - * @inheritDoc - */ public function rmdir($path): void { // TODO: Implement rmdir() method. } /** - * @inheritDoc + * @param mixed $source + * @param mixed $target + * * @throws Exception */ public function rename($source, $target): bool { @@ -357,118 +330,89 @@ public function rename($source, $target): bool { $newPath = substr_replace($oldPath, $target, 0, strlen($source)); $this->fileMapper->updatePath($oldPath, $newPath, $this->storageId); } + return true; } - /** - * @inheritDoc - */ public function opendir($path): bool { return true; } /** - * * @inheritDoc + * * {@inheritDoc} + * * @throws Exception */ public function is_dir($path): bool { - return $this->getMetaData($path)['mimetype'] === 'httpd/unix-directory'; + return 'httpd/unix-directory' === $this->getMetaData($path)['mimetype']; } /** - * @inheritDoc + * @param mixed $path + * * @throws Exception */ public function is_file($path): bool { - return $this->getMetaData($path)['mimetype'] !== 'httpd/unix-directory'; + return 'httpd/unix-directory' !== $this->getMetaData($path)['mimetype']; } /** - * @inheritDoc + * @param mixed $path + * * @throws Exception */ public function filetype($path): string { return $this->is_file($path) ? 'file' : 'dir'; } - /** - * @inheritDoc - */ public function getPermissions($path = null): int { - return (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE - Constants::PERMISSION_UPDATE); + return Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE - Constants::PERMISSION_UPDATE; } - /** - * @inheritDoc - */ - public function free_space($path): float|false|int { + public function free_space($path): false|float|int { return FileInfo::SPACE_UNLIMITED; } - /** - * @inheritDoc - */ public function hasUpdated($path, $time): bool { return true; } - /** - * @inheritDoc - */ public function isLocal(): bool { // the common implementation returns a temporary file by // default, which is not local return false; } - /** - * @inheritDoc - */ public function setMountOptions(array $options): void { // TODO: Implement setMountOptions() method. } - /** - * @inheritDoc - */ public function getMountOption($name, $default = null): ?string { return $this->mountOptions[$name] ?? $default; } - /** - * @inheritDoc - */ - public function verifyPath($path, $fileName) { - - } + public function verifyPath($path, $fileName) {} - /** - * @inheritDoc - */ public function isCreatable($path): bool { return true; } - /** - * @inheritDoc - */ public function isUpdatable($path): bool { return true; } - /** - * @inheritDoc - */ public function unlink($path): bool { return true; } /** - * @inheritDoc + * @param mixed $path + * @param mixed $mode + * * @throws Exception */ public function fopen($path, $mode) { - if ($path === '' || $path === '/' || $path === '.') { + if ('' === $path || '/' === $path || '.' === $path) { return false; } $swarmFile = $this->fileMapper->find($path, $this->storageId); @@ -479,6 +423,7 @@ public function fopen($path, $mode) { case 'rb': // Get file from swarm return $this->downloadSwarm($reference); + case 'w': // Open for writing only; place the file pointer at the beginning of the file case 'w+': // Open for reading and writing case 'wb': @@ -492,37 +437,31 @@ public function fopen($path, $mode) { case 'c': // Open the file for writing only case 'c+': // Open the file for reading and writing; } + return false; } - /** - * @inheritDoc - */ public function touch($path, $mtime = null): bool { return true; } /** - * @inheritDoc + * @param mixed $path + * * @throws Exception */ - public function file_get_contents($path): string|false { + public function file_get_contents($path): false|string { $swarmFile = $this->fileMapper->find($path, $this->storageId); $reference = $swarmFile->getSwarmReference(); + return stream_get_contents($this->downloadSwarm($reference)); } - /** - * @inheritDoc - */ - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents($path, $data): false|float|int { // TODO: Implement file_put_contents() method. return parent::file_put_contents($path, $data); } - /** - * @inheritDoc - */ public function getDirectDownload($path): array|bool { // TODO: Implement getDirectDownload() method. return parent::getDirectDownload($path); @@ -536,13 +475,14 @@ public function getCache($path = '', $storage = null) */ /** - * @inheritDoc + * @param mixed $path + * * @throws Exception */ public function getMetaData($path): ?array { $data = []; // If not in swarm table, assume it's a folder - $exists = $this->fileMapper->findExists($path, $this->storageId) !== 0; + $exists = 0 !== $this->fileMapper->findExists($path, $this->storageId); if (!$exists) { // Create a folder item $data['name'] = $path; @@ -550,7 +490,7 @@ public function getMetaData($path): ?array { $data['permissions'] = (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE); // Check if this is likely a file based on extension - $isFile = pathinfo($path, PATHINFO_EXTENSION) !== ''; + $isFile = '' !== pathinfo($path, PATHINFO_EXTENSION); if ($isFile) { $data['mimetype'] = $this->mimeTypeDetector->detectPath($path); @@ -570,7 +510,7 @@ public function getMetaData($path): ?array { } else { $data['permissions'] = (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE - Constants::PERMISSION_UPDATE); } - $data['name'] = basename($path); //TODO: Test + $data['name'] = basename($path); // TODO: Test $data['mimetype'] = $this->mimeTypeHandler->getMimetypeById($mimeTypeId); $data['mtime'] = time(); $data['storage_mtime'] = $swarmFile->getStorageMtime(); @@ -578,11 +518,13 @@ public function getMetaData($path): ?array { $data['etag'] = uniqid(); $data['swarm_ref'] = $swarmFile->getSwarmReference(); } + return $data; } /** - * @inheritDoc + * @param mixed $directory + * * @throws Exception */ public function getDirectoryContent($directory): Traversable { @@ -594,19 +536,7 @@ public function getDirectoryContent($directory): Traversable { /** * @param resource $stream - * @return string - */ - protected function createTempFile($stream): string { - $extension = ''; - $tmpFile = $this->tempManager->getTemporaryFile($extension); - $target = fopen($tmpFile, 'w'); - OC_Helper::streamCopy($stream, $target); - fclose($target); - return $tmpFile; - } - - /** - * @inheritDoc + * * @throws Exception */ public function writeStream(string $path, $stream, ?int $size = null): int { @@ -643,4 +573,17 @@ public function writeStream(string $path, $stream, ?int $size = null): int { // TODO: Read back from swarm to return filesize? return $tmpFileSize; } + + /** + * @param resource $stream + */ + protected function createTempFile($stream): string { + $extension = ''; + $tmpFile = $this->tempManager->getTemporaryFile($extension); + $target = fopen($tmpFile, 'w'); + OC_Helper::streamCopy($stream, $target); + fclose($target); + + return $tmpFile; + } } diff --git a/lib/Storage/BeeSwarmTrait.php b/lib/Storage/BeeSwarmTrait.php index 1889366..30a33d5 100755 --- a/lib/Storage/BeeSwarmTrait.php +++ b/lib/Storage/BeeSwarmTrait.php @@ -2,9 +2,7 @@ /** * @copyright Copyright (c) 2022, MetaProvide Holding EKF - * * @author Ron Trevor - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -19,7 +17,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ namespace OCA\Files_External_Ethswarm\Storage; @@ -36,15 +33,21 @@ trait BeeSwarmTrait { private const INFRASTRUCTURE_VERSION_GATEWAY = 1; private const INFRASTRUCTURE_VERSION_HEJBIT = 2; - /** @var string */ protected string $api_url; - /** @var string */ protected string $access_key; + public function isVersion(int $version = self::INFRASTRUCTURE_VERSION_GATEWAY): bool { + return match ($version) { + self::INFRASTRUCTURE_VERSION_GATEWAY => 'https://license.hejbit.com' === $this->api_url, + self::INFRASTRUCTURE_VERSION_HEJBIT => 'https://license.hejbit.com' !== $this->api_url, + default => false, + }; + } + /** - * @param $params - * @return void + * @param mixed $params + * * @throws StorageBadConfigException */ protected function parseParams($params): void { @@ -55,63 +58,54 @@ protected function parseParams($params): void { } /** - * @param array $params - * @return void * @throws StorageBadConfigException */ private function validateParams(array &$params): void { if (!$params[BeeSwarm::OPTION_HOST_URL] || !$params[License::SCHEME_ACCESS_KEY]) { - throw new StorageBadConfigException('Creating ' . self::class . ' storage failed, required parameters not set'); + throw new StorageBadConfigException('Creating '.self::class.' storage failed, required parameters not set'); } if (!preg_match('/^https?:\/\//i', $params[BeeSwarm::OPTION_HOST_URL])) { - $params[BeeSwarm::OPTION_HOST_URL] = 'https://' . $params[BeeSwarm::OPTION_HOST_URL]; + $params[BeeSwarm::OPTION_HOST_URL] = 'https://'.$params[BeeSwarm::OPTION_HOST_URL]; } if (!filter_var($params[BeeSwarm::OPTION_HOST_URL], FILTER_VALIDATE_URL)) { - throw new StorageBadConfigException('Creating ' . self::class . ' storage failed, invalid url'); + throw new StorageBadConfigException('Creating '.self::class.' storage failed, invalid url'); } } /** - * @return string * @throws CurlException * @throws SwarmException */ private function getUploadLink(): string { - $endpoint = $this->api_url . '/api/upload'; + $endpoint = $this->api_url.'/api/upload'; $curl = new Curl($endpoint, authorization: $this->access_key); $response = $curl->exec(true); if (!$curl->isResponseSuccessful()) { - throw new SwarmException('Failed to connect to HejBit: ' . $response['message']); + throw new SwarmException('Failed to connect to HejBit: '.$response['message']); } return $response['url']; } /** - * @param string $reference - * @return string * @throws CurlException * @throws SwarmException */ private function getDownloadLink(string $reference): string { - $endpoint = $this->api_url . '/api/download'; + $endpoint = $this->api_url.'/api/download'; $curl = new Curl($endpoint, authorization: $this->access_key); $response = $curl->exec(true); if (!$curl->isResponseSuccessful()) { - throw new SwarmException('Failed to connect to HejBit: ' . $response['message']); + throw new SwarmException('Failed to connect to HejBit: '.$response['message']); } - return $response['url'] . DIRECTORY_SEPARATOR . $reference; + return $response['url'].DIRECTORY_SEPARATOR.$reference; } /** - * @param string $path - * @param string $tempFile - * @param string $mimetype - * @return string - * @throws SwarmException|CurlException + * @throws CurlException|SwarmException */ private function uploadSwarm(string $path, string $tempFile, string $mimetype): string { if ($this->isVersion(self::INFRASTRUCTURE_VERSION_GATEWAY)) { @@ -127,16 +121,16 @@ private function uploadSwarm(string $path, string $tempFile, string $mimetype): $response = $curl->exec(true); if (!$curl->isResponseSuccessful() || !isset($response['reference'])) { - throw new SwarmException('Failed to upload file to Swarm: ' . $response['message']); + throw new SwarmException('Failed to upload file to Swarm: '.$response['message']); } return $response['reference']; } /** - * @param string $reference * @return resource - * @throws SwarmException|CurlException + * + * @throws CurlException|SwarmException */ private function downloadSwarm(string $reference) { if ($this->isVersion(self::INFRASTRUCTURE_VERSION_GATEWAY)) { @@ -147,55 +141,43 @@ private function downloadSwarm(string $reference) { $response = $curl->exec(); if (!$curl->isResponseSuccessful()) { - throw new SwarmException('Failed to download file from Swarm: ' . $response['message']); + throw new SwarmException('Failed to download file from Swarm: '.$response['message']); } $stream = fopen('php://memory', 'r+'); fwrite($stream, $response); rewind($stream); + return $stream; } /** - * Returns the connection status of Swarm node + * Returns the connection status of Swarm node. * - * @return bool - * @throws SwarmException|CurlException + * @throws CurlException|SwarmException */ private function checkConnection(): bool { if ($this->isVersion(self::INFRASTRUCTURE_VERSION_GATEWAY)) { return $this->checkConnectionV1(); } - $endpoint = $this->api_url . '/api/readiness'; + $endpoint = $this->api_url.'/api/readiness'; $curl = new Curl($endpoint, authorization: $this->access_key); $response = $curl->exec(true); if (!$curl->isResponseSuccessful() and !isset($response['status'])) { - throw new SwarmException('Failed to connect to HejBit: ' . $response['message']); + throw new SwarmException('Failed to connect to HejBit: '.$response['message']); } - return $response['status'] === 'ok'; - } - /** - * @param int $version - * @return bool - */ - public function isVersion(int $version = self::INFRASTRUCTURE_VERSION_GATEWAY): bool { - return match ($version) { - self::INFRASTRUCTURE_VERSION_GATEWAY => $this->api_url === 'https://license.hejbit.com', - self::INFRASTRUCTURE_VERSION_HEJBIT => $this->api_url !== 'https://license.hejbit.com', - default => false, - }; + return 'ok' === $response['status']; } /** - * @return bool * @throws CurlException */ private function checkConnectionV1(): bool { - $endpoint = $this->api_url . DIRECTORY_SEPARATOR . 'readiness'; + $endpoint = $this->api_url.DIRECTORY_SEPARATOR.'readiness'; $curl = new Curl($endpoint); $curl->setAuthorization($this->access_key, CURLAUTH_ANY); @@ -203,16 +185,16 @@ private function checkConnectionV1(): bool { $output = $curl->exec(); $httpCode = $curl->getInfo(CURLINFO_HTTP_CODE); - return $httpCode === 200 and $output === 'OK'; + return 200 === $httpCode and 'OK' === $output; } /** - * @param string $reference * @return resource + * * @throws CurlException|SwarmException */ private function downloadSwarmV1(string $reference) { - $endpoint = $this->api_url . DIRECTORY_SEPARATOR . 'bzz' . DIRECTORY_SEPARATOR . $reference . DIRECTORY_SEPARATOR; + $endpoint = $this->api_url.DIRECTORY_SEPARATOR.'bzz'.DIRECTORY_SEPARATOR.$reference.DIRECTORY_SEPARATOR; $curl = new Curl($endpoint, [ CURLOPT_FOLLOWLOCATION => true, @@ -226,36 +208,33 @@ private function downloadSwarmV1(string $reference) { $response = $curl->exec(); $httpCode = $curl->getInfo(CURLINFO_HTTP_CODE); - if ($httpCode !== 200) { + if (200 !== $httpCode) { throw new SwarmException('Failed to download file from Swarm'); } $stream = fopen('php://memory', 'r+'); fwrite($stream, $response); rewind($stream); + return $stream; } /** - * @param string $path - * @param string $tempFile - * @param string $mimetype - * @return array|string * @throws CurlException|SwarmException */ private function uploadSwarmV1(string $path, string $tempFile, string $mimetype): array|string { - $endpoint = $this->api_url . DIRECTORY_SEPARATOR . 'bzz'; - $params = '?name=' . urlencode(basename($path)); + $endpoint = $this->api_url.DIRECTORY_SEPARATOR.'bzz'; + $params = '?name='.urlencode(basename($path)); - $curl = new Curl($endpoint . $params, [ + $curl = new Curl($endpoint.$params, [ CURLOPT_PUT => true, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POST => true, CURLOPT_INFILE => fopen($tempFile, 'r'), CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_VERBOSE => true + CURLOPT_VERBOSE => true, ], [ - 'content-type: ' . $mimetype, + 'content-type: '.$mimetype, 'swarm-pin: true', 'swarm-redundancy-level: 2', ]); @@ -265,8 +244,9 @@ private function uploadSwarmV1(string $path, string $tempFile, string $mimetype) $reference = (isset($result['reference']) ? $result['reference'] : null); if (!isset($reference)) { - throw new SwarmException('Failed to upload file to ' . $this->id . ': ' . $result['message']); + throw new SwarmException('Failed to upload file to '.$this->id.': '.$result['message']); } + return $reference; } } diff --git a/lib/Utils/Curl.php b/lib/Utils/Curl.php index 246ea95..c8d62b5 100644 --- a/lib/Utils/Curl.php +++ b/lib/Utils/Curl.php @@ -21,12 +21,6 @@ class Curl { protected ?string $authorization = null; protected int $authorizationType = CURLAUTH_NONE; - /** - * @param string $url - * @param array $options - * @param array $headers - * @param string|null $authorization - */ public function __construct(string $url, array $options = [], array $headers = [], ?string $authorization = null) { $this->url = $url; $this->options = $options + self::getDefaultOptions(); @@ -37,8 +31,49 @@ public function __construct(string $url, array $options = [], array $headers = [ } /** - * @return array + * set authorization. */ + public function setAuthorization(?string $authorization, int $authorizationType = CURLAUTH_BEARER): void { + $this->authorization = $authorization; + if (!$authorization) { + $this->authorizationType = CURLAUTH_NONE; + } else { + $this->authorizationType = $authorizationType; + } + } + + /** + * execute curl request. + * + * @throws CurlException + */ + public function exec(bool $array = false): array|string { + $this->setOptions(); + $this->setHeaders(); + $response = curl_exec($this->handler); + $this->checkResponse(); + + return $array ? json_decode($response, true) : $response; + } + + /** + * get curl info. + */ + public function getInfo(?int $option = null): mixed { + return curl_getinfo($this->handler, $option); + } + + /** + * @throws CurlException + */ + public function isResponseSuccessful(): bool { + if (0 === $this->getInfo(CURLINFO_HTTP_CODE)) { + throw new CurlException('Curl handler has not been executed'); + } + + return 200 === $this->getInfo(CURLINFO_HTTP_CODE) || 201 === $this->getInfo(CURLINFO_HTTP_CODE); + } + private static function getDefaultOptions(): array { return self::checkSSLOption() + self::DEFAULT_OPTIONS; } @@ -54,8 +89,7 @@ private static function checkSSLOption(): array { } /** - * initializes a curl handler - * @return void + * initializes a curl handler. */ private function init(): void { $this->handler = curl_init(); @@ -63,94 +97,34 @@ private function init(): void { } /** - * set curl options - * - * @param array $options - * @return void + * set curl options. */ private function setOptions(array $options = []): void { $options = self::getDefaultOptions() + $this->options + $options; curl_setopt_array($this->handler, $options); } - /** - * @param array $headers - * @return void - */ private function setHeaders(array $headers = []): void { $headers = $this->headers + $headers; if ($this->authorization) { $headers[] = match ($this->authorizationType) { - CURLAUTH_BEARER => 'Authorization: Bearer ' . $this->authorization, - default => 'Authorization: ' . $this->authorization + CURLAUTH_BEARER => 'Authorization: Bearer '.$this->authorization, + default => 'Authorization: '.$this->authorization }; } curl_setopt($this->handler, CURLOPT_HTTPHEADER, $headers); } /** - * set authorization + * check response results for error. * - * @param string|null $authorization - * @param int $authorizationType - * @return void - */ - public function setAuthorization(?string $authorization, int $authorizationType = CURLAUTH_BEARER): void { - $this->authorization = $authorization; - if (!$authorization) { - $this->authorizationType = CURLAUTH_NONE; - } else { - $this->authorizationType = $authorizationType; - } - } - - /** - * execute curl request - * - * @param bool $array - * @return string|array - * @throws CurlException - */ - public function exec(bool $array = false): string|array { - $this->setOptions(); - $this->setHeaders(); - $response = curl_exec($this->handler); - $this->checkResponse(); - return $array ? json_decode($response, true) : $response; - } - - /** - * get curl info - * - * @param int|null $option - * @return mixed - */ - public function getInfo(?int $option = null): mixed { - return curl_getinfo($this->handler, $option); - } - - /** - * check response results for error - * - * @return void * @throws CurlException */ private function checkResponse(): void { - if (curl_errno($this->handler) !== 0) { + if (0 !== curl_errno($this->handler)) { curl_close($this->handler); - throw new CurlException(curl_error($this->handler)); - } - } - /** - * @return bool - * @throws CurlException - */ - public function isResponseSuccessful(): bool { - if ($this->getInfo(CURLINFO_HTTP_CODE) === 0) { - throw new CurlException('Curl handler has not been executed'); + throw new CurlException(curl_error($this->handler)); } - - return $this->getInfo(CURLINFO_HTTP_CODE) === 200 || $this->getInfo(CURLINFO_HTTP_CODE) === 201; } } diff --git a/lib/Utils/Env.php b/lib/Utils/Env.php index 95b6945..c1160b6 100644 --- a/lib/Utils/Env.php +++ b/lib/Utils/Env.php @@ -3,27 +3,15 @@ namespace OCA\Files_External_Ethswarm\Utils; class Env { - /** - * @param string $name - * @return string - */ public static function get(string $name): string { return getenv($name); } - /** - * @param string $name - * @param string $value - * @return bool - */ public static function set(string $name, string $value): bool { - return putenv($name . '=' . $value); + return putenv($name.'='.$value); } - /** - * @return bool - */ public static function isDevelopment(): bool { - return self::get('ENV') === 'development'; + return 'development' === self::get('ENV'); } } diff --git a/templates/admin-settings.php b/templates/admin-settings.php index feb5077..826ec31 100644 --- a/templates/admin-settings.php +++ b/templates/admin-settings.php @@ -1,9 +1,7 @@ - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -18,14 +16,13 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ style('files_external_ethswarm', 'settings-admin'); script('files_external_ethswarm', 'settings'); ?>

t('External Storage: Swarm')); ?>

- +

t('View the current status of the Swarm node(s) configured in \'External Storage\' section of NextCloud.')); ?>

- - + +
diff --git a/templates/vue-admin-settings.php b/templates/vue-admin-settings.php index dc752dd..73a1fe7 100644 --- a/templates/vue-admin-settings.php +++ b/templates/vue-admin-settings.php @@ -1,11 +1,9 @@ - * * @author Henry Bergström - * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -20,7 +18,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * */ ?> From f7178442d77c0415406f3d7b4c9cabebeb06d137 Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 13:26:28 +0800 Subject: [PATCH 10/14] refactor(file): find_exists return value --- lib/Storage/BeeSwarm.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/Storage/BeeSwarm.php b/lib/Storage/BeeSwarm.php index cb437e8..37036b7 100755 --- a/lib/Storage/BeeSwarm.php +++ b/lib/Storage/BeeSwarm.php @@ -265,12 +265,7 @@ public function file_exists($path): bool { // Return true always the creation of the root folder return true; } - $exists = $this->fileMapper->findExists($path, $this->storageId); - if (0 == $exists) { - return false; - } - - return true; + return $this->fileMapper->findExists($path, $this->storageId) > 0; } public function filemtime($path): int { From 70f4048b834d818472b7ed6da491c1996b7670b7 Mon Sep 17 00:00:00 2001 From: mahiarirani Date: Sat, 28 Dec 2024 05:27:05 +0000 Subject: [PATCH 11/14] chore: fix code style --- lib/Storage/BeeSwarm.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Storage/BeeSwarm.php b/lib/Storage/BeeSwarm.php index 37036b7..3f8d45a 100755 --- a/lib/Storage/BeeSwarm.php +++ b/lib/Storage/BeeSwarm.php @@ -265,6 +265,7 @@ public function file_exists($path): bool { // Return true always the creation of the root folder return true; } + return $this->fileMapper->findExists($path, $this->storageId) > 0; } From deca719753affa5738283e86cc1e0ad66c9f04ea Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 13:34:02 +0800 Subject: [PATCH 12/14] refactor(swarm): ref check and param arg type --- lib/Storage/BeeSwarmTrait.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Storage/BeeSwarmTrait.php b/lib/Storage/BeeSwarmTrait.php index 30a33d5..c8b5b72 100755 --- a/lib/Storage/BeeSwarmTrait.php +++ b/lib/Storage/BeeSwarmTrait.php @@ -46,11 +46,9 @@ public function isVersion(int $version = self::INFRASTRUCTURE_VERSION_GATEWAY): } /** - * @param mixed $params - * * @throws StorageBadConfigException */ - protected function parseParams($params): void { + protected function parseParams(array $params): void { $this->validateParams($params); $this->api_url = $params[BeeSwarm::OPTION_HOST_URL]; @@ -241,7 +239,7 @@ private function uploadSwarmV1(string $path, string $tempFile, string $mimetype) $curl->setAuthorization($this->access_key, CURLAUTH_ANY); $result = $curl->exec(true); - $reference = (isset($result['reference']) ? $result['reference'] : null); + $reference = ($result['reference'] ?? null); if (!isset($reference)) { throw new SwarmException('Failed to upload file to '.$this->id.': '.$result['message']); From aa9299dac8e65b173e231351fe2e3081e3bc1a0b Mon Sep 17 00:00:00 2001 From: Mahyar Iranibazaz Date: Sat, 28 Dec 2024 13:37:54 +0800 Subject: [PATCH 13/14] refactor(swarm): param arg type --- lib/Storage/BeeSwarm.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Storage/BeeSwarm.php b/lib/Storage/BeeSwarm.php index 3f8d45a..dd35cee 100755 --- a/lib/Storage/BeeSwarm.php +++ b/lib/Storage/BeeSwarm.php @@ -81,8 +81,6 @@ class BeeSwarm extends Common { private LoggerInterface $logger; /** - * @param mixed $params - * * @throws StorageBadConfigException */ public function __construct($params) { From 28f7f5e5ea270cafaf9ac112876191351fca5d2b Mon Sep 17 00:00:00 2001 From: mahiarirani Date: Sat, 28 Dec 2024 05:38:20 +0000 Subject: [PATCH 14/14] chore: fix code style --- lib/Storage/BeeSwarm.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Storage/BeeSwarm.php b/lib/Storage/BeeSwarm.php index dd35cee..3f8d45a 100755 --- a/lib/Storage/BeeSwarm.php +++ b/lib/Storage/BeeSwarm.php @@ -81,6 +81,8 @@ class BeeSwarm extends Common { private LoggerInterface $logger; /** + * @param mixed $params + * * @throws StorageBadConfigException */ public function __construct($params) {