diff --git a/.github/workflows/lint-php.yml b/.github/workflows/lint-php.yml index a4abc44f..d8694efd 100644 --- a/.github/workflows/lint-php.yml +++ b/.github/workflows/lint-php.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ["7.4", "8.0"] + php-versions: ["7.4", "8.0", "8.1"] name: php-lint diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 00000000..8fa3c9ec --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,26 @@ +name: Static analysis + +on: [pull_request] + +jobs: + static-psalm-analysis: + runs-on: ubuntu-latest + strategy: + matrix: + ocp-version: [ 'dev-master' ] + name: Nextcloud ${{ matrix.ocp-version }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up php + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + tools: composer:v1 + coverage: none + - name: Install dependencies + run: composer i + - name: Install dependencies + run: composer require --dev christophwurst/nextcloud:${{ matrix.ocp-version }} + - name: Run coding standards check + run: composer run psalm diff --git a/composer.json b/composer.json index 2878cd18..005bb7c9 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,6 @@ "friendica/json-ld": "^1.0" }, "require-dev": { - "jakub-onderka/php-parallel-lint": "^1.0", - "rector/rector": "^0.12.20", "phpunit/phpunit": "^9.5", "nextcloud/coding-standard": "^1.0.0", "christophwurst/nextcloud": "dev-master", @@ -39,7 +37,7 @@ "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l", "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", - "psalm": "psalm --threads=1", + "psalm": "psalm --threads=1 --update-baseline", "psalm:update-baseline": "psalm --threads=1 --update-baseline", "psalm:clear": "psalm --clear-cache && psalm --clear-global-cache", "psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType" diff --git a/composer.lock b/composer.lock index 6ae40e1b..7de17866 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "303af33a7156caaf44b7a28ce25c7755", + "content-hash": "c9f825ade4c2baa82438409e058171bc", "packages": [ { "name": "daita/my-small-php-tools", @@ -1097,59 +1097,6 @@ ], "time": "2022-03-18T17:20:59+00:00" }, - { - "name": "jakub-onderka/php-parallel-lint", - "version": "v1.0.0", - "source": { - "type": "git", - "url": "https://github.com/JakubOnderka/PHP-Parallel-Lint.git", - "reference": "04fbd3f5fb1c83f08724aa58a23db90bd9086ee8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/JakubOnderka/PHP-Parallel-Lint/zipball/04fbd3f5fb1c83f08724aa58a23db90bd9086ee8", - "reference": "04fbd3f5fb1c83f08724aa58a23db90bd9086ee8", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "jakub-onderka/php-console-highlighter": "~0.3", - "nette/tester": "~1.3", - "squizlabs/php_codesniffer": "~2.7" - }, - "suggest": { - "jakub-onderka/php-console-highlighter": "Highlight syntax in code snippet" - }, - "bin": [ - "parallel-lint" - ], - "type": "library", - "autoload": { - "classmap": [ - "./" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "authors": [ - { - "name": "Jakub Onderka", - "email": "ahoj@jakubonderka.cz" - } - ], - "description": "This tool check syntax of PHP files about 20x faster than serial check.", - "homepage": "https://github.com/JakubOnderka/PHP-Parallel-Lint", - "support": { - "issues": "https://github.com/JakubOnderka/PHP-Parallel-Lint/issues", - "source": "https://github.com/JakubOnderka/PHP-Parallel-Lint/tree/master" - }, - "abandoned": "php-parallel-lint/php-parallel-lint", - "time": "2018-02-24T15:31:20+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.11.0", @@ -1800,65 +1747,6 @@ }, "time": "2021-12-08T12:19:24+00:00" }, - { - "name": "phpstan/phpstan", - "version": "1.5.5", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "d77a607667f29ae099c0686f99664bd451fd23df" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d77a607667f29ae099c0686f99664bd451fd23df", - "reference": "d77a607667f29ae099c0686f99664bd451fd23df", - "shasum": "" - }, - "require": { - "php": "^7.2|^8.0" - }, - "conflict": { - "phpstan/phpstan-shim": "*" - }, - "bin": [ - "phpstan", - "phpstan.phar" - ], - "type": "library", - "autoload": { - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPStan - PHP Static Analysis Tool", - "support": { - "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.5.5" - }, - "funding": [ - { - "url": "https://github.com/ondrejmirtes", - "type": "github" - }, - { - "url": "https://github.com/phpstan", - "type": "github" - }, - { - "url": "https://www.patreon.com/phpstan", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" - } - ], - "time": "2022-04-14T12:20:26+00:00" - }, { "name": "phpunit/php-code-coverage", "version": "9.2.15", @@ -2477,66 +2365,6 @@ }, "time": "2021-05-03T11:20:27+00:00" }, - { - "name": "rector/rector", - "version": "0.12.20", - "source": { - "type": "git", - "url": "https://github.com/rectorphp/rector.git", - "reference": "cfa8d3e236a6e1a41d69712a84d434dfdf70e560" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/cfa8d3e236a6e1a41d69712a84d434dfdf70e560", - "reference": "cfa8d3e236a6e1a41d69712a84d434dfdf70e560", - "shasum": "" - }, - "require": { - "php": "^7.2|^8.0", - "phpstan/phpstan": "^1.5" - }, - "conflict": { - "phpstan/phpdoc-parser": "<1.2", - "rector/rector-cakephp": "*", - "rector/rector-doctrine": "*", - "rector/rector-laravel": "*", - "rector/rector-nette": "*", - "rector/rector-phpoffice": "*", - "rector/rector-phpunit": "*", - "rector/rector-prefixed": "*", - "rector/rector-symfony": "*" - }, - "bin": [ - "bin/rector" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "0.12-dev" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Instant Upgrade and Automated Refactoring of any PHP code", - "support": { - "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.12.20" - }, - "funding": [ - { - "url": "https://github.com/tomasvotruba", - "type": "github" - } - ], - "time": "2022-04-06T12:55:14+00:00" - }, { "name": "sebastian/cli-parser", "version": "1.0.1", diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f3933bd8..664798c0 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -32,7 +32,6 @@ declare(strict_types=1); namespace OCA\Social\AppInfo; use Closure; -use OC\DB\SchemaWrapper; use OCA\Social\Notification\Notifier; use OCA\Social\Search\UnifiedSearchProvider; use OCA\Social\Service\ConfigService; @@ -45,6 +44,8 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\QueryException; use OCP\IDBConnection; use OCP\IServerContainer; +use OC\DB\SchemaWrapper; +use OCP\DB\ISchemaWrapper; use Throwable; require_once __DIR__ . '/../../vendor/autoload.php'; @@ -106,6 +107,7 @@ class Application extends App implements IBootstrap { return; } + /** @var ISchemaWrapper $schema */ $schema = new SchemaWrapper($container->get(IDBConnection::class)); if ($schema->hasTable('social_a2_stream')) { $updateService->checkUpdateStatus(); diff --git a/lib/Command/CheckInstall.php b/lib/Command/CheckInstall.php index 8a312079..575a6fa4 100644 --- a/lib/Command/CheckInstall.php +++ b/lib/Command/CheckInstall.php @@ -175,7 +175,7 @@ class CheckInstall extends Base { return true; } - private function regenerateIndex(OutputInterface $output) { + private function regenerateIndex(OutputInterface $output): void { $streams = $this->streamRequest->getAll(); $progressBar = new ProgressBar($output, count($streams)); $progressBar->start(); diff --git a/lib/Command/NoteBoost.php b/lib/Command/NoteBoost.php index f68587e8..91c83983 100644 --- a/lib/Command/NoteBoost.php +++ b/lib/Command/NoteBoost.php @@ -49,22 +49,10 @@ use Symfony\Component\Console\Output\OutputInterface; */ class NoteBoost extends Base { private StreamService $streamService; - private AccountService $accountService; - private BoostService $boostService; - private MiscService $miscService; - - /** - * NoteBoost constructor. - * - * @param AccountService $accountService - * @param StreamService $streamService - * @param BoostService $boostService - * @param MiscService $miscService - */ public function __construct( AccountService $accountService, StreamService $streamService, BoostService $boostService, MiscService $miscService @@ -104,6 +92,7 @@ class NoteBoost extends Base { $actor = $this->accountService->getActorFromUserId($userId); $this->streamService->setViewer($actor); + $token = ''; if (!$input->getOption('unboost')) { $activity = $this->boostService->create($actor, $noteId, $token); } else { diff --git a/lib/Command/NoteCreate.php b/lib/Command/NoteCreate.php index d167e726..f719a2cc 100644 --- a/lib/Command/NoteCreate.php +++ b/lib/Command/NoteCreate.php @@ -137,6 +137,7 @@ class NoteCreate extends Base { $post->addTo(($to === null) ? '' : $to); $post->setHashtags(($hashtag === null) ? [] : [$hashtag]); + $token = ''; $activity = $this->postService->createPost($post, $token); echo 'object: ' . json_encode($activity, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"; diff --git a/lib/Command/NoteLike.php b/lib/Command/NoteLike.php index 3e4d46a5..63364298 100644 --- a/lib/Command/NoteLike.php +++ b/lib/Command/NoteLike.php @@ -104,6 +104,7 @@ class NoteLike extends Base { $actor = $this->accountService->getActorFromUserId($userId); $this->streamService->setViewer($actor); + $token = ''; if (!$input->getOption('unlike')) { $activity = $this->likeService->create($actor, $noteId, $token); } else { diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index 36c62725..0311eebf 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -125,6 +125,7 @@ class LocalController extends Controller { $post->setHashtags($this->getArray('hashtags', $data, [])); $post->setAttachments($this->getArray('attachments', $data, [])); + $token = ''; $activity = $this->postService->createPost($post, $token); return $this->success( @@ -209,6 +210,7 @@ class LocalController extends Controller { public function postBoost(string $postId): DataResponse { try { $this->initViewer(true); + $token = ''; $announce = $this->boostService->create($this->viewer, $postId, $token); return $this->success( @@ -231,6 +233,7 @@ class LocalController extends Controller { public function postUnboost(string $postId): DataResponse { try { $this->initViewer(true); + $token = ''; $announce = $this->boostService->delete($this->viewer, $postId, $token); return $this->success( @@ -253,6 +256,7 @@ class LocalController extends Controller { public function postLike(string $postId): DataResponse { try { $this->initViewer(true); + $token = ''; $announce = $this->likeService->create($this->viewer, $postId, $token); return $this->success( @@ -275,6 +279,7 @@ class LocalController extends Controller { public function postUnlike(string $postId): DataResponse { try { $this->initViewer(true); + $token = ''; $like = $this->likeService->delete($this->viewer, $postId, $token); return $this->success( diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index 05b06fbb..0f95c0bf 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -74,6 +74,7 @@ class NavigationController extends Controller { private MiscService $miscService; private IL10N $l10n; private CheckService $checkService; + private IInitialStateService $initialStateService; public function __construct( IL10N $l10n, diff --git a/lib/Controller/OAuthController.php b/lib/Controller/OAuthController.php index c7f63772..9ffda8fa 100644 --- a/lib/Controller/OAuthController.php +++ b/lib/Controller/OAuthController.php @@ -140,10 +140,11 @@ class OAuthController extends Controller { /** * @NoCSRFRequired * @PublicPage + * @param array|string $redirect_uris * @throws ClientException */ public function apps( - string $client_name = '', string $redirect_uris = '', string $website = '', string $scopes = 'read' + string $client_name = '', $redirect_uris = '', string $website = '', string $scopes = 'read' ): DataResponse { // TODO: manage array from request if (!is_array($redirect_uris)) { diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php index cf9a5c6d..1495689c 100644 --- a/lib/Controller/SocialPubController.php +++ b/lib/Controller/SocialPubController.php @@ -67,6 +67,7 @@ class SocialPubController extends Controller { private CacheActorService $cacheActorService; private StreamService $streamService; private ConfigService $configService; + private IInitialStateService $initialStateService; public function __construct( ?string $userId, IInitialStateService $initialStateService, IRequest $request, IL10N $l10n, NavigationController $navigationController, diff --git a/lib/Cron/Cache.php b/lib/Cron/Cache.php index 7958510c..2a5aacab 100644 --- a/lib/Cron/Cache.php +++ b/lib/Cron/Cache.php @@ -32,7 +32,7 @@ declare(strict_types=1); namespace OCA\Social\Cron; use Exception; -use OC\AppFramework\Utility\TimeFactory; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; use OCA\Social\AppInfo\Application; use OCA\Social\Service\AccountService; @@ -52,7 +52,7 @@ class Cache extends TimedJob { private ?DocumentService $documentService = null; private ?HashtagService $hashtagService = null; - public function __construct(TimeFactory $time) { + public function __construct(ITimeFactory $time) { parent::__construct($time); $this->setInterval(12 * 60); // 12 minutes } diff --git a/lib/Cron/Chunk.php b/lib/Cron/Chunk.php index 4d635fca..9631c897 100644 --- a/lib/Cron/Chunk.php +++ b/lib/Cron/Chunk.php @@ -31,11 +31,10 @@ declare(strict_types=1); namespace OCA\Social\Cron; -use OC\AppFramework\Utility\TimeFactory; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; use OCA\Social\AppInfo\Application; use OCA\Social\Service\ConfigService; -use OCA\Social\Service\MiscService; use OCP\AppFramework\QueryException; /** @@ -46,7 +45,7 @@ use OCP\AppFramework\QueryException; class Chunk extends TimedJob { private ?ConfigService $configService = null; - public function __construct(TimeFactory $time) { + public function __construct(ITimeFactory $time) { parent::__construct($time); $this->setInterval(12 * 3600); // 12 hours } @@ -62,7 +61,6 @@ class Chunk extends TimedJob { $c = $app->getContainer(); $this->configService = $c->query(ConfigService::class); - $this->miscService = $c->query(MiscService::class); $size = (int)$this->configService->getAppValue(ConfigService::DATABASE_CHUNK_SIZE); $this->morphChunks($size); diff --git a/lib/Cron/Queue.php b/lib/Cron/Queue.php index 449b4a4e..9c516974 100644 --- a/lib/Cron/Queue.php +++ b/lib/Cron/Queue.php @@ -31,12 +31,11 @@ declare(strict_types=1); namespace OCA\Social\Cron; -use OC\AppFramework\Utility\TimeFactory; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; use OCA\Social\AppInfo\Application; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Service\ActivityService; -use OCA\Social\Service\MiscService; use OCA\Social\Service\RequestQueueService; use OCA\Social\Service\StreamQueueService; use OCP\AppFramework\QueryException; @@ -51,11 +50,10 @@ class Queue extends TimedJob { private ?RequestQueueService $requestQueueService = null; private ?StreamQueueService $streamQueueService = null; - /** * Cache constructor. */ - public function __construct(TimeFactory $time) { + public function __construct(ITimeFactory $time) { parent::__construct($time); $this->setInterval(12 * 60); // 12 minutes } @@ -74,7 +72,6 @@ class Queue extends TimedJob { $this->requestQueueService = $c->get(RequestQueueService::class); $this->streamQueueService = $c->get(StreamQueueService::class); $this->activityService = $c->get(ActivityService::class); - $this->miscService = $c->get(MiscService::class); $this->manageRequestQueue(); $this->manageStreamQueue(); diff --git a/lib/Db/ActionsRequest.php b/lib/Db/ActionsRequest.php index ca7ed694..59ef8f4c 100644 --- a/lib/Db/ActionsRequest.php +++ b/lib/Db/ActionsRequest.php @@ -69,7 +69,7 @@ class ActionsRequest extends ActionsRequestBuilder { $this->generatePrimaryKey($qb, $like->getId()); - $qb->execute(); + $qb->executeStatement(); } diff --git a/lib/Db/ActionsRequestBuilder.php b/lib/Db/ActionsRequestBuilder.php index 144077c3..39d60bdc 100644 --- a/lib/Db/ActionsRequestBuilder.php +++ b/lib/Db/ActionsRequestBuilder.php @@ -118,8 +118,8 @@ class ActionsRequestBuilder extends CoreRequestBuilder { * @throws ActionDoesNotExistException */ protected function getActionFromRequest(SocialQueryBuilder $qb): ACore { - /** @var ACore $result */ try { + /** @var ACore $result */ $result = $qb->getRow([$this, 'parseActionsSelectSql']); } catch (RowNotFoundException $e) { throw new ActionDoesNotExistException($e->getMessage()); diff --git a/lib/Db/CacheActorsRequest.php b/lib/Db/CacheActorsRequest.php index 490beff4..35f65c19 100644 --- a/lib/Db/CacheActorsRequest.php +++ b/lib/Db/CacheActorsRequest.php @@ -31,22 +31,20 @@ declare(strict_types=1); namespace OCA\Social\Db; use DateTime; -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Exception; use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Model\ActivityPub\Actor\Person; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\DB\Exception as DBException; class CacheActorsRequest extends CacheActorsRequestBuilder { public const CACHE_TTL = 60 * 24; // 1d /** - * insert cache about an Actor in database. - * - * @param Person $actor + * Insert cache about an Actor in database. */ - public function save(Person $actor) { + public function save(Person $actor): void { $qb = $this->getCacheActorsInsertSql(); $qb->setValue('id', $qb->createNamedParameter($actor->getId())) ->setValue('id_prim', $qb->createNamedParameter($this->prim($actor->getId()))) @@ -95,18 +93,14 @@ class CacheActorsRequest extends CacheActorsRequestBuilder { $qb->generatePrimaryKey($actor->getId()); try { - $qb->execute(); - } catch (UniqueConstraintViolationException $e) { + $qb->executeStatement(); + } catch (DBException $e) { } } /** - * insert cache about an Actor in database. - * - * @param Person $actor - * - * @return int + * Insert cache about an Actor in database. */ public function update(Person $actor): int { $qb = $this->getCacheActorsUpdateSql(); @@ -151,7 +145,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder { $this->limitToIdString($qb, $actor->getId()); - return $qb->execute(); + return $qb->executeStatement(); } @@ -202,6 +196,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder { $qb = $this->getCacheActorsSelectSql(); $this->limitToPreferredUsername($qb, $account); $this->limitToLocal($qb, true); + /** @var SocialQueryBuilder $qb */ $qb->leftJoinCacheDocuments('icon_id'); $this->leftJoinDetails($qb); @@ -217,6 +212,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder { public function searchAccounts(string $search): array { $qb = $this->getCacheActorsSelectSql(); $this->searchInAccount($qb, $search); + /** @var SocialQueryBuilder $qb */ $qb->leftJoinCacheDocuments('icon_id'); $this->leftJoinDetails($qb); $this->limitResults($qb, 25); diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index b284d490..f4ffd2cd 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -38,6 +38,7 @@ use Doctrine\DBAL\Query\QueryBuilder; use Exception; use OC; use OC\DB\SchemaWrapper; +use OCP\DB\ISchemaWrapper; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Object\Follow; @@ -109,7 +110,6 @@ class CoreRequestBuilder { ) { $this->dbConnection = $connection; $this->logger = $logger; - $this->loggerInterface = $logger; $this->urlGenerator = $urlGenerator; $this->configService = $configService; $this->miscService = $miscService; @@ -122,7 +122,7 @@ class CoreRequestBuilder { public function getQueryBuilder(): SocialQueryBuilder { $qb = new SocialQueryBuilder( $this->dbConnection, - OC::$server->getSystemConfig(), + OC::$server->get(\OC\SystemConfig::class), $this->logger, $this->urlGenerator ); @@ -729,20 +729,11 @@ class CoreRequestBuilder { } - /** - * @param IQueryBuilder $qb - * @param string $field - * @param array $values - */ - protected function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values) { + protected function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values): void { $expr = $qb->expr(); $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; $field = $pf . $field; - if (!is_array($values)) { - $values = [$values]; - } - $orX = $expr->orX(); foreach ($values as $value) { $orX->add($expr->eq($field, $qb->createNamedParameter($value))); @@ -1185,6 +1176,7 @@ class CoreRequestBuilder { * this just empty all tables from the app. */ public function uninstallSocialTables() { + /** @var ISchemaWrapper|SchemaWrapper $schema */ $schema = new SchemaWrapper($this->dbConnection); foreach ($this->tables as $table) { if ($schema->hasTable($table)) { diff --git a/lib/Db/StreamActionsRequest.php b/lib/Db/StreamActionsRequest.php index 08299bc8..37ca8a08 100644 --- a/lib/Db/StreamActionsRequest.php +++ b/lib/Db/StreamActionsRequest.php @@ -43,11 +43,9 @@ class StreamActionsRequest extends StreamActionsRequestBuilder { /** - * create a new Queue in the database. - * - * @param StreamAction $action + * Create a new Queue in the database. */ - public function create(StreamAction $action) { + public function create(StreamAction $action): void { $qb = $this->getStreamActionInsertSql(); $values = $action->getValues(); @@ -68,16 +66,12 @@ class StreamActionsRequest extends StreamActionsRequestBuilder { ->setValue('boosted', $qb->createNamedParameter(($boosted) ? 1 : 0)) ->setValue('replied', $qb->createNamedParameter(($replied) ? 1 : 0)); - $qb->execute(); + $qb->executeStatement(); } /** - * create a new Queue in the database. - * - * @param StreamAction $action - * - * @return int + * Create a new Queue in the database. */ public function update(StreamAction $action): int { $qb = $this->getStreamActionUpdateSql(); @@ -95,15 +89,11 @@ class StreamActionsRequest extends StreamActionsRequestBuilder { $this->limitToActorId($qb, $action->getActorId()); $this->limitToStreamId($qb, $action->getStreamId()); - return $qb->execute(); + return $qb->executeStatement(); } /** - * @param string $actorId - * @param string $streamId - * - * @return StreamAction * @throws StreamActionDoesNotExistException */ public function getAction(string $actorId, string $streamId): StreamAction { @@ -111,7 +101,7 @@ class StreamActionsRequest extends StreamActionsRequestBuilder { $this->limitToActorId($qb, $actorId); $this->limitToStreamId($qb, $streamId); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $data = $cursor->fetch(); if ($data === false) { throw new StreamActionDoesNotExistException(); @@ -121,15 +111,11 @@ class StreamActionsRequest extends StreamActionsRequestBuilder { return $this->parseStreamActionsSelectSql($data); } - - /** - * @param StreamAction $action - */ - public function delete(StreamAction $action) { + public function delete(StreamAction $action): void { $qb = $this->getStreamActionDeleteSql(); $this->limitToActorId($qb, $action->getActorId()); $this->limitToStreamId($qb, $action->getStreamId()); - $qb->execute(); + $qb->executeStatement(); } } diff --git a/lib/Db/StreamDestRequest.php b/lib/Db/StreamDestRequest.php index 1cc2b230..be0f318d 100644 --- a/lib/Db/StreamDestRequest.php +++ b/lib/Db/StreamDestRequest.php @@ -32,8 +32,8 @@ declare(strict_types=1); namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TStringTools; -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Exception; +use OCP\DB\Exception as DBException; use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification; use OCA\Social\Model\ActivityPub\Stream; use OCA\Social\Service\CacheActorService; @@ -71,16 +71,12 @@ class StreamDestRequest extends StreamDestRequestBuilder { $qb->setValue('subtype', $qb->createNamedParameter($subType)); try { - $qb->execute(); - } catch (UniqueConstraintViolationException $e) { + $qb->executeStatement(); + } catch (DBException $e) { } } - - /** - * @param Stream $stream - */ - public function generateStreamDest(Stream $stream) { + public function generateStreamDest(Stream $stream): void { if ($this->generateStreamNotification($stream)) { return; } @@ -92,12 +88,6 @@ class StreamDestRequest extends StreamDestRequestBuilder { $this->generateStreamHome($stream); } - - /** - * @param Stream $stream - * - * @return bool - */ private function generateStreamHome(Stream $stream): bool { $recipients = [ @@ -118,12 +108,6 @@ class StreamDestRequest extends StreamDestRequestBuilder { return true; } - - /** - * @param Stream $stream - * - * @return bool - */ private function generateStreamDirect(Stream $stream): bool { try { $author = $this->cacheActorService->getFromId($stream->getAttributedTo()); @@ -152,12 +136,6 @@ class StreamDestRequest extends StreamDestRequestBuilder { return true; } - - /** - * @param Stream $stream - * - * @return bool - */ private function generateStreamNotification(Stream $stream): bool { if ($stream->getType() !== SocialAppNotification::TYPE) { return false; @@ -174,14 +152,10 @@ class StreamDestRequest extends StreamDestRequestBuilder { return true; } - - /** - * - */ - public function emptyStreamDest() { + public function emptyStreamDest(): void { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete(self::TABLE_STREAM_DEST); - $qb->execute(); + $qb->executeStatement(); } } diff --git a/lib/Db/StreamDestRequestBuilder.php b/lib/Db/StreamDestRequestBuilder.php index 737f8b45..239f0f40 100644 --- a/lib/Db/StreamDestRequestBuilder.php +++ b/lib/Db/StreamDestRequestBuilder.php @@ -44,8 +44,6 @@ class StreamDestRequestBuilder extends CoreRequestBuilder { /** * Base of the Sql Insert request - * - * @return IQueryBuilder */ protected function getStreamDestInsertSql(): SocialQueryBuilder { $qb = $this->getQueryBuilder(); diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php index 780ff512..23834cd0 100644 --- a/lib/Db/StreamRequest.php +++ b/lib/Db/StreamRequest.php @@ -33,8 +33,8 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Exceptions\DateTimeException; use daita\MySmallPhpTools\Model\Cache; use DateTime; -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Exception; +use OCP\DB\Exception as DBException; use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\StreamNotFoundException; use OCA\Social\Model\ActivityPub\ACore; @@ -70,11 +70,7 @@ class StreamRequest extends StreamRequestBuilder { $this->streamTagsRequest = $streamTagsRequest; } - - /** - * @param Stream $stream - */ - public function save(Stream $stream) { + public function save(Stream $stream): void { $qb = $this->saveStream($stream); if ($stream->getType() === Note::TYPE) { /** @var Note $stream */ @@ -87,19 +83,15 @@ class StreamRequest extends StreamRequestBuilder { } try { - $qb->execute(); + $qb->executeStatement(); $this->streamDestRequest->generateStreamDest($stream); $this->streamTagsRequest->generateStreamTags($stream); - } catch (UniqueConstraintViolationException $e) { + } catch (DBException $e) { } } - - /** - * @param Stream $stream \ - */ - public function update(Stream $stream) { + public function update(Stream $stream): void { $qb = $this->getStreamUpdateSql(); $qb->set('details', $qb->createNamedParameter(json_encode($stream->getDetailsAll()))); @@ -109,34 +101,25 @@ class StreamRequest extends StreamRequestBuilder { ) ); $qb->limitToIdPrim($qb->prim($stream->getId())); - $qb->execute(); + $qb->executeStatement(); $this->streamDestRequest->generateStreamDest($stream); } - - /** - * @param Stream $stream - * @param Cache $cache - */ - public function updateCache(Stream $stream, Cache $cache) { + public function updateCache(Stream $stream, Cache $cache): void { $qb = $this->getStreamUpdateSql(); $qb->set('cache', $qb->createNamedParameter(json_encode($cache, JSON_UNESCAPED_SLASHES))); $qb->limitToIdPrim($qb->prim($stream->getId())); - $qb->execute(); + $qb->executeStatement(); } - - /** - * @param Document $document - */ - public function updateAttachments(Document $document) { + public function updateAttachments(Document $document): void { $qb = $this->getStreamSelectSql(); $qb->limitToIdPrim($qb->prim($document->getParentId())); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $data = $cursor->fetch(); $cursor->closeCursor(); @@ -149,13 +132,10 @@ class StreamRequest extends StreamRequestBuilder { $qb->set('attachments', $qb->createNamedParameter(json_encode($new, JSON_UNESCAPED_SLASHES))); $qb->limitToIdPrim($qb->prim($document->getParentId())); - $qb->execute(); + $qb->executeStatement(); } /** - * @param Document $document - * @param array $attachments - * * @return Document[] */ private function updateAttachmentInList(Document $document, array $attachments): array { @@ -174,18 +154,14 @@ class StreamRequest extends StreamRequestBuilder { } - /** - * @param string $itemId - * @param string $to - */ - public function updateAttributedTo(string $itemId, string $to) { + public function updateAttributedTo(string $itemId, string $to): void { $qb = $this->getStreamUpdateSql(); $qb->set('attributed_to', $qb->createNamedParameter($to)); $qb->set('attributed_to_prim', $qb->createNamedParameter($qb->prim($to))); $qb->limitToIdPrim($qb->prim($itemId)); - $qb->execute(); + $qb->executeStatement(); } diff --git a/lib/Db/StreamTagsRequest.php b/lib/Db/StreamTagsRequest.php index d69289c8..76649f0b 100644 --- a/lib/Db/StreamTagsRequest.php +++ b/lib/Db/StreamTagsRequest.php @@ -32,9 +32,9 @@ declare(strict_types=1); namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TStringTools; -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCA\Social\Model\ActivityPub\Object\Note; use OCA\Social\Model\ActivityPub\Stream; +use OCP\DB\Exception as DBException; /** * Class StreamTagsRequest @@ -44,11 +44,7 @@ use OCA\Social\Model\ActivityPub\Stream; class StreamTagsRequest extends StreamTagsRequestBuilder { use TStringTools; - - /** - * @param Stream $stream - */ - public function generateStreamTags(Stream $stream) { + public function generateStreamTags(Stream $stream): void { if ($stream->getType() !== Note::TYPE) { return; } @@ -60,22 +56,18 @@ class StreamTagsRequest extends StreamTagsRequestBuilder { $qb->setValue('stream_id', $qb->createNamedParameter($streamId)); $qb->setValue('hashtag', $qb->createNamedParameter($hashtag)); try { - $qb->execute(); - } catch (UniqueConstraintViolationException $e) { + $qb->executeStatement(); + } catch (DBException $e) { \OC::$server->getLogger() ->log(1, 'Social - Duplicate hashtag on Stream ' . json_encode($stream)); } } } - - /** - * - */ - public function emptyStreamTags() { + public function emptyStreamTags(): void { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete(self::TABLE_STREAM_TAGS); - $qb->execute(); + $qb->executeStatement(); } } diff --git a/lib/Interfaces/Actor/PersonInterface.php b/lib/Interfaces/Actor/PersonInterface.php index 7fca6a51..34e692bd 100644 --- a/lib/Interfaces/Actor/PersonInterface.php +++ b/lib/Interfaces/Actor/PersonInterface.php @@ -54,30 +54,13 @@ use OCA\Social\Service\MiscService; class PersonInterface implements IActivityPubInterface { use TArrayTools; - private CacheActorsRequest $cacheActorsRequest; - private StreamRequest $streamRequest; - private FollowsRequest $followsRequest; - private ActorService $actorService; - private ConfigService $configService; - private MiscService $miscService; - - /** - * UndoService constructor. - * - * @param CacheActorsRequest $cacheActorsRequest - * @param StreamRequest $streamRequest - * @param FollowsRequest $followsRequest - * @param ActorService $actorService - * @param ConfigService $configService - * @param MiscService $miscService - */ public function __construct( CacheActorsRequest $cacheActorsRequest, StreamRequest $streamRequest, FollowsRequest $followsRequest, ActorService $actorService, ConfigService $configService, @@ -91,25 +74,15 @@ class PersonInterface implements IActivityPubInterface { $this->miscService = $miscService; } - - /** - * @param ACore $person - */ - public function processIncomingRequest(ACore $person) { + public function processIncomingRequest(ACore $item) { } - /** - * @param ACore $item - */ public function processResult(ACore $item) { } /** - * @param ACore $item - * - * @return ACore * @throws ItemNotFoundException */ public function getItem(ACore $item): ACore { @@ -149,12 +122,9 @@ class PersonInterface implements IActivityPubInterface { } } - - /** - * @param ACore $person - */ - public function save(ACore $person) { + public function save(ACore $item) { /** @var Person $person */ + $person = $item; try { $this->getItemById($person->getId()); $this->actorService->update($person); @@ -163,17 +133,9 @@ class PersonInterface implements IActivityPubInterface { } } - - /** - * @param ACore $item - */ public function update(ACore $item) { } - - /** - * @param ACore $item - */ public function delete(ACore $item) { /** @var Person $item */ $this->cacheActorsRequest->deleteCacheById($item->getId()); @@ -181,19 +143,9 @@ class PersonInterface implements IActivityPubInterface { $this->followsRequest->deleteRelatedId($item->getId()); } - - /** - * @param ACore $item - * @param string $source - */ public function event(ACore $item, string $source) { } - - /** - * @param Person $actor - * @param ACore $activity - */ private function updateActor(Person $actor, ACore $activity) { $actor->setCreation($activity->getOriginCreationTime()); diff --git a/lib/Interfaces/Internal/SocialAppNotificationInterface.php b/lib/Interfaces/Internal/SocialAppNotificationInterface.php index ebac5936..159f862b 100644 --- a/lib/Interfaces/Internal/SocialAppNotificationInterface.php +++ b/lib/Interfaces/Internal/SocialAppNotificationInterface.php @@ -73,7 +73,7 @@ class SocialAppNotificationInterface implements IActivityPubInterface { /** * @param ACore $note */ - public function processIncomingRequest(ACore $note) { + public function processIncomingRequest(ACore $item) { } @@ -113,12 +113,9 @@ class SocialAppNotificationInterface implements IActivityPubInterface { public function activity(Acore $activity, ACore $item) { } - - /** - * @param ACore $notification - */ - public function save(ACore $notification) { + public function save(ACore $item) { /** @var SocialAppNotification $notification */ + $notification = $item; if ($notification->getId() === '') { return; } @@ -132,12 +129,9 @@ class SocialAppNotificationInterface implements IActivityPubInterface { $this->streamRequest->save($notification); } - - /** - * @param ACore $notification - */ - public function update(ACore $notification) { + public function update(ACore $item) { /** @var SocialAppNotification $notification */ + $notification = $item; $this->miscService->log( 'Updating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1 ); diff --git a/lib/Interfaces/Object/AnnounceInterface.php b/lib/Interfaces/Object/AnnounceInterface.php index 51d1ab8c..257de353 100644 --- a/lib/Interfaces/Object/AnnounceInterface.php +++ b/lib/Interfaces/Object/AnnounceInterface.php @@ -149,8 +149,9 @@ class AnnounceInterface implements IActivityPubInterface { * @throws RequestServerException * @throws UnauthorizedFediverseException */ - public function activity(Acore $activity, ACore $announce) { + public function activity(Acore $activity, ACore $item) { /** @var Announce $announce */ + $announce = $item; if ($activity->getType() === Undo::TYPE) { $activity->checkOrigin($announce->getId()); $activity->checkOrigin($announce->getActorId()); diff --git a/lib/Interfaces/Object/FollowInterface.php b/lib/Interfaces/Object/FollowInterface.php index a68259f7..5219c5fc 100644 --- a/lib/Interfaces/Object/FollowInterface.php +++ b/lib/Interfaces/Object/FollowInterface.php @@ -69,28 +69,12 @@ use OCA\Social\Service\MiscService; */ class FollowInterface implements IActivityPubInterface { private FollowsRequest $followsRequest; - private CacheActorService $cacheActorService; - private AccountService $accountService; - private ActivityService $activityService; - private ConfigService $configService; - private MiscService $miscService; - - /** - * NoteInterface constructor. - * - * @param FollowsRequest $followsRequest - * @param CacheActorService $cacheActorService - * @param AccountService $accountService - * @param ActivityService $activityService - * @param ConfigService $configService - * @param MiscService $miscService - */ public function __construct( FollowsRequest $followsRequest, CacheActorService $cacheActorService, AccountService $accountService, ActivityService $activityService, @@ -104,17 +88,9 @@ class FollowInterface implements IActivityPubInterface { $this->miscService = $miscService; } - - /** - * @param ACore $item - */ public function processResult(ACore $item) { } - - /** - * @param Follow $follow - */ public function confirmFollowRequest(Follow $follow) { try { $remoteActor = $this->cacheActorService->getFromId($follow->getActorId()); @@ -165,8 +141,9 @@ class FollowInterface implements IActivityPubInterface { * @throws RequestResultNotJsonException * @throws Exception */ - public function processIncomingRequest(ACore $follow) { + public function processIncomingRequest(ACore $item) { /** @var Follow $follow */ + $follow = $item; $follow->checkOrigin($follow->getActorId()); try { diff --git a/lib/Interfaces/Object/LikeInterface.php b/lib/Interfaces/Object/LikeInterface.php index 8f81d529..1010d18c 100644 --- a/lib/Interfaces/Object/LikeInterface.php +++ b/lib/Interfaces/Object/LikeInterface.php @@ -88,12 +88,13 @@ class LikeInterface implements IActivityPubInterface { /** - * @param ACore $like + * @param ACore $item * * @throws InvalidOriginException */ - public function processIncomingRequest(ACore $like) { + public function processIncomingRequest(ACore $item) { /** @var Like $like */ + $like = $item; $like->checkOrigin($like->getId()); $like->checkOrigin($like->getActorId()); @@ -110,8 +111,9 @@ class LikeInterface implements IActivityPubInterface { * * @throws InvalidOriginException */ - public function activity(ACore $activity, ACore $like) { + public function activity(ACore $activity, ACore $item) { /** @var Like $like */ + $like = $item; if ($activity->getType() === Undo::TYPE) { $activity->checkOrigin($like->getId()); $activity->checkOrigin($like->getActorId()); @@ -212,7 +214,9 @@ class LikeInterface implements IActivityPubInterface { /** * @param ACore $like */ - private function undoLikeAction(ACore $like) { + private function undoLikeAction(ACore $item) { + /** @var Like $like */ + $like = $item; try { if ($like->hasActor()) { $actor = $like->getActor(); diff --git a/lib/Interfaces/Object/NoteInterface.php b/lib/Interfaces/Object/NoteInterface.php index 91bb30eb..6b66c540 100644 --- a/lib/Interfaces/Object/NoteInterface.php +++ b/lib/Interfaces/Object/NoteInterface.php @@ -47,25 +47,11 @@ use OCA\Social\Service\PushService; class NoteInterface implements IActivityPubInterface { private StreamRequest $streamRequest; - private CurlService $curlService; - private PushService $pushService; - private ConfigService $configService; - private MiscService $miscService; - - /** - * NoteInterface constructor. - * - * @param StreamRequest $streamRequest - * @param CurlService $curlService - * @param PushService $pushService - * @param ConfigService $configService - * @param MiscService $miscService - */ public function __construct( StreamRequest $streamRequest, CurlService $curlService, PushService $pushService, ConfigService $configService, MiscService $miscService @@ -77,36 +63,20 @@ class NoteInterface implements IActivityPubInterface { $this->miscService = $miscService; } - - /** - * @param ACore $note - */ - public function processIncomingRequest(ACore $note) { + public function processIncomingRequest(ACore $item) { } - - /** - * @param ACore $item - */ public function processResult(ACore $item) { } - /** - * @param ACore $item - * - * @return ACore * @throws ItemNotFoundException */ public function getItem(ACore $item): ACore { throw new ItemNotFoundException(); } - /** - * @param string $id - * - * @return ACore * @throws ItemNotFoundException */ public function getItemById(string $id): ACore { @@ -140,13 +110,9 @@ class NoteInterface implements IActivityPubInterface { } } - - /** - * @param ACore $note - */ - public function save(ACore $note) { + public function save(ACore $item) { /** @var Note $note */ - + $note = $item; try { $this->streamRequest->getStreamById($note->getId()); } catch (StreamNotFoundException $e) { diff --git a/lib/Model/ActivityPub/Item.php b/lib/Model/ActivityPub/Item.php index 6920c7c0..f9a2baf8 100644 --- a/lib/Model/ActivityPub/Item.php +++ b/lib/Model/ActivityPub/Item.php @@ -37,163 +37,85 @@ use OCA\Social\Model\InstancePath; class Item { use TArrayTools; - private string $urlSocial = ''; - private string $urlCloud = ''; - private string $address = ''; - private string $id = ''; - private int $nid = 0; - private string $type = ''; - private string $subType = ''; - private string $url = ''; - private string $attributedTo = ''; - private string $summary = ''; - /** @var InstancePath[] */ private array $instancePaths = []; - private string $to = ''; - private array $toArray = []; - private array $cc = []; - private array $bcc = []; - private string $published = ''; - private array $tags = []; - private ?Person $actor = null; - private string $actorId = ''; - private string $iconId = ''; - private string $objectId = ''; - private bool $completeDetails = false; - private string $source = ''; - private bool $local = false; - private string $origin = ''; - private int $originSource = 0; - private int $originCreationTime = 0; - - /** - * @return string - */ public function getId(): string { return $this->id; } - /** - * @param string $id - * - * @return Item - */ public function setId(string $id): Item { $this->id = $id; return $this; } - - /** - * @return int - */ public function getNid(): int { return $this->nid; } - /** - * @param int $nid - * - * @return Item - */ public function setNid(int $nid): self { $this->nid = $nid; return $this; } - - /** - * @return string - */ public function getType(): string { return $this->type; } - /** - * @param string $type - * - * @return Item - */ public function setType(string $type): Item { $this->type = $type; return $this; } - - /** - * @return string - */ public function getSubType(): string { return $this->subType; } - /** - * @param string $type - * - * @return Item - */ public function setSubType(string $type): Item { $this->subType = $type; return $this; } - - /** - * @return string - */ public function getUrl(): string { return $this->url; } - /** - * @param string $url - * - * @return Item - */ public function setUrl(string $url): Item { $this->url = $url; return $this; } - - /** - * @param InstancePath $instancePath - * - * @return Item - */ public function addInstancePath(InstancePath $instancePath): Item { if ($instancePath->getUri() !== '') { $this->instancePaths[] = $instancePath; @@ -202,11 +124,8 @@ class Item { return $this; } - /** * @param InstancePath[] $path - * - * @return Item */ public function addInstancePaths(array $path): Item { $this->instancePaths = array_merge($this->instancePaths, $path); @@ -232,10 +151,6 @@ class Item { return $this; } - - /** - * @return string - */ public function getSummary(): string { return $this->summary; } @@ -255,15 +170,10 @@ class Item { /** * @return Person */ - public function getActor(): Person { + public function getActor(): ?Person { return $this->actor; } - /** - * @param Person $actor - * - * @return Item - */ public function setActor(Person $actor): Item { $this->actor = $actor; diff --git a/lib/Model/ActivityPub/Object/Announce.php b/lib/Model/ActivityPub/Object/Announce.php index 401f61b9..b14db201 100644 --- a/lib/Model/ActivityPub/Object/Announce.php +++ b/lib/Model/ActivityPub/Object/Announce.php @@ -51,7 +51,7 @@ class Announce extends Stream implements JsonSerializable { * * @param ACore $parent */ - public function __construct($parent = null) { + public function __construct(?ACore $parent = null) { parent::__construct($parent); $this->setType(self::TYPE); diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index 58b11184..ac25c53b 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -58,40 +58,26 @@ class Stream extends ACore implements IQueryRow, JsonSerializable { public const TYPE_DIRECT = 'direct'; public const TYPE_ANNOUNCE = 'announce'; - private string $activityId = ''; - private string $content = ''; - private string $spoilerText = ''; - private string $language = 'en'; - private string $attributedTo = ''; - private string $inReplyTo = ''; - private bool $sensitive = false; - private string $conversation = ''; - private ?Cache $cache = null; - private int $publishedTime = 0; - private ?StreamAction $action = null; - private string $timeline = ''; - private bool $filterDuplicate = false; - /** * Stream constructor. * - * @param null $parent + * @param ?ACore $parent */ - public function __construct($parent = null) { + public function __construct(?ACore $parent = null) { parent::__construct($parent); } @@ -286,7 +272,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable { /** * @return Cache */ - public function getCache(): Cache { + public function getCache(): ?Cache { return $this->cache; } @@ -315,19 +301,10 @@ class Stream extends ACore implements IQueryRow, JsonSerializable { return $this; } - - /** - * @return StreamAction - */ - public function getAction(): StreamAction { + public function getAction(): ?StreamAction { return $this->action; } - /** - * @param StreamAction $action - * - * @return Stream - */ public function setAction(StreamAction $action): Stream { $this->action = $action; diff --git a/lib/Model/LinkedDataSignature.php b/lib/Model/LinkedDataSignature.php index bd9af964..b4022ed2 100644 --- a/lib/Model/LinkedDataSignature.php +++ b/lib/Model/LinkedDataSignature.php @@ -107,18 +107,27 @@ class LinkedDataSignature implements JsonSerializable { return $this->privateKey; } - public function setPrivateKey(string $privateKey): LinkedDataSignature { + public function setPrivateKey(string $privateKey): self { $this->privateKey = $privateKey; return $this; } - public function setPublicKey(string $publicKey): LinkedDataSignature { + public function setPublicKey(string $publicKey): self { $this->publicKey = $publicKey; return $this; } + public function getObject(): array { + return $this->object; + } + + public function setObject(array $object): self { + $this->object = $object; + return $this; + } + /** * @throws LinkedDataSignatureMissingException */ diff --git a/lib/Model/StreamAction.php b/lib/Model/StreamAction.php index 784734a5..455511c2 100644 --- a/lib/Model/StreamAction.php +++ b/lib/Model/StreamAction.php @@ -49,169 +49,88 @@ class StreamAction implements JsonSerializable { public const BOOSTED = 'boosted'; public const REPLIED = 'replied'; - private int $id = 0; - private string $actorId = ''; - private string $streamId = ''; - private array $values = []; /** * StreamAction constructor. - * - * @param string $actorId - * @param string $streamId */ public function __construct(string $actorId = '', string $streamId = '') { $this->actorId = $actorId; $this->streamId = $streamId; } - - /** - * @return int - */ public function getId(): int { return $this->id; } - /** - * @param int $id - * - * @return StreamAction - */ public function setId(int $id): StreamAction { $this->id = $id; return $this; } - - /** - * @return string - */ public function getActorId(): string { return $this->actorId; } - /** - * @param string $actorId - * - * @return StreamAction - */ public function setActorId(string $actorId): StreamAction { $this->actorId = $actorId; return $this; } - - /** - * @return string - */ public function getStreamId(): string { return $this->streamId; } - /** - * @param string $streamId - * - * @return StreamAction - */ public function setStreamId(string $streamId): StreamAction { $this->streamId = $streamId; return $this; } - - /** - * @param string $key - * @param string $value - */ - public function updateValue(string $key, string $value) { + public function updateValue(string $key, string $value): void { $this->values[$key] = $value; } - /** - * @param string $key - * @param int $value - */ - public function updateValueInt(string $key, int $value) { + public function updateValueInt(string $key, int $value): void { $this->values[$key] = $value; } - /** - * @param string $key - * @param bool $value - */ - public function updateValueBool(string $key, bool $value) { + public function updateValueBool(string $key, bool $value): void { $this->values[$key] = $value; } - /** - * @param string $key - * - * @return bool - */ public function hasValue(string $key): bool { return (array_key_exists($key, $this->values)); } - /** - * @param string $key - * - * @return string - */ public function getValue(string $key): string { return $this->values[$key]; } - /** - * @param string $key - * - * @return int - */ public function getValueInt(string $key): int { return $this->values[$key]; } - /** - * @param string $key - * - * @return bool - */ public function getValueBool(string $key): bool { return $this->values[$key]; } - /** - * @return array - */ public function getValues(): array { return $this->values; } - /** - * @param array $values - * - * @return StreamAction - */ public function setValues(array $values): StreamAction { $this->values = $values; return $this; } - - /** - * @param array $default - * - * @return StreamAction - */ public function setDefaultValues(array $default): StreamAction { $keys = array_keys($default); foreach ($keys as $k) { @@ -223,21 +142,13 @@ class StreamAction implements JsonSerializable { return $this; } - - /** - * @param array $data - */ - public function importFromDatabase(array $data) { + public function importFromDatabase(array $data): void { $this->setId($this->getInt('id', $data, 0)); $this->setActorId($this->get('actor_id', $data, '')); $this->setStreamId($this->get('stream_id', $data, '')); $this->setValues($this->getArray('values', $data, [])); } - - /** - * @return array - */ public function jsonSerialize(): array { return [ 'id' => $this->getId(), diff --git a/lib/Model/StreamDetails.php b/lib/Model/StreamDetails.php index e62d3963..79adf472 100644 --- a/lib/Model/StreamDetails.php +++ b/lib/Model/StreamDetails.php @@ -44,7 +44,6 @@ use OCA\Social\Model\ActivityPub\Stream; class StreamDetails implements JsonSerializable { use TArrayTools; - private Stream $stream; /** @var Person[] */ @@ -52,82 +51,51 @@ class StreamDetails implements JsonSerializable { /** @var Person[] */ private array $directViewers = []; - private bool $public = false; - private bool $federated = false; /** * StreamDetails constructor. - * - * @param Stream|null $stream */ - public function __construct(Stream $stream = null) { + public function __construct(?Stream $stream = null) { $this->stream = $stream; } - - /** - * @return Stream - */ public function getStream(): Stream { return $this->stream; } - /** - * @param Stream $stream - * - * @return StreamDetails - */ public function setStream(Stream $stream): self { $this->stream = $stream; return $this; } - - /** - * @return Person[] - */ + /** @return Person[] */ public function getHomeViewers(): array { return $this->homeViewers; } - /** - * @param Person[] $viewers - * - * @return StreamDetails - */ + /** @param Person[] $viewers */ public function setHomeViewers(array $viewers): self { $this->homeViewers = $viewers; return $this; } - /** - * @param Person $viewer - * - * @return StreamDetails - */ public function addHomeViewer(Person $viewer): self { $this->homeViewers[] = $viewer; return $this; } - - /** - * @return Person[] - */ public function getDirectViewers(): array { return $this->directViewers; } /** * @param Person[] $viewers - * - * @return StreamDetails */ public function setDirectViewers(array $viewers): self { $this->directViewers = $viewers; @@ -135,59 +103,32 @@ class StreamDetails implements JsonSerializable { return $this; } - /** - * @param Person $viewer - * - * @return StreamDetails - */ public function addDirectViewer(Person $viewer): self { $this->directViewers[] = $viewer; return $this; } - - /** - * @return bool - */ public function isPublic(): bool { return $this->public; } - /** - * @param bool $public - * - * @return StreamDetails - */ public function setPublic(bool $public): self { $this->public = $public; return $this; } - - /** - * @return bool - */ public function isFederated(): bool { return $this->federated; } - /** - * @param bool $federated - * - * @return StreamDetails - */ public function setFederated(bool $federated): self { $this->federated = $federated; return $this; } - - /** - * @return array - */ public function jsonSerialize(): array { return [ 'stream' => $this->getStream(), diff --git a/lib/Model/StreamQueue.php b/lib/Model/StreamQueue.php index 3bae0f6a..7077dc2b 100644 --- a/lib/Model/StreamQueue.php +++ b/lib/Model/StreamQueue.php @@ -44,7 +44,6 @@ use JsonSerializable; class StreamQueue implements JsonSerializable { use TArrayTools; - public const TYPE_CACHE = 'Cache'; public const TYPE_VERIFY = 'Signature'; @@ -52,58 +51,30 @@ class StreamQueue implements JsonSerializable { public const STATUS_RUNNING = 1; public const STATUS_SUCCESS = 9; - private int $id = 0; - private string $token = ''; - private string $streamId = ''; - private string $type = ''; - private int $status = 0; - private int $tries = 0; - private int $last = 0; - - /** - * StreamQueue constructor. - * - * @param string $token - * @param string $type - * @param string $streamId - */ public function __construct(string $token = '', string $type = '', string $streamId = '') { $this->token = $token; $this->type = $type; $this->streamId = $streamId; } - - /** - * @return int - */ public function getId(): int { return $this->id; } - /** - * @param int $id - * - * @return StreamQueue - */ public function setId(int $id): StreamQueue { $this->id = $id; return $this; } - - /** - * @return string - */ public function getToken(): string { return $this->token; } diff --git a/lib/Service/CheckService.php b/lib/Service/CheckService.php index d6aef40b..08b6420a 100644 --- a/lib/Service/CheckService.php +++ b/lib/Service/CheckService.php @@ -61,51 +61,22 @@ class CheckService { public const CACHE_PREFIX = 'social_check_'; private IUserManager $userManager; - private ICache $cache; - private IConfig $config; - private IClientService $clientService; - private IRequest $request; - private IURLGenerator $urlGenerator; - private FollowsRequest $followRequest; - private CacheActorsRequest $cacheActorsRequest; - private StreamDestRequest $streamDestRequest; - private StreamRequest $streamRequest; - private AccountService $accountService; - private ConfigService $configService; - private MiscService $miscService; + private ?string $userId = null; - - /** - * CheckService constructor. - * - * @param IUserManager $userManager - * @param ICache $cache - * @param IConfig $config - * @param IClientService $clientService - * @param IRequest $request - * @param IURLGenerator $urlGenerator - * @param FollowsRequest $followRequest - * @param CacheActorsRequest $cacheActorsRequest - * @param StreamDestRequest $streamDestRequest - * @param StreamRequest $streamRequest - * @param AccountService $accountService - * @param ConfigService $configService - * @param MiscService $miscService - */ public function __construct( - IUserManager $userManager, ICache $cache, IConfig $config, IClientService $clientService, + IUserManager $userManager, ?string $userId, ICache $cache, IConfig $config, IClientService $clientService, IRequest $request, IURLGenerator $urlGenerator, FollowsRequest $followRequest, CacheActorsRequest $cacheActorsRequest, StreamDestRequest $streamDestRequest, StreamRequest $streamRequest, AccountService $accountService, ConfigService $configService, @@ -124,6 +95,7 @@ class CheckService { $this->accountService = $accountService; $this->configService = $configService; $this->miscService = $miscService; + $this->userId = $userId; } @@ -291,16 +263,12 @@ class CheckService { return $count; } - - /** - * @param string $base - * - * @return bool - */ - private function requestWellKnown(string $base) { + private function requestWellKnown(string $base): bool { try { - $url = $base . '/.well-known/webfinger'; + $url = $base . '/.well-known/webfinger?resource=acct:' . $this->userId . '@' . parse_url($base, PHP_URL_HOST); $options['nextcloud']['allow_local_address'] = true; + $options['verify'] = $this->config->getSystemValue('social.checkssl', true); + $response = $this->clientService->newClient() ->get($url, $options); if ($response->getStatusCode() === Http::STATUS_OK) { diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 18905b4a..20e20412 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -87,29 +87,14 @@ class ConfigService { 'WHITELIST' => 'none_but' ]; - - private string $userId; - + private ?string $userId = null; private IConfig $config; - private IRequest $request; - private IURLGenerator $urlGenerator; - private MiscService $miscService; - - /** - * ConfigService constructor. - * - * @param string $userId - * @param IConfig $config - * @param IRequest $request - * @param IURLGenerator $urlGenerator - * @param MiscService $miscService - */ public function __construct( - $userId, IConfig $config, IRequest $request, IURLGenerator $urlGenerator, + ?string $userId, IConfig $config, IRequest $request, IURLGenerator $urlGenerator, MiscService $miscService ) { $this->userId = $userId; diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index 97ec688c..7f572a83 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -65,11 +65,8 @@ class CurlService { public const ASYNC_REQUEST_TOKEN = '/async/request/{token}'; public const USER_AGENT = 'Nextcloud Social'; - private ConfigService $configService; - private FediverseService $fediverseService; - private MiscService $miscService; @@ -115,10 +112,12 @@ class CurlService { throw new InvalidResourceException('account format is not valid'); } - list($username, $host) = explode('@', $account); - if ($username === null || $host === null) { + $exploded = explode('@', $account); + + if (count($exploded) < 2) { throw new InvalidResourceException(); } + [$username, $host] = $exploded; $protocols = ['https', 'http']; try { diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php index 98319806..32b90608 100644 --- a/lib/Service/SignatureService.php +++ b/lib/Service/SignatureService.php @@ -69,38 +69,21 @@ use stdClass; class SignatureService { use TArrayTools; - public const ORIGIN_HEADER = 1; public const ORIGIN_SIGNATURE = 2; public const ORIGIN_REQUEST = 3; - public const DATE_HEADER = 'D, d M Y H:i:s T'; public const DATE_OBJECT = 'Y-m-d\TH:i:s\Z'; public const DATE_DELAY = 300; - private CacheActorService $cacheActorService; - private ActorsRequest $actorsRequest; - private CurlService $curlService; - private ConfigService $configService; - private MiscService $miscService; - - /** - * ActivityService constructor. - * - * @param ActorsRequest $actorsRequest - * @param CacheActorService $cacheActorService - * @param CurlService $curlService - * @param ConfigService $configService - * @param MiscService $miscService - */ public function __construct( ActorsRequest $actorsRequest, CacheActorService $cacheActorService, CurlService $curlService, diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..eac4c173 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rector.php b/rector.php deleted file mode 100644 index ed03ec41..00000000 --- a/rector.php +++ /dev/null @@ -1,30 +0,0 @@ -parameters(); - $parameters->set(Option::PATHS, [ - __DIR__ . '/lib', - __DIR__ . '/tests/', - ]); - - $parameters->set(Option::BOOTSTRAP_FILES, [ - __DIR__ . '/vendor/autoload.php', - __DIR__ . '/../../lib/composer/autoload.php', - __DIR__ . '/../../3rdparty/autoload.php', - ]); - - $parameters->set(Option::AUTO_IMPORT_NAMES, true); - $parameters->set(Option::IMPORT_SHORT_CLASSES, false); - - $services = $containerConfigurator->services(); - $services->set(TypedPropertyRector::class) - ->configure([ - TypedPropertyRector::INLINE_PUBLIC => true, - ]); -}; diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml new file mode 100644 index 00000000..820766ca --- /dev/null +++ b/tests/psalm-baseline.xml @@ -0,0 +1,156 @@ + + + + + $level + + + $ap->groupInterface + $ap->groupInterface + $ap->groupInterface + + + + + DBALException + + + + + SchemaException + SchemaException + Type + + + + + ['a', 'p', 'span', 'br'] + + + Acore + + + ACore + ACore + Document + LinkedDataSignature + + + $parent + + + $this->icon + $this->object + $this->parent + $this->signature + + + $v === null + + + $v === 0 + $v === 0 + + + + + $object = $cache->getItem($this->getObjectId()) + + + + + Person + string + + + $this->accountPrim + $this->contactAccount + + + + + getPublicKey + + + + + InstancePath + + + $this->instance + + + + + (bool)($this->cache->get(self::CACHE_PREFIX . 'wellknown') === 'true') + + + ClientException + + + + + $this->configService->getAppValue(ConfigService::SOCIAL_MAX_SIZE) + + + is_array($result) + + + + + $this->followsRequest->getFollowersByActorId($actor->getId()) + $this->followsRequest->getFollowingByActorId($actor->getId()) + + + Person[] + Person[] + + + + + $result + + + Stream[] + + + + + ACore + + + $activity + + + setAttributedTo + setContent + + + + + !$type + !$type + !$type + + + + + $varr[0] !== null + + + getAppDataDir + + + + + Note[] + + + + + $host === null + $username === null + $username === null + + + diff --git a/tests/stub.phpstub b/tests/stub.phpstub new file mode 100644 index 00000000..e069ae71 --- /dev/null +++ b/tests/stub.phpstub @@ -0,0 +1,1019 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Files_Trashbin\Trash { + use OCP\Files\Node; + use OCP\Files\Storage\IStorage; + use OCP\IUser; + use OCP\Files\FileInfo; + + interface ITrashManager { + public function pauseTrash(); + + public function resumeTrash(); + } + + interface ITrashBackend { + /** + * @return ITrashItem[] + */ + public function listTrashRoot(IUser $user): array; + + /** + * @return ITrashItem[] + */ + public function listTrashFolder(ITrashItem $folder): array; + + /** + * @param ITrashItem $item + */ + public function restoreItem(ITrashItem $item); + + public function removeItem(ITrashItem $item); + + public function moveToTrash(IStorage $storage, string $internalPath): bool; + + /** + * @return Node|null + */ + public function getTrashNodeById(IUser $user, int $fileId); + } + + interface ITrashItem extends FileInfo { + public function getTrashBackend(): ITrashBackend; + + public function getOriginalLocation(): string; + + public function getDeletedTime(): int; + + public function getTrashPath(): string; + + public function isRootItem(): bool; + + public function getUser(): IUser; + + public function getTitle(): string; + } + + class TrashItem implements ITrashItem { + public function getTrashBackend(): ITrashBackend { + throw new \Exception('stub'); + } + + public function getOriginalLocation(): string { + throw new \Exception('stub'); + } + + public function getDeletedTime(): int { + throw new \Exception('stub'); + } + + public function getTrashPath(): string { + throw new \Exception('stub'); + } + + public function isRootItem(): bool { + throw new \Exception('stub'); + } + + public function getUser(): IUser { + throw new \Exception('stub'); + } + + public function getEtag() { + } + + public function getId() { + } + + public function getSize($includeMounts = true) { + throw new \Exception('stub'); + } + + public function getMtime() { + throw new \Exception('stub'); + } + + public function getName() { + throw new \Exception('stub'); + } + + public function getInternalPath() { + throw new \Exception('stub'); + } + + public function getPath() { + throw new \Exception('stub'); + } + + public function getMimetype() { + throw new \Exception('stub'); + } + + public function getMimePart() { + throw new \Exception('stub'); + } + + public function getStorage() { + throw new \Exception('stub'); + } + + public function isEncrypted() { + throw new \Exception('stub'); + } + + public function getPermissions() { + throw new \Exception('stub'); + } + + public function getType() { + throw new \Exception('stub'); + } + + public function isReadable() { + throw new \Exception('stub'); + } + + public function isUpdateable() { + throw new \Exception('stub'); + } + + public function isCreatable() { + throw new \Exception('stub'); + } + + public function isDeletable() { + throw new \Exception('stub'); + } + + public function isShareable() { + throw new \Exception('stub'); + } + + public function isShared() { + throw new \Exception('stub'); + } + + public function isMounted() { + throw new \Exception('stub'); + } + + public function getMountPoint() { + throw new \Exception('stub'); + } + + public function getOwner() { + throw new \Exception('stub'); + } + + public function getChecksum() { + throw new \Exception('stub'); + } + + public function getExtension(): string { + throw new \Exception('stub'); + } + + public function getTitle(): string { + throw new \Exception('stub'); + } + + public function getCreationTime(): int { + throw new \Exception('stub'); + } + + public function getUploadTime(): int { + throw new \Exception('stub'); + } + } +} + +namespace OCA\Files_Trashbin { + class Expiration { + + public const DEFAULT_RETENTION_OBLIGATION = 30; + public const NO_OBLIGATION = -1; + + public function setRetentionObligation(string $obligation) {} + + /** @return bool */ + public function isEnabled() {} + + /** + * @param int $timestamp + * @param bool $quotaExceeded + * @return bool + */ + public function isExpired($timestamp, $quotaExceeded = false) {} + } +} + + +namespace OCA\Files_Versions\Versions { + use OCP\Files\File; + use OCP\Files\FileInfo; + use OCP\Files\NotFoundException; + use OCP\Files\Storage\IStorage; + use OCP\IUser; + + interface IVersionBackend { + public function useBackendForStorage(IStorage $storage): bool; + + /** + * @return IVersion[] + */ + public function getVersionsForFile(IUser $user, FileInfo $file): array; + + public function createVersion(IUser $user, FileInfo $file); + + public function rollback(IVersion $version); + + /** + * @return resource|false + * @throws NotFoundException + */ + public function read(IVersion $version); + + /** + * @param int|string $revision + */ + public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): ?File; + } + + interface IVersion { + public function getBackend(): IVersionBackend; + + public function getSourceFile(): FileInfo; + + /** + * @return int|string + */ + public function getRevisionId(); + + public function getTimestamp(): int; + + public function getSize(): int; + + public function getSourceFileName(): string; + + public function getMimeType(): string; + + public function getVersionPath(): string; + + public function getUser(): IUser; + } + + class Version implements IVersion { + public function __construct( + int $timestamp, + $revisionId, + string $name, + int $size, + string $mimetype, + string $path, + FileInfo $sourceFileInfo, + IVersionBackend $backend, + IUser $user + ) { + } + + public function getBackend(): IVersionBackend { + throw new \Exception('stub'); + } + + public function getSourceFile(): FileInfo { + throw new \Exception('stub'); + } + + public function getRevisionId() { + throw new \Exception('stub'); + } + + public function getTimestamp(): int { + throw new \Exception('stub'); + } + + public function getSize(): int { + throw new \Exception('stub'); + } + + public function getSourceFileName(): string { + throw new \Exception('stub'); + } + + public function getMimeType(): string { + throw new \Exception('stub'); + } + + public function getVersionPath(): string { + throw new \Exception('stub'); + } + + public function getUser(): IUser { + throw new \Exception('stub'); + } + } +} + +namespace OCA\Files_Versions { + class Expiration { + // how long do we keep files a version if no other value is defined in the config file (unit: days) + public const NO_OBLIGATION = -1; + /** @return bool */ + public function isEnabled() {} + + public function shouldAutoExpire() { } + + /** + * @param int $timestamp + * @param bool $quotaExceeded + * @return bool + */ + public function isExpired($timestamp, $quotaExceeded = false) {} + + /** @return int */ + public function getMaxAgeAsTimestamp() {} + } +} + +namespace { + + use OCP\IServerContainer; + + class OC { + static $CLI = false; + /** @var IServerContainer */ + static $server; + } +} + +namespace OC\Files\Node { + use OCP\Files\FileInfo; + abstract class Node implements \OCP\Files\Node { + /** @return FileInfo|\ArrayAccess */ + public function getFileInfo() {} + + /** @return \OCP\Files\Mount\IMountPoint */ + public function getMountPoint() {} + } +} + +namespace OC\Hooks { + class Emitter { + public function emit(string $class, string $value, array $option) {} + /** Closure $closure */ + public function listen(string $class, string $value, $closure) {} + } + class BasicEmitter extends Emitter { + } +} + +namespace OC\Cache { + class CappedMemoryCache { + public function get($key) {} + public function set($key, $value, $ttl = '') {} + } +} + +namespace OC\Core\Command { + use Symfony\Component\Console\Input\InputInterface; + use Symfony\Component\Console\Output\OutputInterface; + class Base { + public const OUTPUT_FORMAT_PLAIN = 'plain'; + public const OUTPUT_FORMAT_JSON = 'json'; + public const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty'; + + public function __construct() {} + protected function configure() {} + public function run(InputInterface $input, OutputInterface $output) {} + public function setName(string $name) {} + public function getHelper(string $name) {} + protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { + } + } +} + +namespace OC\Files\ObjectStore { + class NoopScanner {} +} + +namespace Symfony\Component\Console\Helper { + use Symfony\Component\Console\Output\OutputInterface; + class Table { + public function __construct(OutputInterface $text) {} + public function setHeaders(array $header) {} + public function setRows(array $rows) {} + public function render() {} + public function appendRow(array $row) {} + } +} + +namespace Symfony\Component\Console\Input { + class InputInterface { + public function getOption(string $key) {} + public function getArgument(string $key) {} + } + class InputArgument { + const REQUIRED = 0; + const OPTIONAL = 1; + const IS_ARRAY = 1; + } + class InputOption { + const VALUE_NONE = 1; + const VALUE_REQUIRED = 1; + const VALUE_OPTIONAL = 1; + } +} + +namespace Symfony\Component\Console\Question { + class ConfirmationQuestion { + public function __construct(string $text, bool $default, string $accept = 'y') {} + } +} + +namespace Symfony\Component\Console\Output { + class OutputInterface { + public const VERBOSITY_VERBOSE = 1; + public function writeln(string $text, int $flat = 0) {} + public function write(string $text, int $flat = 0) {} + } +} + +namespace OC\User { + class NoUserException extends \Exception {} +} + +namespace OC\DB { + use OCP\IDBConnection; + class ConnectionAdapter {} + + class SchemaWrapper { + public function __construct(IDBConnection $connection) {} + + public function performDropTableCalls(); + } +} + +namespace OC { + class SystemConfig {} +} + +namespace Doctrine\DBAL\Query { + class QueryBuilder { + public const SELECT = 'select'; + } +} + +namespace OC\DB\QueryBuilder { + use OCP\DB\IResult; + use OCP\DB\QueryBuilder\ICompositeExpression; + use OCP\DB\QueryBuilder\ILiteral; + use OCP\DB\QueryBuilder\IParameter; + use OCP\DB\QueryBuilder\IQueryBuilder; + use OCP\DB\QueryBuilder\IQueryFunction; + use Psr\Log\LoggerInterface; + + class QueryBuilder implements IQueryBuilder { + public function __construct(ConnectionAdapter $connection, SystemConfig $systemConfig, LoggerInterface $logger) { + } + public function automaticTablePrefix($enabled) { } + public function expr() { } + public function func() { } + public function getType() { } + public function getConnection() { } + public function getState() { } + public function execute() { } + public function executeQuery(): IResult { } + public function executeUpdate(): int { } + public function executeStatement(): int { } + public function getSQL() { } + public function setParameter($key, $value, $type = null) { } + public function setParameters(array $params, array $types = []) { } + public function getParameters() { } + public function getParameter($key) { } + public function getParameterTypes() { } + public function getParameterType($key) { } + public function setFirstResult($firstResult) { } + public function getFirstResult() { } + public function setMaxResults($maxResults) { } + public function getMaxResults() { } + public function select(...$selects) { } + public function selectAlias($select, $alias) { } + public function selectDistinct($select) { } + public function addSelect(...$selects) { } + public function delete($delete = null, $alias = null) { } + public function update($update = null, $alias = null) { } + public function insert($insert = null) { } + public function from($from, $alias = null) { } + public function join($fromAlias, $join, $alias, $condition = null) { } + public function innerJoin($fromAlias, $join, $alias, $condition = null) { } + public function leftJoin($fromAlias, $join, $alias, $condition = null) { } + public function rightJoin($fromAlias, $join, $alias, $condition = null) { } + public function set($key, $value) { } + public function where(...$predicates) { } + public function andWhere(...$where) { } + public function orWhere(...$where) { } + public function groupBy(...$groupBys) { } + public function addGroupBy(...$groupBys) { } + public function setValue($column, $value) { } + public function values(array $values) { } + public function having(...$having) { } + public function andHaving(...$having) { } + public function orHaving(...$having) { } + public function orderBy($sort, $order = null) { } + public function addOrderBy($sort, $order = null) { } + public function getQueryPart($queryPartName) { } + public function getQueryParts() { } + public function resetQueryParts($queryPartNames = null) { } + public function resetQueryPart($queryPartName) { } + public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) { } + public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) { } + public function createParameter($name) { } + public function createFunction($call) { } + public function getLastInsertId(): int { } + public function getTableName($table) { } + protected function prefixTableName($table) { } + public function getColumnName($column, $tableAlias = '') { } + public function quoteAlias($alias) { } + } +} + +namespace OC\Files\Cache { + use OCP\Files\Cache\ICache; + use OCP\Files\Cache\ICacheEntry; + use OCP\Files\Search\ISearchQuery; + use OCP\Files\Search\ISearchOperator; + use OCP\Files\Search\ISearchQuery; + use OCP\Files\IMimeTypeLoader; + + class Cache implements ICache { + /** + * @param \OCP\Files\Cache\ICache $cache + */ + public function __construct($cache) { + $this->cache = $cache; + } + public function getNumericStorageId() { } + public function get() { } + public function getIncomplete() {} + public function getPathById($id) {} + public function getAll() {} + public function get($file) {} + public function getFolderContents($folder) {} + public function getFolderContentsById($fileId) {} + public function put($file, array $data) {} + public function insert($file, array $data) {} + public function update($id, array $data) {} + public function getId($file) {} + public function getParentId($file) {} + public function inCache($file) {} + public function remove($file) {} + public function move($source, $target) {} + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {} + public function clear() {} + public function getStatus($file) {} + public function search($pattern) {} + public function searchByMime($mimetype) {} + public function searchQuery(ISearchQuery $query) {} + public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {} + public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {} + public function normalize($path) {} + public function getQueryFilterForStorage(): ISearchOperator {} + public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {} + public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader): ICacheEntry {} + } +} + +namespace OC\Files\Cache\Wrapper { + use OC\Files\Cache\Cache; + class CacheWrapper extends Cache {} +} + +namespace OC\Files { + use OCP\Files\Cache\ICacheEntry; + use OCP\Files\Mount\IMountPoint; + use OCP\IUser; + + class Filesystem { + public static function addStorageWrapper(string $wrapperName, callable $wrapper, int $priority = 50) { + } + } + + class FileInfo implements \OCP\Files\FileInfo { + /** + * @param string|boolean $path + * @param \OCP\Files\Storage\IStorage $storage + * @param string $internalPath + * @param array|ICacheEntry $data + * @param \OCP\Files\Mount\IMountPoint $mount + * @param \OCP\IUser|null $owner + */ + public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) {} + } + class View { + public function __construct(string $path) {} + public function unlink($path) {} + } +} + +namespace OC\User { + use OCP\UserInterface; + use OCP\IUser; + use Symfony\Component\EventDispatcher\EventDispatcherInterface; + class User implements IUser { + public function __construct(string $uid, ?UserInterface $backend, EventDispatcherInterface $dispatcher, $emitter = null, IConfig $config = null, $urlGenerator = null) {} + } +} + +namespace OCA\DAV\Upload { + + use Sabre\DAV\File; + + abstract class FutureFile extends File {} +} + +namespace OCA\DAV\Connector\Sabre { + + class Node { + public function getFileInfo(): \OCP\Files\FileInfo {} + } +} + +namespace OC\BackgroundJob { + + use OCP\BackgroundJob\IJob; + use OCP\BackgroundJob\IJobList; + use OCP\ILogger; + + abstract class TimedJob implements IJob { + public function execute(IJobList $jobList, ILogger $logger = null) { + } + + abstract protected function run($argument); + + public function setId(int $id) { + } + + public function setLastRun(int $lastRun) { + } + + public function setArgument($argument) { + } + + public function getId() { + } + + public function getLastRun() { + } + + public function getArgument() { + } + } +} + +namespace OC\Files\Mount { + use OC\Files\Filesystem; + use OC\Files\Storage\Storage; + use OC\Files\Storage\StorageFactory; + use OCP\Files\Mount\IMountPoint; + + class MountPoint implements IMountPoint { + /** + * @var \OC\Files\Storage\Storage $storage + */ + protected $storage = null; + protected $class; + protected $storageId; + protected $rootId = null; + + /** @var int|null */ + protected $mountId; + + /** + * @param string|\OCP\Files\Storage\IStorage $storage + * @param string $mountpoint + * @param array $arguments (optional) configuration for the storage backend + * @param \OCP\Files\Storage\IStorageFactory $loader + * @param array $mountOptions mount specific options + * @param int|null $mountId + * @throws \Exception + */ + public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { + throw new \Exception('stub'); + } + + /** + * get complete path to the mount point, relative to data/ + * + * @return string + */ + public function getMountPoint() { + throw new \Exception('stub'); + } + + /** + * Sets the mount point path, relative to data/ + * + * @param string $mountPoint new mount point + */ + public function setMountPoint($mountPoint) { + throw new \Exception('stub'); + } + + /** + * @return \OCP\Files\Storage\IStorage + */ + public function getStorage() { + throw new \Exception('stub'); + } + + /** + * @return string + */ + public function getStorageId() { + throw new \Exception('stub'); + } + + /** + * @return int + */ + public function getNumericStorageId() { + throw new \Exception('stub'); + } + + /** + * @param string $path + * @return string + */ + public function getInternalPath($path) { + throw new \Exception('stub'); + } + + /** + * @param callable $wrapper + */ + public function wrapStorage($wrapper) { + throw new \Exception('stub'); + } + + /** + * Get a mount option + * + * @param string $name Name of the mount option to get + * @param mixed $default Default value for the mount option + * @return mixed + */ + public function getOption($name, $default) { + throw new \Exception('stub'); + } + + /** + * Get all options for the mount + * + * @return array + */ + public function getOptions() { + throw new \Exception('stub'); + } + + /** + * @return int + */ + public function getStorageRootId() { + throw new \Exception('stub'); + } + + public function getMountId() { + throw new \Exception('stub'); + } + + public function getMountType() { + throw new \Exception('stub'); + } + + public function getMountProvider(): string { + throw new \Exception('stub'); + } + } +} + +namespace OC\Files\Storage\Wrapper{ + + use OCP\Files\Cache\ICache; + use OCP\Files\Cache\ICacheEntry; + use OCP\Files\Search\ISearchQuery; + use OCP\Files\Storage\IStorage; + + class Wrapper implements IStorage { + public function __construct(array $parameters) { + } + + public function getWrapperStorage(): ?IStorage {} + + public function getId() {} + + public function mkdir($path) {} + + public function rmdir($path) {} + + public function opendir($path) { + throw new \Exception('stub'); + } + + public function is_dir($path) { + throw new \Exception('stub'); + } + + public function is_file($path) { + throw new \Exception('stub'); + } + + public function stat($path) { + throw new \Exception('stub'); + } + + public function filetype($path) { + throw new \Exception('stub'); + } + + public function filesize($path) { + throw new \Exception('stub'); + } + + public function isCreatable($path) { + throw new \Exception('stub'); + } + + public function isReadable($path) { + throw new \Exception('stub'); + } + + public function isUpdatable($path) { + throw new \Exception('stub'); + } + + public function isDeletable($path) { + throw new \Exception('stub'); + } + + public function isSharable($path) { + throw new \Exception('stub'); + } + + public function getPermissions($path) { + throw new \Exception('stub'); + } + + public function file_exists($path) { + throw new \Exception('stub'); + } + + public function filemtime($path) { + throw new \Exception('stub'); + } + + public function file_get_contents($path) { + throw new \Exception('stub'); + } + + public function file_put_contents($path, $data) { + throw new \Exception('stub'); + } + + public function unlink($path) { + throw new \Exception('stub'); + } + + public function rename($path1, $path2) { + throw new \Exception('stub'); + } + + public function copy($path1, $path2) { + throw new \Exception('stub'); + } + + public function fopen($path, $mode) { + throw new \Exception('stub'); + } + + public function getMimeType($path) { + throw new \Exception('stub'); + } + + public function hash($type, $path, $raw = false) { + throw new \Exception('stub'); + } + + public function free_space($path) { + throw new \Exception('stub'); + } + + public function touch($path, $mtime = null) { + throw new \Exception('stub'); + } + + public function getLocalFile($path) { + throw new \Exception('stub'); + } + + public function hasUpdated($path, $time) { + throw new \Exception('stub'); + } + + public function getETag($path) { + throw new \Exception('stub'); + } + + public function isLocal() { + throw new \Exception('stub'); + } + + public function instanceOfStorage($class) { + throw new \Exception('stub'); + } + + public function getDirectDownload($path) { + throw new \Exception('stub'); + } + + public function verifyPath($path, $fileName) { + throw new \Exception('stub'); + } + + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + throw new \Exception('stub'); + } + + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + throw new \Exception('stub'); + } + + public function test() { + throw new \Exception('stub'); + } + + public function getAvailability() { + throw new \Exception('stub'); + } + + public function setAvailability($isAvailable) { + throw new \Exception('stub'); + } + + public function getOwner($path) { + throw new \Exception('stub'); + } + + public function getCache() { + throw new \Exception('stub'); + } + + public function getPropagator() { + throw new \Exception('stub'); + } + + public function getScanner() { + throw new \Exception('stub'); + } + + public function getUpdater() { + throw new \Exception('stub'); + } + + public function getWatcher() { + throw new \Exception('stub'); + } + } + + class Jail extends Wrapper { + public function getUnjailedPath(string $path): string {} + } + + class Quota extends Wrapper { + public function getQuota() {} + } + + class PermissionsMask extends Wrapper { + public function getQuota() {} + } +}