From 79a6f1f490f0831109828f849ba2b9a92efb5164 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 2 Feb 2025 07:40:22 +0000 Subject: [PATCH 1/2] chore(deps): update dependency nextcloud/coding-standard to ^v1.3.2 Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- composer.json | 2 +- composer.lock | 73 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 483701dbc..fd258b2a1 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require-dev": { - "nextcloud/coding-standard": "^v1.0.0", + "nextcloud/coding-standard": "^v1.3.2", "nextcloud/ocp": "dev-master", "staabm/annotate-pull-request-from-checkstyle": "^1.8.5", "phpunit/phpunit": "^9", diff --git a/composer.lock b/composer.lock index 29b880104..73113c6e9 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": "f2b232873fb9281ef86e5988a073c748", + "content-hash": "fd3e738079538821efaa6000cb273f8c", "packages": [ { "name": "composer/pcre", @@ -840,6 +840,52 @@ ], "time": "2022-12-30T00:15:36+00:00" }, + { + "name": "kubawerlos/php-cs-fixer-custom-fixers", + "version": "v3.22.0", + "source": { + "type": "git", + "url": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers.git", + "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/8701394f0c7cd450ac4fa577d24589122c1d5d5e", + "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-tokenizer": "*", + "friendsofphp/php-cs-fixer": "^3.61.1", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.6.4 || ^10.5.29" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpCsFixerCustomFixers\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kuba Werłos", + "email": "werlos@gmail.com" + } + ], + "description": "A set of custom fixers for PHP CS Fixer", + "support": { + "issues": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/issues", + "source": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/tree/v3.22.0" + }, + "time": "2024-08-16T20:44:35+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.12.1", @@ -902,19 +948,20 @@ }, { "name": "nextcloud/coding-standard", - "version": "v1.1.1", + "version": "v1.3.2", "source": { "type": "git", "url": "https://github.com/nextcloud/coding-standard.git", - "reference": "55def702fb9a37a219511e1d8c6fe8e37164c1fb" + "reference": "9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/55def702fb9a37a219511e1d8c6fe8e37164c1fb", - "reference": "55def702fb9a37a219511e1d8c6fe8e37164c1fb", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d", + "reference": "9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d", "shasum": "" }, "require": { + "kubawerlos/php-cs-fixer-custom-fixers": "^3.22", "php": "^7.3|^8.0", "php-cs-fixer/shim": "^3.17" }, @@ -937,9 +984,9 @@ "description": "Nextcloud coding standards for the php cs fixer", "support": { "issues": "https://github.com/nextcloud/coding-standard/issues", - "source": "https://github.com/nextcloud/coding-standard/tree/v1.1.1" + "source": "https://github.com/nextcloud/coding-standard/tree/v1.3.2" }, - "time": "2023-06-01T12:05:01+00:00" + "time": "2024-10-14T16:49:05+00:00" }, { "name": "nextcloud/ocp", @@ -1168,16 +1215,16 @@ }, { "name": "php-cs-fixer/shim", - "version": "v3.46.0", + "version": "v3.68.5", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/shim.git", - "reference": "e9fc76796f284c050615937b9bd2df7688452c33" + "reference": "4a0a5cfd39b0677017a85f0fc252d3e8a6a6c02c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/e9fc76796f284c050615937b9bd2df7688452c33", - "reference": "e9fc76796f284c050615937b9bd2df7688452c33", + "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/4a0a5cfd39b0677017a85f0fc252d3e8a6a6c02c", + "reference": "4a0a5cfd39b0677017a85f0fc252d3e8a6a6c02c", "shasum": "" }, "require": { @@ -1214,9 +1261,9 @@ "description": "A tool to automatically fix PHP code style", "support": { "issues": "https://github.com/PHP-CS-Fixer/shim/issues", - "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.46.0" + "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.68.5" }, - "time": "2024-01-03T21:39:12+00:00" + "time": "2025-01-30T17:01:41+00:00" }, { "name": "phpunit/php-code-coverage", From c7c669fc58cf5d1a94f1bbdad3a9e93d6724b954 Mon Sep 17 00:00:00 2001 From: "Cleopatra Enjeck M." Date: Sun, 2 Feb 2025 18:32:09 +0000 Subject: [PATCH 2/2] fix: composer run cs:fix Signed-off-by: Cleopatra Enjeck M. --- lib/Analytics/AnalyticsDatasource.php | 13 +- lib/Api/V1Api.php | 1 + lib/AppInfo/Application.php | 1 + lib/Capabilities.php | 1 + lib/Command/AddTable.php | 4 +- lib/Command/ChangeOwnershipTable.php | 12 +- lib/Command/Clean.php | 70 ++++----- lib/Command/CleanLegacy.php | 66 ++++----- lib/Command/ListTables.php | 8 +- lib/Command/RemoveTable.php | 4 +- lib/Command/RenameTable.php | 4 +- lib/Command/TransferLegacyRows.php | 32 ++-- lib/Controller/AOCSController.php | 2 +- lib/Controller/Api1Controller.php | 124 ++++++++-------- lib/Controller/ApiColumnsController.php | 4 +- lib/Controller/ApiGeneralController.php | 6 +- lib/Controller/ApiTablesController.php | 2 +- lib/Controller/ColumnController.php | 4 +- lib/Controller/ContextController.php | 8 +- lib/Controller/Errors.php | 4 +- lib/Controller/ImportController.php | 8 +- lib/Controller/NavigationController.php | 2 +- lib/Controller/RowController.php | 4 +- lib/Db/Column.php | 4 +- lib/Db/ColumnMapper.php | 4 +- lib/Db/ColumnTypes/SelectionColumnQB.php | 2 +- lib/Db/ColumnTypes/SuperColumnQB.php | 30 ++-- lib/Db/ContextMapper.php | 10 +- lib/Db/LegacyRow.php | 2 +- lib/Db/LegacyRowMapper.php | 30 ++-- lib/Db/Row2.php | 2 +- lib/Db/Row2Mapper.php | 20 +-- lib/Db/RowCellNumberMapper.php | 6 +- lib/Db/RowCellUsergroupMapper.php | 5 +- lib/Db/RowSleeveMapper.php | 2 +- lib/Db/ShareMapper.php | 2 +- lib/Db/Table.php | 4 +- lib/Db/TableMapper.php | 4 +- lib/Db/View.php | 6 +- lib/Db/ViewMapper.php | 11 +- lib/Event/TableDeletedEvent.php | 4 +- lib/Event/TableOwnershipTransferredEvent.php | 8 +- lib/Event/ViewDeletedEvent.php | 4 +- lib/Helper/CircleHelper.php | 2 +- lib/Helper/UserHelper.php | 2 +- .../BeforeTemplateRenderedListener.php | 2 +- lib/Listener/UserDeletedListener.php | 4 +- .../WhenRowDeletedAuditLogListener.php | 4 +- .../WhenTableDeletedAuditLogListener.php | 4 +- .../WhenTableTransferredAuditLogListener.php | 4 +- .../WhenViewDeletedAuditLogListener.php | 4 +- lib/Middleware/PermissionMiddleware.php | 6 +- lib/Migration/NewDbStructureRepairStep.php | 20 +-- .../Version000000Date20210921000000.php | 2 +- .../Version000700Date20230916000000.php | 4 +- .../Version000800Date20240712000000.php | 4 +- lib/Model/Public/Row.php | 4 +- lib/Model/TableScheme.php | 2 +- lib/Reference/ContentReferenceHelper.php | 14 +- lib/Reference/ReferenceHelper.php | 16 +- lib/ResponseDefinitions.php | 1 + lib/Search/SearchTablesProvider.php | 20 +-- lib/Service/ColumnService.php | 66 ++++----- lib/Service/ColumnTypes/DatetimeBusiness.php | 2 +- .../ColumnTypes/NumberProgressBusiness.php | 4 +- .../ColumnTypes/NumberStarsBusiness.php | 4 +- lib/Service/ColumnTypes/SelectionBusiness.php | 22 +-- .../ColumnTypes/SelectionCheckBusiness.php | 2 +- .../ColumnTypes/SelectionMultiBusiness.php | 30 ++-- lib/Service/ColumnTypes/SuperBusiness.php | 2 +- lib/Service/ColumnTypes/TextLinkBusiness.php | 12 +- lib/Service/ColumnTypes/UsergroupBusiness.php | 14 +- lib/Service/ContextService.php | 22 +-- lib/Service/FavoritesService.php | 2 +- lib/Service/ImportService.php | 38 ++--- lib/Service/PermissionsService.php | 40 ++--- lib/Service/RowService.php | 108 +++++++------- lib/Service/ShareService.php | 48 +++--- .../Support/DefaultAuditLogService.php | 4 +- lib/Service/TableService.php | 82 +++++------ lib/Service/TableTemplateService.php | 26 ++-- lib/Service/ViewService.php | 28 ++-- .../features/bootstrap/FeatureContext.php | 138 +++++++++--------- tests/phan-config.php | 2 +- tests/unit/bootstrap.php | 2 +- 85 files changed, 697 insertions(+), 664 deletions(-) diff --git a/lib/Analytics/AnalyticsDatasource.php b/lib/Analytics/AnalyticsDatasource.php index 55a932742..4a92580a0 100644 --- a/lib/Analytics/AnalyticsDatasource.php +++ b/lib/Analytics/AnalyticsDatasource.php @@ -1,4 +1,5 @@ l10n = $l10n; $this->logger = $logger; diff --git a/lib/Api/V1Api.php b/lib/Api/V1Api.php index 69590e2f4..e76f8e430 100644 --- a/lib/Api/V1Api.php +++ b/lib/Api/V1Api.php @@ -1,4 +1,5 @@ writeln(json_encode($arr, JSON_PRETTY_PRINT)); } catch (InternalError|PermissionError|Exception $e) { - $output->writeln('Error occurred: '.$e->getMessage()); - $this->logger->warning('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $output->writeln('Error occurred: ' . $e->getMessage()); + $this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); return 1; } return 0; diff --git a/lib/Command/ChangeOwnershipTable.php b/lib/Command/ChangeOwnershipTable.php index 381b7f732..de412aa53 100644 --- a/lib/Command/ChangeOwnershipTable.php +++ b/lib/Command/ChangeOwnershipTable.php @@ -57,16 +57,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $table = $this->tableService->setOwner($id, $newOwnerUserId, ''); $output->writeln(json_encode($table->jsonSerialize(), JSON_PRETTY_PRINT)); } catch (InternalError $e) { - $output->writeln('Error occurred: '.$e->getMessage()); - $this->logger->warning('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $output->writeln('Error occurred: ' . $e->getMessage()); + $this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); return 1; } catch (NotFoundError $e) { - $output->writeln('Not found error occurred: '.$e->getMessage()); - $this->logger->warning('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $output->writeln('Not found error occurred: ' . $e->getMessage()); + $this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); return 1; } catch (PermissionError $e) { - $output->writeln('Permission error occurred: '.$e->getMessage()); - $this->logger->warning('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $output->writeln('Permission error occurred: ' . $e->getMessage()); + $this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); return 1; } return 0; diff --git a/lib/Command/Clean.php b/lib/Command/Clean.php index 080f2aa72..e145ac907 100644 --- a/lib/Command/Clean.php +++ b/lib/Command/Clean.php @@ -71,13 +71,13 @@ protected function configure(): void { */ protected function execute(InputInterface $input, OutputInterface $output): int { $this->output = $output; - $this->dry = !!$input->getOption('dry'); + $this->dry = (bool)$input->getOption('dry'); if ($this->dry) { - $this->print("Dry run activated."); + $this->print('Dry run activated.'); } if ($output->isVerbose()) { - $this->print("Verbose mode activated."); + $this->print('Verbose mode activated.'); } // check action, starting point for magic @@ -90,9 +90,9 @@ private function getNextRow():void { try { $nextRowId = $this->rowMapper->findNextId($this->offset); if ($nextRowId === null) { - $this->print(""); - $this->print("No more rows found.", self::PRINT_LEVEL_INFO); - $this->print(""); + $this->print(''); + $this->print('No more rows found.', self::PRINT_LEVEL_INFO); + $this->print(''); $this->row = null; return; } @@ -102,7 +102,7 @@ private function getNextRow():void { $this->offset = $this->row->getId(); } catch (Exception $e) { $this->print('Error while fetching row', self::PRINT_LEVEL_ERROR); - $this->logger->error('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->logger->error('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); } } @@ -116,10 +116,10 @@ private function checkIfColumnsForRowsExists(): void { $this->getNextRow(); while ($this->row) { - $this->print(""); - $this->print(""); - $this->print("Lets check row with id = " . $this->row->getId()); - $this->print("=========================================="); + $this->print(''); + $this->print(''); + $this->print('Lets check row with id = ' . $this->row->getId()); + $this->print('=========================================='); $this->checkColumns(); @@ -130,29 +130,29 @@ private function checkIfColumnsForRowsExists(): void { private function checkColumns(): void { foreach ($this->row->getData() as $date) { $valueAsString = is_string($date['value']) ? $date['value'] : json_encode($date['value']); - $suffix = strlen($valueAsString) > $this->truncateLength ? "...": ""; - $this->print(""); - $this->print("columnId: " . $date['columnId'] . " -> " . substr($valueAsString, 0, $this->truncateLength) . $suffix, self::PRINT_LEVEL_INFO); + $suffix = strlen($valueAsString) > $this->truncateLength ? '...': ''; + $this->print(''); + $this->print('columnId: ' . $date['columnId'] . ' -> ' . substr($valueAsString, 0, $this->truncateLength) . $suffix, self::PRINT_LEVEL_INFO); try { $this->columnService->find($date['columnId'], ''); - if($this->output->isVerbose()) { - $this->print("column found", self::PRINT_LEVEL_SUCCESS); + if ($this->output->isVerbose()) { + $this->print('column found', self::PRINT_LEVEL_SUCCESS); } } catch (InternalError $e) { - $this->print("😱️ internal error while looking for column", self::PRINT_LEVEL_ERROR); - $this->logger->error('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->print('😱️ internal error while looking for column', self::PRINT_LEVEL_ERROR); + $this->logger->error('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); } catch (NotFoundError $e) { - if($this->output->isVerbose()) { - $this->print("corresponding column not found.", self::PRINT_LEVEL_ERROR); + if ($this->output->isVerbose()) { + $this->print('corresponding column not found.', self::PRINT_LEVEL_ERROR); } else { - $this->print("columnId: " . $date['columnId'] . " not found, but needed by row ".$this->row->getId(), self::PRINT_LEVEL_WARNING); + $this->print('columnId: ' . $date['columnId'] . ' not found, but needed by row ' . $this->row->getId(), self::PRINT_LEVEL_WARNING); } // if the corresponding column is not found, lets delete the data from the row. $this->deleteDataFromRow($date['columnId']); } catch (PermissionError $e) { - $this->print("😱️ permission error while looking for column", self::PRINT_LEVEL_ERROR); - $this->logger->error('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->print('😱️ permission error while looking for column', self::PRINT_LEVEL_ERROR); + $this->logger->error('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); } } } @@ -164,40 +164,40 @@ private function checkColumns(): void { */ private function deleteDataFromRow(int $columnId): void { if ($this->dry) { - $this->print("Is dry run, will not remove the column data from row dataset.", self::PRINT_LEVEL_INFO); + $this->print('Is dry run, will not remove the column data from row dataset.', self::PRINT_LEVEL_INFO); return; } - $this->print("DANGER, start deleting", self::PRINT_LEVEL_WARNING); + $this->print('DANGER, start deleting', self::PRINT_LEVEL_WARNING); $data = $this->row->getData(); - $this->print("Data before: \t".json_encode(array_values($data)), self::PRINT_LEVEL_INFO); + $this->print("Data before: \t" . json_encode(array_values($data)), self::PRINT_LEVEL_INFO); $key = array_search($columnId, array_column($data, 'columnId')); unset($data[$key]); - $this->print("Data after: \t".json_encode(array_values($data)), self::PRINT_LEVEL_INFO); + $this->print("Data after: \t" . json_encode(array_values($data)), self::PRINT_LEVEL_INFO); $this->row->setData(array_values($data)); try { $this->rowMapper->update($this->row, $this->columnService->findAllByTable($this->row->getTableId())); - $this->print("Row successfully updated", self::PRINT_LEVEL_SUCCESS); + $this->print('Row successfully updated', self::PRINT_LEVEL_SUCCESS); } catch (InternalError|PermissionError $e) { - $this->print("Error while updating row to db.", self::PRINT_LEVEL_ERROR); - $this->logger->error('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->print('Error while updating row to db.', self::PRINT_LEVEL_ERROR); + $this->logger->error('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); } } private function print(string $message, ?int $level = null): void { - if($level === self::PRINT_LEVEL_SUCCESS) { - echo "✅ ".$message; + if ($level === self::PRINT_LEVEL_SUCCESS) { + echo '✅ ' . $message; echo "\n"; } elseif ($level === self::PRINT_LEVEL_INFO && $this->output->isVerbose()) { - echo "ℹ️ ".$message; + echo 'ℹ️ ' . $message; echo "\n"; } elseif ($level === self::PRINT_LEVEL_WARNING) { - echo "⚠️ ".$message; + echo '⚠️ ' . $message; echo "\n"; } elseif ($level === self::PRINT_LEVEL_ERROR) { - echo "❌ ".$message; + echo '❌ ' . $message; echo "\n"; } elseif ($this->output->isVerbose()) { echo $message; diff --git a/lib/Command/CleanLegacy.php b/lib/Command/CleanLegacy.php index 78d66b73d..ce3563b8e 100644 --- a/lib/Command/CleanLegacy.php +++ b/lib/Command/CleanLegacy.php @@ -73,13 +73,13 @@ protected function configure(): void { */ protected function execute(InputInterface $input, OutputInterface $output): int { $this->output = $output; - $this->dry = !!$input->getOption('dry'); + $this->dry = (bool)$input->getOption('dry'); if ($this->dry) { - $this->print("Dry run activated."); + $this->print('Dry run activated.'); } if ($output->isVerbose()) { - $this->print("Verbose mode activated."); + $this->print('Verbose mode activated.'); } // check action, starting point for magic @@ -94,11 +94,11 @@ private function getNextRow():void { $this->offset = $this->row->getId(); } catch (MultipleObjectsReturnedException|Exception $e) { $this->print('Error while fetching row', self::PRINT_LEVEL_ERROR); - $this->logger->error('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->logger->error('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); } catch (DoesNotExistException $e) { - $this->print(""); - $this->print("No more rows found.", self::PRINT_LEVEL_INFO); - $this->print(""); + $this->print(''); + $this->print('No more rows found.', self::PRINT_LEVEL_INFO); + $this->print(''); $this->row = null; } } @@ -113,10 +113,10 @@ private function checkIfColumnsForRowsExists(): void { $this->getNextRow(); while ($this->row) { - $this->print(""); - $this->print(""); - $this->print("Lets check row with id = " . $this->row->getId()); - $this->print("=========================================="); + $this->print(''); + $this->print(''); + $this->print('Lets check row with id = ' . $this->row->getId()); + $this->print('=========================================='); $this->checkColumns(); @@ -131,29 +131,29 @@ private function checkColumns(): void { if (is_array($date->value)) { $date->value = json_encode($date->value); } - $suffix = strlen($date->value) > $this->truncateLength ? "...": ""; - $this->print(""); - $this->print("columnId: " . $date->columnId . " -> " . substr($date->value, 0, $this->truncateLength) . $suffix, self::PRINT_LEVEL_INFO); + $suffix = strlen($date->value) > $this->truncateLength ? '...': ''; + $this->print(''); + $this->print('columnId: ' . $date->columnId . ' -> ' . substr($date->value, 0, $this->truncateLength) . $suffix, self::PRINT_LEVEL_INFO); try { $this->columnService->find($date->columnId, ''); - if($this->output->isVerbose()) { - $this->print("column found", self::PRINT_LEVEL_SUCCESS); + if ($this->output->isVerbose()) { + $this->print('column found', self::PRINT_LEVEL_SUCCESS); } } catch (InternalError $e) { - $this->print("😱️ internal error while looking for column", self::PRINT_LEVEL_ERROR); - $this->logger->error('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->print('😱️ internal error while looking for column', self::PRINT_LEVEL_ERROR); + $this->logger->error('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); } catch (NotFoundError $e) { - if($this->output->isVerbose()) { - $this->print("corresponding column not found.", self::PRINT_LEVEL_ERROR); + if ($this->output->isVerbose()) { + $this->print('corresponding column not found.', self::PRINT_LEVEL_ERROR); } else { - $this->print("columnId: " . $date->columnId . " not found, but needed by row ".$this->row->getId(), self::PRINT_LEVEL_WARNING); + $this->print('columnId: ' . $date->columnId . ' not found, but needed by row ' . $this->row->getId(), self::PRINT_LEVEL_WARNING); } // if the corresponding column is not found, lets delete the data from the row. $this->deleteDataFromRow($date->columnId); } catch (PermissionError $e) { - $this->print("😱️ permission error while looking for column", self::PRINT_LEVEL_ERROR); - $this->logger->error('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->print('😱️ permission error while looking for column', self::PRINT_LEVEL_ERROR); + $this->logger->error('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); } } } @@ -165,11 +165,11 @@ private function checkColumns(): void { */ private function deleteDataFromRow(int $columnId): void { if ($this->dry) { - $this->print("Is dry run, will not remove the column data from row dataset.", self::PRINT_LEVEL_INFO); + $this->print('Is dry run, will not remove the column data from row dataset.', self::PRINT_LEVEL_INFO); return; } - $this->print("DANGER, start deleting", self::PRINT_LEVEL_WARNING); + $this->print('DANGER, start deleting', self::PRINT_LEVEL_WARNING); $data = json_decode($this->row->getData(), true); // $this->print("Data before: \t".json_encode(array_values($data), 0), self::PRINT_LEVEL_INFO); @@ -179,25 +179,25 @@ private function deleteDataFromRow(int $columnId): void { $this->row->setDataArray(array_values($data)); try { $this->rowMapper->update($this->row); - $this->print("Row successfully updated", self::PRINT_LEVEL_SUCCESS); + $this->print('Row successfully updated', self::PRINT_LEVEL_SUCCESS); } catch (Exception $e) { - $this->print("Error while updating row to db.", self::PRINT_LEVEL_ERROR); - $this->logger->error('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->print('Error while updating row to db.', self::PRINT_LEVEL_ERROR); + $this->logger->error('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); } } private function print(string $message, ?int $level = null): void { - if($level === self::PRINT_LEVEL_SUCCESS) { - echo "✅ ".$message; + if ($level === self::PRINT_LEVEL_SUCCESS) { + echo '✅ ' . $message; echo "\n"; } elseif ($level === self::PRINT_LEVEL_INFO && $this->output->isVerbose()) { - echo "ℹ️ ".$message; + echo 'ℹ️ ' . $message; echo "\n"; } elseif ($level === self::PRINT_LEVEL_WARNING) { - echo "⚠️ ".$message; + echo '⚠️ ' . $message; echo "\n"; } elseif ($level === self::PRINT_LEVEL_ERROR) { - echo "❌ ".$message; + echo '❌ ' . $message; echo "\n"; } elseif ($this->output->isVerbose()) { echo $message; diff --git a/lib/Command/ListTables.php b/lib/Command/ListTables.php index 3ef0745e7..a9af05047 100644 --- a/lib/Command/ListTables.php +++ b/lib/Command/ListTables.php @@ -57,8 +57,8 @@ protected function configure(): void { */ protected function execute(InputInterface $input, OutputInterface $output): int { $userId = $input->getArgument('user-id'); - $showCounter = !!$input->getOption('count'); - $noSharedTables = !!$input->getOption('no-shares'); + $showCounter = (bool)$input->getOption('count'); + $noSharedTables = (bool)$input->getOption('no-shares'); $tables = []; try { @@ -69,12 +69,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } catch (InternalError $e) { $output->writeln('Error while reading tables from db.'); - $this->logger->warning('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); return 1; } if ($showCounter) { - $output->writeln(count($tables).' tables'); + $output->writeln(count($tables) . ' tables'); } else { $out = []; foreach ($tables as $table) { diff --git a/lib/Command/RemoveTable.php b/lib/Command/RemoveTable.php index 51e426278..f743d2873 100644 --- a/lib/Command/RemoveTable.php +++ b/lib/Command/RemoveTable.php @@ -51,8 +51,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->tableService->delete($id, ''); $output->writeln('Table deleted.'); } catch (InternalError|PermissionError|Exception $e) { - $output->writeln('Error occurred: '.$e->getMessage()); - $this->logger->warning('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $output->writeln('Error occurred: ' . $e->getMessage()); + $this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); return 1; } return 0; diff --git a/lib/Command/RenameTable.php b/lib/Command/RenameTable.php index b72c0c116..8f656cd86 100644 --- a/lib/Command/RenameTable.php +++ b/lib/Command/RenameTable.php @@ -85,8 +85,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int unset($arr['ownerDisplayName']); $output->writeln(json_encode($arr, JSON_PRETTY_PRINT)); } catch (InternalError $e) { - $output->writeln('Error occurred: '.$e->getMessage()); - $this->logger->warning('Following error occurred during executing occ command "'.self::class.'"', ['exception' => $e]); + $output->writeln('Error occurred: ' . $e->getMessage()); + $this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]); return 1; } return 0; diff --git a/lib/Command/TransferLegacyRows.php b/lib/Command/TransferLegacyRows.php index 54a1e5c42..fce75e008 100644 --- a/lib/Command/TransferLegacyRows.php +++ b/lib/Command/TransferLegacyRows.php @@ -70,31 +70,31 @@ protected function configure(): void { */ protected function execute(InputInterface $input, OutputInterface $output): int { $tableIds = $input->getArgument('table-ids'); - $optionAll = !!$input->getOption('all'); + $optionAll = (bool)$input->getOption('all'); $optionDelete = $input->getOption('delete') ?: null; if ($optionAll) { - $output->writeln("Look for tables"); + $output->writeln('Look for tables'); try { $tables = $this->tableService->findAll('', true, true, false); - $output->writeln("Found ". count($tables) . " table(s)"); + $output->writeln('Found ' . count($tables) . ' table(s)'); } catch (InternalError $e) { - $output->writeln("Error while fetching tables. Will aboard."); + $output->writeln('Error while fetching tables. Will aboard.'); return 1; } } elseif ($tableIds) { - $output->writeln("Look for given table(s)"); + $output->writeln('Look for given table(s)'); $tableIds = explode(',', $tableIds); $tables = []; foreach ($tableIds as $tableId) { try { $tables[] = $this->tableService->find((int)ltrim($tableId), true, ''); } catch (InternalError|NotFoundError|PermissionError $e) { - $output->writeln("Could not load table id " . $tableId . ". Will continue."); + $output->writeln('Could not load table id ' . $tableId . '. Will continue.'); } } } else { - $output->writeln("🤷🏻‍ Add at least one table id or add the option --all to transfer all tables."); + $output->writeln('🤷🏻‍ Add at least one table id or add the option --all to transfer all tables.'); return 2; } if ($optionDelete) { @@ -114,15 +114,15 @@ private function transferDataForTables(array $tables, OutputInterface $output): $i = 1; foreach ($tables as $table) { $output->writeln(''); - $output->writeln("-- Start transfer for table " . $table->getId() . " (" . $table->getTitle() . ") [" . $i . "/" . count($tables) . "]"); + $output->writeln('-- Start transfer for table ' . $table->getId() . ' (' . $table->getTitle() . ') [' . $i . '/' . count($tables) . ']'); try { $this->transferTable($table, $output); } catch (InternalError|PermissionError|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); if ($output->isVerbose()) { - $output->writeln("❌ Error: " . $e->getMessage()); + $output->writeln('❌ Error: ' . $e->getMessage()); } - $output->writeln("⚠️ Could not transfer data. Continue with next table. The logs will have more information about the error: " . $e->getMessage()); + $output->writeln('⚠️ Could not transfer data. Continue with next table. The logs will have more information about the error: ' . $e->getMessage()); } $i++; } @@ -135,15 +135,15 @@ private function transferDataForTables(array $tables, OutputInterface $output): */ private function transferTable(Table $table, OutputInterface $output): void { $columns = $this->columnService->findAllByTable($table->getId(), null, ''); - $output->writeln("---- Found " . count($columns) . " columns"); + $output->writeln('---- Found ' . count($columns) . ' columns'); $legacyRows = $this->legacyRowMapper->findAllByTable($table->getId()); - $output->writeln("---- Found " . count($legacyRows) . " rows"); + $output->writeln('---- Found ' . count($legacyRows) . ' rows'); foreach ($legacyRows as $legacyRow) { $this->legacyRowMapper->transferLegacyRow($legacyRow, $columns); } - $output->writeln("---- ✅ All rows transferred."); + $output->writeln('---- ✅ All rows transferred.'); } /** @@ -152,16 +152,16 @@ private function transferTable(Table $table, OutputInterface $output): void { * @return void */ private function deleteDataForTables(array $tables, OutputInterface $output): void { - $output->writeln("Start deleting data for tables that should be transferred."); + $output->writeln('Start deleting data for tables that should be transferred.'); foreach ($tables as $table) { try { $columns = $this->columnService->findAllByTable($table->getId(), null, ''); } catch (InternalError|PermissionError $e) { - $output->writeln("Could not delete data for table " . $table->getId()); + $output->writeln('Could not delete data for table ' . $table->getId()); break; } $this->rowMapper->deleteAllForTable($table->getId(), $columns); - $output->writeln("🗑️ Data for table " . $table->getId() . " (" . $table->getTitle() . ")" . " removed."); + $output->writeln('🗑️ Data for table ' . $table->getId() . ' (' . $table->getTitle() . ')' . ' removed.'); } } } diff --git a/lib/Controller/AOCSController.php b/lib/Controller/AOCSController.php index 29d494356..1d5d6d318 100644 --- a/lib/Controller/AOCSController.php +++ b/lib/Controller/AOCSController.php @@ -29,7 +29,7 @@ public function __construct( IRequest $request, LoggerInterface $logger, IL10N $n, - string $userId + string $userId, ) { parent::__construct(Application::APP_ID, $request); $this->logger = $logger; diff --git a/lib/Controller/Api1Controller.php b/lib/Controller/Api1Controller.php index bf3accd55..6957b3908 100644 --- a/lib/Controller/Api1Controller.php +++ b/lib/Controller/Api1Controller.php @@ -67,7 +67,7 @@ class Api1Controller extends ApiController { public function __construct( - IRequest $request, + IRequest $request, TableService $service, ShareService $shareService, ColumnService $columnService, @@ -78,7 +78,7 @@ public function __construct( V1Api $v1Api, LoggerInterface $logger, IL10N $l10N, - ?string $userId + ?string $userId, ) { parent::__construct(Application::APP_ID, $request); $this->tableService = $service; @@ -110,7 +110,7 @@ public function index(): DataResponse { try { return new DataResponse($this->tableService->formatTables($this->tableService->findAll($this->userId))); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -134,7 +134,7 @@ public function createTable(string $title, ?string $emoji, string $template = 'c try { return new DataResponse($this->tableService->create($title, $template, $emoji)->jsonSerialize()); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -157,7 +157,7 @@ public function createTable(string $title, ?string $emoji, string $template = 'c public function showScheme(int $tableId): DataResponse { try { $scheme = $this->tableService->getScheme($tableId); - return new DataResponse($scheme->jsonSerialize(), http::STATUS_OK, ['Content-Disposition' => 'attachment; filename="'.$scheme->getTitle() . '.json"', 'Content-Type' => 'application/octet-stream']); + return new DataResponse($scheme->jsonSerialize(), http::STATUS_OK, ['Content-Disposition' => 'attachment; filename="' . $scheme->getTitle() . '.json"', 'Content-Type' => 'application/octet-stream']); } catch (PermissionError $e) { $this->logger->warning('A permission error occurred: ' . $e->getMessage()); $message = ['message' => $e->getMessage()]; @@ -167,7 +167,7 @@ public function showScheme(int $tableId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } catch (InternalError|Exception $e) { - $this->logger->warning('An internal error or exception occurred: '.$e->getMessage()); + $this->logger->warning('An internal error or exception occurred: ' . $e->getMessage()); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -199,7 +199,7 @@ public function getTable(int $tableId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -234,7 +234,7 @@ public function updateTable(int $tableId, ?string $title = null, ?string $emoji $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -266,7 +266,7 @@ public function deleteTable(int $tableId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -300,7 +300,7 @@ public function indexViews(int $tableId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -327,11 +327,11 @@ public function createView(int $tableId, string $title, ?string $emoji): DataRes try { return new DataResponse($this->viewService->create($title, $emoji, $this->tableService->find($tableId))->jsonSerialize()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -355,11 +355,11 @@ public function getView(int $viewId): DataResponse { try { return new DataResponse($this->viewService->find($viewId)->jsonSerialize()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -397,7 +397,7 @@ public function updateView(int $viewId, array $data): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_BAD_REQUEST); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -421,11 +421,11 @@ public function deleteView(int $viewId): DataResponse { try { return new DataResponse($this->viewService->delete($viewId)->jsonSerialize()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -454,11 +454,11 @@ public function getShare(int $shareId): DataResponse { try { return new DataResponse($this->shareService->find($shareId)->jsonSerialize()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -484,7 +484,7 @@ public function indexViewShares(int $viewId): DataResponse { try { return new DataResponse($this->shareService->formatShares($this->shareService->findAll('view', $viewId))); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -506,7 +506,7 @@ public function indexTableShares(int $tableId): DataResponse { try { return new DataResponse($this->shareService->formatShares($this->shareService->findAll('table', $tableId))); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -563,11 +563,11 @@ public function createShare( $displayMode )->jsonSerialize()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -594,11 +594,11 @@ public function deleteShare(int $shareId): DataResponse { try { return new DataResponse($this->shareService->delete($shareId)->jsonSerialize()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -627,11 +627,11 @@ public function updateSharePermissions(int $shareId, string $permissionType, boo try { return new DataResponse($this->shareService->updatePermission($shareId, $permissionType, $permissionValue)->jsonSerialize()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -675,7 +675,7 @@ public function updateShareDisplayMode(int $shareId, int $displayMode, string $t try { return new DataResponse($this->shareService->updateDisplayMode($shareId, $displayMode, $userId)->jsonSerialize()); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -683,7 +683,7 @@ public function updateShareDisplayMode(int $shareId, int $displayMode, string $t $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } @@ -710,11 +710,11 @@ public function indexTableColumns(int $tableId, ?int $viewId): DataResponse { try { return new DataResponse($this->columnService->formatColumns($this->columnService->findAllByTable($tableId, $viewId))); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -739,11 +739,11 @@ public function indexViewColumns(int $viewId): DataResponse { try { return new DataResponse($this->columnService->formatColumns($this->columnService->findAllByView($viewId))); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -823,7 +823,7 @@ public function createColumn( ?bool $usergroupSelectTeams = null, ?bool $usergroupShowUserStatus = null, - ?array $selectedViewIds = [] + ?array $selectedViewIds = [], ): DataResponse { try { return new DataResponse($this->columnService->create( @@ -858,7 +858,7 @@ public function createColumn( $selectedViewIds )->jsonSerialize()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { @@ -969,7 +969,7 @@ public function updateColumn( ); return new DataResponse($item->jsonSerialize()); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1000,7 +1000,7 @@ public function getColumn(int $columnId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1031,7 +1031,7 @@ public function deleteColumn(int $columnId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1061,7 +1061,7 @@ public function indexTableRowsSimple(int $tableId, ?int $limit, ?int $offset): D $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1091,7 +1091,7 @@ public function indexTableRows(int $tableId, ?int $limit, ?int $offset): DataRes $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1121,7 +1121,7 @@ public function indexViewRows(int $viewId, ?int $limit, ?int $offset): DataRespo $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1142,10 +1142,10 @@ public function indexViewRows(int $viewId, ?int $limit, ?int $offset): DataRespo #[CORS] #[RequirePermission(permission: Application::PERMISSION_CREATE, type: Application::NODE_TYPE_VIEW, idParam: 'viewId')] public function createRowInView(int $viewId, $data): DataResponse { - if(is_string($data)) { + if (is_string($data)) { $data = json_decode($data, true); } - if(!is_array($data)) { + if (!is_array($data)) { $this->logger->warning('createRowInView not possible, data array invalid.'); $message = ['message' => $this->l10N->t('Could not create row.')]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); @@ -1154,7 +1154,7 @@ public function createRowInView(int $viewId, $data): DataResponse { $dataNew = []; foreach ($data as $key => $value) { $dataNew[] = [ - 'columnId' => (int) $key, + 'columnId' => (int)$key, 'value' => $value ]; } @@ -1166,7 +1166,7 @@ public function createRowInView(int $viewId, $data): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1188,10 +1188,10 @@ public function createRowInView(int $viewId, $data): DataResponse { #[CORS] #[RequirePermission(permission: Application::PERMISSION_CREATE, type: Application::NODE_TYPE_TABLE, idParam: 'tableId')] public function createRowInTable(int $tableId, $data): DataResponse { - if(is_string($data)) { + if (is_string($data)) { $data = json_decode($data, true); } - if(!is_array($data)) { + if (!is_array($data)) { $this->logger->warning('createRowInTable not possible, data array invalid.'); $message = ['message' => $this->l10N->t('Could not create row.')]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); @@ -1200,7 +1200,7 @@ public function createRowInTable(int $tableId, $data): DataResponse { $dataNew = []; foreach ($data as $key => $value) { $dataNew[] = [ - 'columnId' => (int) $key, + 'columnId' => (int)$key, 'value' => $value ]; } @@ -1212,7 +1212,7 @@ public function createRowInTable(int $tableId, $data): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1239,7 +1239,7 @@ public function getRow(int $rowId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -1266,10 +1266,10 @@ public function getRow(int $rowId): DataResponse { #[NoCSRFRequired] #[CORS] public function updateRow(int $rowId, ?int $viewId, $data): DataResponse { - if(is_string($data)) { + if (is_string($data)) { $data = json_decode($data, true); } - if(!is_array($data)) { + if (!is_array($data)) { $this->logger->warning('updateRow not possible, data array invalid.'); $message = ['message' => $this->l10N->t('Could not update row.')]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); @@ -1277,7 +1277,7 @@ public function updateRow(int $rowId, ?int $viewId, $data): DataResponse { $dataNew = []; foreach ($data as $key => $value) { $dataNew[] = [ - 'columnId' => (int) $key, + 'columnId' => (int)$key, 'value' => $value ]; } @@ -1285,7 +1285,7 @@ public function updateRow(int $rowId, ?int $viewId, $data): DataResponse { try { return new DataResponse($this->rowService->updateSet($rowId, $viewId, $dataNew, $this->userId)->jsonSerialize()); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -1313,7 +1313,7 @@ public function deleteRow(int $rowId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -1345,7 +1345,7 @@ public function deleteRowByView(int $rowId, int $viewId): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -1380,7 +1380,7 @@ public function importInTable(int $tableId, string $path, bool $createMissingCol $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError|MultipleObjectsReturnedException $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError|DoesNotExistException $e) { @@ -1415,7 +1415,7 @@ public function importInView(int $viewId, string $path, bool $createMissingColum $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError|MultipleObjectsReturnedException $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError|DoesNotExistException $e) { @@ -1465,11 +1465,11 @@ public function createTableShare(int $tableId, string $receiver, string $receive )->jsonSerialize() ); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (NotFoundError $e) { @@ -1548,7 +1548,7 @@ public function createTableColumn( ?bool $usergroupSelectGroups = null, ?bool $usergroupSelectTeams = null, ?bool $usergroupShowUserStatus = null, - ?array $selectedViewIds = [] + ?array $selectedViewIds = [], ): DataResponse { try { $item = $this->columnService->create( @@ -1588,7 +1588,7 @@ public function createTableColumn( $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (InternalError $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } catch (DoesNotExistException $e) { diff --git a/lib/Controller/ApiColumnsController.php b/lib/Controller/ApiColumnsController.php index c4b6fda94..e48ff0c3a 100644 --- a/lib/Controller/ApiColumnsController.php +++ b/lib/Controller/ApiColumnsController.php @@ -54,7 +54,7 @@ public function __construct( #[RequirePermission(permission: Application::PERMISSION_READ)] public function index(int $nodeId, string $nodeType): DataResponse { try { - if($nodeType === 'table') { + if ($nodeType === 'table') { $columns = $this->service->findAllByTable($nodeId); } elseif ($nodeType === 'view') { $columns = $this->service->findAllByView($nodeId); @@ -312,7 +312,7 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da */ #[NoAdminRequired] #[RequirePermission(permission: Application::PERMISSION_MANAGE, typeParam: 'baseNodeType', idParam: 'baseNodeId')] - public function createUsergroupColumn(int $baseNodeId, string $title, ?string $usergroupDefault, bool $usergroupMultipleItems = null, bool $usergroupSelectUsers = null, bool $usergroupSelectGroups = null, bool $usergroupSelectTeams = null, bool $showUserStatus = null, string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse { + public function createUsergroupColumn(int $baseNodeId, string $title, ?string $usergroupDefault, ?bool $usergroupMultipleItems = null, ?bool $usergroupSelectUsers = null, ?bool $usergroupSelectGroups = null, ?bool $usergroupSelectTeams = null, ?bool $showUserStatus = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse { $tableId = $baseNodeType === 'table' ? $baseNodeId : null; $viewId = $baseNodeType === 'view' ? $baseNodeId : null; $column = $this->service->create( diff --git a/lib/Controller/ApiGeneralController.php b/lib/Controller/ApiGeneralController.php index 5d387d935..e376ea754 100644 --- a/lib/Controller/ApiGeneralController.php +++ b/lib/Controller/ApiGeneralController.php @@ -29,12 +29,12 @@ class ApiGeneralController extends AOCSController { private ViewService $viewService; public function __construct( - IRequest $request, + IRequest $request, TableService $tableService, ViewService $viewService, LoggerInterface $logger, IL10N $n, - ?string $userId + ?string $userId, ) { parent::__construct($request, $logger, $n, $userId); $this->tableService = $tableService; @@ -58,7 +58,7 @@ public function index(): DataResponse { $views = $this->viewService->formatViews($this->viewService->findSharedViewsWithMe($this->userId)); return new DataResponse([ 'tables' => $tables, 'views' => $views ]); } catch (InternalError|Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } diff --git a/lib/Controller/ApiTablesController.php b/lib/Controller/ApiTablesController.php index 773067f0e..541d0d09e 100644 --- a/lib/Controller/ApiTablesController.php +++ b/lib/Controller/ApiTablesController.php @@ -180,7 +180,7 @@ public function createFromScheme(string $title, string $emoji, string $descripti } $this->db->commit(); return new DataResponse($table->jsonSerialize()); - } catch(InternalError | Exception $e) { + } catch (InternalError|Exception $e) { try { $this->db->rollBack(); } catch (\OCP\DB\Exception $e) { diff --git a/lib/Controller/ColumnController.php b/lib/Controller/ColumnController.php index e70f8517e..0f1073ad3 100644 --- a/lib/Controller/ColumnController.php +++ b/lib/Controller/ColumnController.php @@ -99,7 +99,7 @@ public function create( ?bool $usergroupSelectTeams, ?bool $showUserStatus, - ?array $selectedViewIds + ?array $selectedViewIds, ): DataResponse { return $this->handleError(function () use ( $tableId, @@ -199,7 +199,7 @@ public function update( ?bool $usergroupSelectUsers, ?bool $usergroupSelectGroups, ?bool $usergroupSelectTeams, - ?bool $showUserStatus + ?bool $showUserStatus, ): DataResponse { return $this->handleError(function () use ( $id, diff --git a/lib/Controller/ContextController.php b/lib/Controller/ContextController.php index 4a2e60a75..1fbc79972 100644 --- a/lib/Controller/ContextController.php +++ b/lib/Controller/ContextController.php @@ -33,11 +33,11 @@ class ContextController extends AOCSController { private ContextService $contextService; public function __construct( - IRequest $request, + IRequest $request, LoggerInterface $logger, - IL10N $n, - string $userId, - ContextService $contextService + IL10N $n, + string $userId, + ContextService $contextService, ) { parent::__construct($request, $logger, $n, $userId); $this->contextService = $contextService; diff --git a/lib/Controller/Errors.php b/lib/Controller/Errors.php index c0acb01de..a2f2c4e3a 100644 --- a/lib/Controller/Errors.php +++ b/lib/Controller/Errors.php @@ -21,7 +21,7 @@ protected function handleError(Closure $callback): DataResponse { try { return new DataResponse($callback()); } catch (PermissionError $e) { - $this->logger->warning('A permission error occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_FORBIDDEN); } catch (NotFoundError $e) { @@ -33,7 +33,7 @@ protected function handleError(Closure $callback): DataResponse { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_BAD_REQUEST); } catch (InternalError|\Exception $e) { - $this->logger->error('An internal error or exception occurred: '.$e->getMessage(), ['exception' => $e]); + $this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]); $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR); } diff --git a/lib/Controller/ImportController.php b/lib/Controller/ImportController.php index 5cf53a377..17fab1a3a 100644 --- a/lib/Controller/ImportController.php +++ b/lib/Controller/ImportController.php @@ -97,7 +97,7 @@ public function previewUploadImportTable(int $tableId): DataResponse { return $this->handleError(function () use ($tableId, $file) { return $this->service->previewImport($tableId, null, $file['tmp_name']); }); - } catch (UploadException | NotPermittedException $e) { + } catch (UploadException|NotPermittedException $e) { $this->logger->error('Upload error', ['exception' => $e]); return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } @@ -113,7 +113,7 @@ public function importUploadInTable(int $tableId, bool $createMissingColumns = t // minimal permission is checked, creating columns requires MANAGE permissions - currently tested on service layer return $this->service->import($tableId, null, $file['tmp_name'], $createMissingColumns, $columnsConfigArray); }); - } catch (UploadException | NotPermittedException $e) { + } catch (UploadException|NotPermittedException $e) { $this->logger->error('Upload error', ['exception' => $e]); return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } @@ -127,7 +127,7 @@ public function previewUploadImportView(int $viewId): DataResponse { return $this->handleError(function () use ($viewId, $file) { return $this->service->previewImport(null, $viewId, $file['tmp_name']); }); - } catch (UploadException | NotPermittedException $e) { + } catch (UploadException|NotPermittedException $e) { $this->logger->error('Upload error', ['exception' => $e]); return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } @@ -143,7 +143,7 @@ public function importUploadInView(int $viewId, bool $createMissingColumns = tru // minimal permission is checked, creating columns requires MANAGE permissions - currently tested on service layer return $this->service->import(null, $viewId, $file['tmp_name'], $createMissingColumns, $columnsConfigArray); }); - } catch (UploadException | NotPermittedException $e) { + } catch (UploadException|NotPermittedException $e) { $this->logger->error('Upload error', ['exception' => $e]); return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); } diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index db07f0752..50e766cca 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -28,7 +28,7 @@ public function __construct( string $appName, IRequest $request, INavigationManager $navigationManager, - IURLGenerator $urlGenerator + IURLGenerator $urlGenerator, ) { parent::__construct($appName, $request, $navigationManager, $urlGenerator); } diff --git a/lib/Controller/RowController.php b/lib/Controller/RowController.php index 27dd9a5cf..c5c7ebb39 100644 --- a/lib/Controller/RowController.php +++ b/lib/Controller/RowController.php @@ -67,7 +67,7 @@ public function update( int $columnId, ?int $tableId, ?int $viewId, - string $data + string $data, ): DataResponse { return $this->handleError(function () use ( $id, @@ -84,7 +84,7 @@ public function update( public function updateSet( int $id, ?int $viewId, - array $data + array $data, ): DataResponse { return $this->handleError(function () use ( diff --git a/lib/Db/Column.php b/lib/Db/Column.php index 434deb5a3..d7bd74fc0 100644 --- a/lib/Db/Column.php +++ b/lib/Db/Column.php @@ -199,7 +199,7 @@ public static function fromDto(ColumnDto $data): self { public function getUsergroupDefaultArray():array { $default = $this->getUsergroupDefault(); - if ($default !== "" && $default !== null) { + if ($default !== '' && $default !== null) { return \json_decode($default, true) ?? []; } else { return []; @@ -213,7 +213,7 @@ public function setUsergroupDefaultArray(array $array):void { public function getSelectionOptionsArray():array { $options = $this->getSelectionOptions(); - if ($options !== "" && $options !== null && $options !== 'null') { + if ($options !== '' && $options !== null && $options !== 'null') { return \json_decode($options, true); } else { return []; diff --git a/lib/Db/ColumnMapper.php b/lib/Db/ColumnMapper.php index a417e6969..a72968cce 100644 --- a/lib/Db/ColumnMapper.php +++ b/lib/Db/ColumnMapper.php @@ -124,7 +124,7 @@ public function getColumnTypes(array $neededColumnIds): array { $result = $qb->executeQuery(); try { while ($row = $result->fetch()) { - $out[$row['id']] = $row['type'].($row['subtype'] ? '-'.$row['subtype']: ''); + $out[$row['id']] = $row['type'] . ($row['subtype'] ? '-' . $row['subtype']: ''); } } finally { $result->closeCursor(); @@ -149,7 +149,7 @@ public function countColumns(int $tableId): int { $result = $this->findOneQuery($qb); return (int)$result['counter']; } catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { - $this->logger->warning('Exception occurred: '.$e->getMessage().' Returning 0.'); + $this->logger->warning('Exception occurred: ' . $e->getMessage() . ' Returning 0.'); return 0; } } diff --git a/lib/Db/ColumnTypes/SelectionColumnQB.php b/lib/Db/ColumnTypes/SelectionColumnQB.php index 135412e7f..7b2f41c0c 100644 --- a/lib/Db/ColumnTypes/SelectionColumnQB.php +++ b/lib/Db/ColumnTypes/SelectionColumnQB.php @@ -11,7 +11,7 @@ class SelectionColumnQB extends SuperColumnQB implements IColumnTypeQB { public function passSearchValue(IQueryBuilder $qb, string $unformattedSearchValue, string $operator, string $searchValuePlaceHolder): void { - if(substr($unformattedSearchValue, 0, 1) === '@') { + if (substr($unformattedSearchValue, 0, 1) === '@') { $parts = explode('-', $unformattedSearchValue); $selectedId = intval($parts[2]); $qb->setParameter($searchValuePlaceHolder, $selectedId, IQueryBuilder::PARAM_INT); diff --git a/lib/Db/ColumnTypes/SuperColumnQB.php b/lib/Db/ColumnTypes/SuperColumnQB.php index 9e5d96010..6109f73c4 100644 --- a/lib/Db/ColumnTypes/SuperColumnQB.php +++ b/lib/Db/ColumnTypes/SuperColumnQB.php @@ -27,7 +27,7 @@ public function setPlatform(int $platform): void { public function formatCellValue(string $unformattedValue): string { if ($this->platform === self::DB_PLATFORM_PGSQL) { - return 'LOWER('.$unformattedValue.')'; + return 'LOWER(' . $unformattedValue . ')'; } elseif ($this->platform === self::DB_PLATFORM_SQLITE) { return $unformattedValue; } else { // mariadb / mysql @@ -65,31 +65,31 @@ private function sqlFilterOperation(string $operator, string $formattedCellValue case 'begins-with': case 'ends-with': case 'contains': - return $formattedCellValue.' LIKE :'.$searchValuePlaceHolder; + return $formattedCellValue . ' LIKE :' . $searchValuePlaceHolder; case 'is-equal': - return $formattedCellValue.' = :'.$searchValuePlaceHolder; + return $formattedCellValue . ' = :' . $searchValuePlaceHolder; case 'is-greater-than': - return $formattedCellValue.' > :'.$searchValuePlaceHolder; + return $formattedCellValue . ' > :' . $searchValuePlaceHolder; case 'is-greater-than-or-equal': - return $formattedCellValue.' >= :'.$searchValuePlaceHolder; + return $formattedCellValue . ' >= :' . $searchValuePlaceHolder; case 'is-lower-than': - return $formattedCellValue.' < :'.$searchValuePlaceHolder; + return $formattedCellValue . ' < :' . $searchValuePlaceHolder; case 'is-lower-than-or-equal': - return $formattedCellValue.' <= :'.$searchValuePlaceHolder; + return $formattedCellValue . ' <= :' . $searchValuePlaceHolder; case 'is-empty': - return $formattedCellValue.' = \'\' OR '.$formattedCellValue.' IS NULL'; + return $formattedCellValue . ' = \'\' OR ' . $formattedCellValue . ' IS NULL'; default: - throw new InternalError('Operator '.$operator.' is not supported.'); + throw new InternalError('Operator ' . $operator . ' is not supported.'); } } private function getFormattedDataCellValue(string $columnPlaceHolder, int $columnId): string { if ($this->platform === self::DB_PLATFORM_PGSQL) { - $cellValue = 'c'.$columnId.' ->> \'value\''; + $cellValue = 'c' . $columnId . ' ->> \'value\''; } elseif ($this->platform === self::DB_PLATFORM_SQLITE) { - $cellValue = 'json_extract(t2.value, "$.columnId") = '.$columnId.' AND LOWER(json_extract(t2.value, "$.value"))'; + $cellValue = 'json_extract(t2.value, "$.columnId") = ' . $columnId . ' AND LOWER(json_extract(t2.value, "$.value"))'; } else { - $cellValue = 'JSON_EXTRACT(data, CONCAT( JSON_UNQUOTE(JSON_SEARCH(JSON_EXTRACT(data, \'$[*].columnId\'), \'one\', :'.$columnPlaceHolder.')), \'.value\'))'; + $cellValue = 'JSON_EXTRACT(data, CONCAT( JSON_UNQUOTE(JSON_SEARCH(JSON_EXTRACT(data, \'$[*].columnId\'), \'one\', :' . $columnPlaceHolder . ')), \'.value\'))'; } return $this->formatCellValue($cellValue); @@ -125,10 +125,10 @@ public static function getMetaColumnName(int $metaId): string { * @throws InternalError */ public function addWhereFilterExpression(IQueryBuilder $qb, array $filter, string $filterId): IQueryFunction { - $searchValuePlaceHolder = 'searchValue'.$filterId; // qb parameter binding name + $searchValuePlaceHolder = 'searchValue' . $filterId; // qb parameter binding name $this->passSearchValue($qb, $filter['value'], $filter['operator'], $searchValuePlaceHolder); - $columnPlaceHolder = 'column'.$filterId; // qb parameter binding name - if($filter['columnId'] < 0) { // negative ids for meta data columns + $columnPlaceHolder = 'column' . $filterId; // qb parameter binding name + if ($filter['columnId'] < 0) { // negative ids for meta data columns return $qb->createFunction($this->sqlFilterOperation($filter['operator'], $this->getMetaColumnName($filter['columnId']), $searchValuePlaceHolder)); } diff --git a/lib/Db/ContextMapper.php b/lib/Db/ContextMapper.php index a7e314346..25bb809dd 100644 --- a/lib/Db/ContextMapper.php +++ b/lib/Db/ContextMapper.php @@ -20,7 +20,11 @@ class ContextMapper extends QBMapper { protected string $table = 'tables_contexts_context'; - public function __construct(IDBConnection $db, protected UserHelper $userHelper, protected GroupHelper $groupHelper) { + public function __construct( + IDBConnection $db, + protected UserHelper $userHelper, + protected GroupHelper $groupHelper, + ) { parent::__construct($db, $this->table, Context::class); } @@ -162,7 +166,7 @@ public function findAll(?string $userId = null): array { foreach ($contextIds as $contextId) { $workArray = []; foreach ($r as $row) { - if ((int) $row['id'] === $contextId) { + if ((int)$row['id'] === $contextId) { $workArray[] = $row; } } @@ -212,7 +216,7 @@ public function findForNavBar(string $userId): array { foreach ($contextIds as $contextId) { $workArray = []; foreach ($r as $row) { - if ((int) $row['id'] === $contextId) { + if ((int)$row['id'] === $contextId) { $workArray[] = $row; } } diff --git a/lib/Db/LegacyRow.php b/lib/Db/LegacyRow.php index 746a23e8b..690fecba4 100644 --- a/lib/Db/LegacyRow.php +++ b/lib/Db/LegacyRow.php @@ -60,7 +60,7 @@ public function setDataArray(array $array):void { $new = []; foreach ($array as $a) { $new[] = [ - 'columnId' => (int) $a['columnId'], + 'columnId' => (int)$a['columnId'], 'value' => $a['value'] ]; } diff --git a/lib/Db/LegacyRowMapper.php b/lib/Db/LegacyRowMapper.php index 6a1fad2e4..fe60ebdf2 100644 --- a/lib/Db/LegacyRowMapper.php +++ b/lib/Db/LegacyRowMapper.php @@ -100,9 +100,9 @@ public function find(int $id): LegacyRow { private function buildFilterByColumnType($qb, array $filter, string $filterId): ?IQueryFunction { try { $columnQbClassName = 'OCA\Tables\Db\ColumnTypes\\'; - $type = explode("-", $filter['columnType'])[0]; + $type = explode('-', $filter['columnType'])[0]; - $columnQbClassName .= ucfirst($type).'ColumnQB'; + $columnQbClassName .= ucfirst($type) . 'ColumnQB'; /** @var IColumnTypeQB $columnQb */ $columnQb = Server::get($columnQbClassName); @@ -121,7 +121,7 @@ private function buildFilterByColumnType($qb, array $filter, string $filterId): private function getInnerFilterExpressions(IQueryBuilder $qb, array $filterGroup, int $groupIndex): array { $innerFilterExpressions = []; foreach ($filterGroup as $index => $filter) { - $innerFilterExpressions[] = $this->buildFilterByColumnType($qb, $filter, $groupIndex.$index); + $innerFilterExpressions[] = $this->buildFilterByColumnType($qb, $filter, $groupIndex . $index); } return $innerFilterExpressions; } @@ -156,7 +156,7 @@ private function resolveSearchValue(string $unresolvedSearchValue, string $userI case 'datetime-date-start-of-month': return date('Y-m-01') ? date('Y-m-01') : ''; case 'datetime-date-start-of-week': $day = date('w'); - $result = date('Y-m-d', strtotime('-'.$day.' days')); + $result = date('Y-m-d', strtotime('-' . $day . ' days')); return $result ?: ''; case 'datetime-time-now': return date('H:i'); case 'datetime-now': return date('Y-m-d H:i') ? date('Y-m-d H:i') : ''; @@ -175,7 +175,7 @@ private function addOrderByRules(IQueryBuilder $qb, array $sortArray) { if (!in_array($sortMode, ['ASC', 'DESC'])) { continue; } - $sortColumnPlaceholder = 'sortColumn'.$index; + $sortColumnPlaceholder = 'sortColumn' . $index; if ($sortRule['columnId'] < 0) { try { $orderString = SuperColumnQB::getMetaColumnName($sortRule['columnId']); @@ -184,15 +184,15 @@ private function addOrderByRules(IQueryBuilder $qb, array $sortArray) { } } else { if ($this->platform === IColumnTypeQB::DB_PLATFORM_PGSQL) { - $orderString = 'c'.$sortRule['columnId'].'->>\'value\''; + $orderString = 'c' . $sortRule['columnId'] . '->>\'value\''; } elseif ($this->platform === IColumnTypeQB::DB_PLATFORM_SQLITE) { // here is an error for (multiple) sorting, works only for the first column at the moment $orderString = 'json_extract(t2.value, "$.value")'; } else { // mariadb / mysql - $orderString = 'JSON_EXTRACT(data, CONCAT( JSON_UNQUOTE(JSON_SEARCH(JSON_EXTRACT(data, \'$[*].columnId\'), \'one\', :'.$sortColumnPlaceholder.')), \'.value\'))'; + $orderString = 'JSON_EXTRACT(data, CONCAT( JSON_UNQUOTE(JSON_SEARCH(JSON_EXTRACT(data, \'$[*].columnId\'), \'one\', :' . $sortColumnPlaceholder . ')), \'.value\'))'; } if (str_starts_with($sortRule['columnType'], 'number')) { - $orderString = 'CAST('.$orderString.' as decimal)'; + $orderString = 'CAST(' . $orderString . ' as decimal)'; } } @@ -228,7 +228,7 @@ public function countRowsForView(View $view, $userId): int { $result = $this->findOneQuery($qb); return (int)$result['counter']; } catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { - $this->logger->warning('Exception occurred: '.$e->getMessage().' Returning 0.'); + $this->logger->warning('Exception occurred: ' . $e->getMessage() . ' Returning 0.'); return 0; } } @@ -266,8 +266,8 @@ private function addFilterToQuery(IQueryBuilder $qb, View $view, array $neededCo foreach ($filterGroup as &$filter) { $filter['columnType'] = $neededColumnTypes[$filter['columnId']]; // TODO move resolution for magic fields to service layer - if(str_starts_with((string) $filter['value'], '@')) { - $filter['value'] = $this->resolveSearchValue((string) $filter['value'], $userId); + if (str_starts_with((string)$filter['value'], '@')) { + $filter['value'] = $this->resolveSearchValue((string)$filter['value'], $userId); } } } @@ -364,7 +364,7 @@ private function getAllColumnIdsFromView(View $view, IQueryBuilder $qb): array { foreach ($neededColumnIds as $columnId) { if ($columnId >= 0) { /** @psalm-suppress ImplicitToStringCast */ - $qb->leftJoin("t1", $qb->createFunction('json_array_elements(t1.data)'), 'c' . intval($columnId), $qb->createFunction("CAST(c".intval($columnId).".value->>'columnId' AS int) = ".$columnId)); + $qb->leftJoin('t1', $qb->createFunction('json_array_elements(t1.data)'), 'c' . intval($columnId), $qb->createFunction('CAST(c' . intval($columnId) . ".value->>'columnId' AS int) = " . $columnId)); // TODO Security } } @@ -430,7 +430,7 @@ public function countRows(int $tableId): int { $result = $this->findOneQuery($qb); return (int)$result['counter']; } catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { - $this->logger->warning('Exception occurred: '.$e->getMessage().' Returning 0.'); + $this->logger->warning('Exception occurred: ' . $e->getMessage() . ' Returning 0.'); return 0; } } @@ -489,7 +489,7 @@ public function migrateLegacyRow(LegacyRow $legacyRow, array $columns): Row2 { if ($this->getColumnFromColumnsArray($columnId, $columns)) { $data[] = $legacyDatum; } else { - $this->logger->warning("The row with id " . $row->getId() . " has a value for the column with id " . $columnId . ". But this column does not exist or is not part of the table " . $row->getTableId() . ". Will ignore this value abd continue."); + $this->logger->warning('The row with id ' . $row->getId() . ' has a value for the column with id ' . $columnId . '. But this column does not exist or is not part of the table ' . $row->getTableId() . '. Will ignore this value abd continue.'); } } $row->setData($data); @@ -504,7 +504,7 @@ public function migrateLegacyRow(LegacyRow $legacyRow, array $columns): Row2 { */ private function getColumnFromColumnsArray(int $columnId, array $columns): ?Column { foreach ($columns as $column) { - if($column->getId() === $columnId) { + if ($column->getId() === $columnId) { return $column; } } diff --git a/lib/Db/Row2.php b/lib/Db/Row2.php index b64a6abb0..09c595f0e 100644 --- a/lib/Db/Row2.php +++ b/lib/Db/Row2.php @@ -100,7 +100,7 @@ public function insertOrUpdateCell(array $entry): string { $columnId = $entry['columnId']; $value = $entry['value']; foreach ($this->data as &$cell) { - if($cell['columnId'] === $columnId) { + if ($cell['columnId'] === $columnId) { if ($cell['value'] != $value) { // yes, no type safety here $cell['value'] = $value; $this->addChangedColumnId($columnId); diff --git a/lib/Db/Row2Mapper.php b/lib/Db/Row2Mapper.php index 2cabb62a3..512605ada 100644 --- a/lib/Db/Row2Mapper.php +++ b/lib/Db/Row2Mapper.php @@ -104,7 +104,7 @@ public function find(int $id, array $columns): Row2 { public function findNextId(int $offsetId = -1): ?int { try { $rowSleeve = $this->rowSleeveMapper->findNext($offsetId); - } catch (MultipleObjectsReturnedException | Exception $e) { + } catch (MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (DoesNotExistException $e) { @@ -314,7 +314,7 @@ private function getFilter(IQueryBuilder &$qb, array $filterGroup): array { // if column id is unknown } else { - $e = new Exception("Needed column (" . $columnId . ") not found."); + $e = new Exception('Needed column (' . $columnId . ') not found.'); $this->logger->error($e->getMessage(), ['exception' => $e]); throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } @@ -497,7 +497,7 @@ private function resolveSearchValue(string $placeholder, string $userId): string case 'datetime-date-start-of-month': return date('Y-m-01') ? date('Y-m-01') : ''; case 'datetime-date-start-of-week': $day = date('w'); - $result = date('Y-m-d', strtotime('-'.$day.' days')); + $result = date('Y-m-d', strtotime('-' . $day . ' days')); return $result ?: ''; case 'datetime-time-now': return date('H:i'); case 'datetime-now': return date('Y-m-d H:i') ? date('Y-m-d H:i') : ''; @@ -536,7 +536,7 @@ private function parseEntities(IResult $result, array $sleeves, array $columnTyp $columnType = $this->columns[$rowData['column_id']]->getType(); $cellClassName = 'OCA\Tables\Db\RowCell' . ucfirst($columnType); - $entity = call_user_func($cellClassName .'::fromRowData', $rowData); // >5.2.3 + $entity = call_user_func($cellClassName . '::fromRowData', $rowData); // >5.2.3 $cellMapper = $this->getCellMapperFromType($columnType); $value = $cellMapper->formatEntity($this->columns[$rowData['column_id']], $entity); $compositeKey = (string)$rowData['row_id'] . ',' . (string)$rowData['column_id']; @@ -622,7 +622,7 @@ public function update(Row2 $row, array $columns): Row2 { $sleeve = $this->rowSleeveMapper->find($row->getId()); $this->updateMetaData($sleeve); $this->rowSleeveMapper->update($sleeve); - } catch (DoesNotExistException | MultipleObjectsReturnedException | Exception $e) { + } catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } @@ -686,9 +686,9 @@ private function updateMetaData($entity, bool $setCreate = false, ?string $lastE */ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEditAt = null, ?string $lastEditBy = null): void { if (!isset($this->columns[$columnId])) { - $e = new Exception("Can not insert cell, because the given column-id is not known"); + $e = new Exception('Can not insert cell, because the given column-id is not known'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } @@ -757,7 +757,7 @@ private function insertOrUpdateCell(int $rowId, int $columnId, $value): void { $this->insertCell($rowId, $columnId, $value); } catch (MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -781,13 +781,13 @@ private function getCellMapper(Column $column): RowCellMapperSuper { } private function getCellMapperFromType(string $columnType): RowCellMapperSuper { - $cellMapperClassName = 'OCA\Tables\Db\RowCell'.ucfirst($columnType).'Mapper'; + $cellMapperClassName = 'OCA\Tables\Db\RowCell' . ucfirst($columnType) . 'Mapper'; /** @var RowCellMapperSuper $cellMapper */ try { return Server::get($cellMapperClassName); } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } diff --git a/lib/Db/RowCellNumberMapper.php b/lib/Db/RowCellNumberMapper.php index 38c844716..45a02531f 100644 --- a/lib/Db/RowCellNumberMapper.php +++ b/lib/Db/RowCellNumberMapper.php @@ -20,19 +20,19 @@ public function __construct(IDBConnection $db) { public function formatEntity(Column $column, RowCellSuper $cell) { $value = $cell->getValue(); - if($value === '') { + if ($value === '') { return null; } $decimals = $column->getNumberDecimals() ?? 0; if ($decimals === 0) { - return (int) $value; + return (int)$value; } else { return round(floatval($value), $decimals); } } public function applyDataToEntity(Column $column, RowCellSuper $cell, $data): void { - if(!is_numeric($data)) { + if (!is_numeric($data)) { $cell->setValueWrapper(null); } $cell->setValueWrapper((float)$data); diff --git a/lib/Db/RowCellUsergroupMapper.php b/lib/Db/RowCellUsergroupMapper.php index 55d9a7461..956b1b78e 100644 --- a/lib/Db/RowCellUsergroupMapper.php +++ b/lib/Db/RowCellUsergroupMapper.php @@ -14,7 +14,10 @@ class RowCellUsergroupMapper extends RowCellMapperSuper { protected string $table = 'tables_row_cells_usergroup'; - public function __construct(IDBConnection $db, private IUserManager $userManager) { + public function __construct( + IDBConnection $db, + private IUserManager $userManager, + ) { parent::__construct($db, $this->table, RowCellUsergroup::class); } diff --git a/lib/Db/RowSleeveMapper.php b/lib/Db/RowSleeveMapper.php index a61f7531f..7000ee7d8 100644 --- a/lib/Db/RowSleeveMapper.php +++ b/lib/Db/RowSleeveMapper.php @@ -110,7 +110,7 @@ public function countRows(int $tableId): int { $result = $this->findOneQuery($qb); return (int)$result['counter']; } catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { - $this->logger->warning('Exception occurred: '.$e->getMessage().' Will return 0.'); + $this->logger->warning('Exception occurred: ' . $e->getMessage() . ' Will return 0.'); return 0; } } diff --git a/lib/Db/ShareMapper.php b/lib/Db/ShareMapper.php index 1df77394c..5dc359603 100644 --- a/lib/Db/ShareMapper.php +++ b/lib/Db/ShareMapper.php @@ -71,7 +71,7 @@ public function findShareForNode(int $nodeId, string $nodeType, string $receiver return $items[0]; } } catch (Exception $e) { - $this->logger->warning('Exception occurred while executing SQL statement: '.$e->getMessage()); + $this->logger->warning('Exception occurred while executing SQL statement: ' . $e->getMessage()); } throw new Exception('no shares found as expected'); diff --git a/lib/Db/Table.php b/lib/Db/Table.php index 17f0699bb..02882cb6f 100644 --- a/lib/Db/Table.php +++ b/lib/Db/Table.php @@ -97,10 +97,10 @@ public function jsonSerialize(): array { 'lastEditBy' => $this->lastEditBy ?: '', 'lastEditAt' => $this->lastEditAt ?: '', 'archived' => $this->archived, - 'isShared' => !!$this->isShared, + 'isShared' => (bool)$this->isShared, 'favorite' => $this->favorite, 'onSharePermissions' => $this->getSharePermissions()?->jsonSerialize(), - 'hasShares' => !!$this->hasShares, + 'hasShares' => (bool)$this->hasShares, 'rowsCount' => $this->rowsCount ?: 0, 'columnsCount' => $this->columnsCount ?: 0, 'views' => $this->getViewsArray(), diff --git a/lib/Db/TableMapper.php b/lib/Db/TableMapper.php index 8b450dc50..f78e5e4c3 100644 --- a/lib/Db/TableMapper.php +++ b/lib/Db/TableMapper.php @@ -87,7 +87,7 @@ public function search(?string $term = null, ?string $userId = null, ?int $limit ->andWhere($qb->expr()->eq('receiver_type', $qb->createNamedParameter('user', IQueryBuilder::PARAM_STR))) ->andWhere($qb->expr()->eq('receiver', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))); - if($userGroups) { + if ($userGroups) { $shareQueryTablesSharedViaGroup->selectDistinct('node_id') ->from('tables_shares') ->andWhere($qb->expr()->eq('node_type', $qb->createNamedParameter('table', IQueryBuilder::PARAM_STR))) @@ -102,7 +102,7 @@ public function search(?string $term = null, ?string $userId = null, ?int $limit if ($userId) { $qb->andWhere($qb->expr()->eq('ownership', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))); $qb->orWhere($shareQueryTablesSharedViaUser->expr()->in('id', $qb->createFunction($shareQueryTablesSharedViaUser->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)); - if($userGroups) { + if ($userGroups) { $qb->orWhere($shareQueryTablesSharedViaGroup->expr()->in('id', $qb->createFunction($shareQueryTablesSharedViaGroup->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)); } } diff --git a/lib/Db/View.php b/lib/Db/View.php index 744ba9441..6dc436d05 100644 --- a/lib/Db/View.php +++ b/lib/Db/View.php @@ -114,7 +114,7 @@ public function getFilterArray():array { } private function getArray(?string $json): array { - if ($json !== "" && $json !== null && $json !== 'null') { + if ($json !== '' && $json !== null && $json !== 'null') { return \json_decode($json, true); } else { return []; @@ -162,10 +162,10 @@ public function jsonSerialize(): array { 'lastEditAt' => $this->lastEditAt ?: '', 'columns' => $this->getColumnsArray(), 'sort' => $this->getSortArray(), - 'isShared' => !!$this->isShared, + 'isShared' => (bool)$this->isShared, 'favorite' => $this->favorite, 'onSharePermissions' => $this->getSharePermissions()?->jsonSerialize(), - 'hasShares' => !!$this->hasShares, + 'hasShares' => (bool)$this->hasShares, 'rowsCount' => $this->rowsCount ?: 0, 'ownerDisplayName' => $this->ownerDisplayName, ]; diff --git a/lib/Db/ViewMapper.php b/lib/Db/ViewMapper.php index 09d261d4d..21531efc5 100644 --- a/lib/Db/ViewMapper.php +++ b/lib/Db/ViewMapper.php @@ -19,7 +19,10 @@ class ViewMapper extends QBMapper { protected string $table = 'tables_views'; - public function __construct(IDBConnection $db, private UserHelper $userHelper) { + public function __construct( + IDBConnection $db, + private UserHelper $userHelper, + ) { parent::__construct($db, $this->table, View::class); } @@ -73,7 +76,7 @@ public function search(?string $term = null, ?string $userId = null, ?int $limit ->andWhere($qb->expr()->eq('receiver_type', $qb->createNamedParameter('user', IQueryBuilder::PARAM_STR))) ->andWhere($qb->expr()->eq('receiver', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))); - if($userGroups) { + if ($userGroups) { $shareQueryViewsSharedViaGroup->selectDistinct('node_id') ->from('tables_shares') ->andWhere($qb->expr()->eq('node_type', $qb->createNamedParameter('view', IQueryBuilder::PARAM_STR))) @@ -93,8 +96,8 @@ public function search(?string $term = null, ?string $userId = null, ?int $limit if ($userId) { $qb->where($qb->expr()->eq('ownership', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) - ->orWhere($shareQueryViewsSharedViaUser->expr()->in('v.id', $qb->createFunction($shareQueryViewsSharedViaUser->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)); - if($userGroups) { + ->orWhere($shareQueryViewsSharedViaUser->expr()->in('v.id', $qb->createFunction($shareQueryViewsSharedViaUser->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)); + if ($userGroups) { $qb->orWhere($shareQueryViewsSharedViaGroup->expr()->in('v.id', $qb->createFunction($shareQueryViewsSharedViaGroup->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)); } } diff --git a/lib/Event/TableDeletedEvent.php b/lib/Event/TableDeletedEvent.php index 27d83ed1d..66b6051bc 100644 --- a/lib/Event/TableDeletedEvent.php +++ b/lib/Event/TableDeletedEvent.php @@ -11,7 +11,9 @@ use OCP\EventDispatcher\Event; final class TableDeletedEvent extends Event { - public function __construct(protected Table $table) { + public function __construct( + protected Table $table, + ) { parent::__construct(); } diff --git a/lib/Event/TableOwnershipTransferredEvent.php b/lib/Event/TableOwnershipTransferredEvent.php index 9079ee14a..72b94bea0 100644 --- a/lib/Event/TableOwnershipTransferredEvent.php +++ b/lib/Event/TableOwnershipTransferredEvent.php @@ -11,7 +11,11 @@ use OCP\EventDispatcher\Event; final class TableOwnershipTransferredEvent extends Event { - public function __construct(protected Table $table, protected string $toUserId, protected ?string $fromUserId = null) { + public function __construct( + protected Table $table, + protected string $toUserId, + protected ?string $fromUserId = null, + ) { parent::__construct(); } @@ -19,7 +23,7 @@ public function getTable(): Table { return $this->table; } - public function getFromUserId(): string|null { + public function getFromUserId(): ?string { return $this->fromUserId; } diff --git a/lib/Event/ViewDeletedEvent.php b/lib/Event/ViewDeletedEvent.php index ad99ee8f2..5ead40b29 100644 --- a/lib/Event/ViewDeletedEvent.php +++ b/lib/Event/ViewDeletedEvent.php @@ -11,7 +11,9 @@ use OCP\EventDispatcher\Event; final class ViewDeletedEvent extends Event { - public function __construct(protected View $view) { + public function __construct( + protected View $view, + ) { parent::__construct(); } diff --git a/lib/Helper/CircleHelper.php b/lib/Helper/CircleHelper.php index e40282fab..052229bc9 100644 --- a/lib/Helper/CircleHelper.php +++ b/lib/Helper/CircleHelper.php @@ -27,7 +27,7 @@ class CircleHelper { */ public function __construct( private LoggerInterface $logger, - IAppManager $appManager + IAppManager $appManager, ) { $this->circlesEnabled = $appManager->isEnabledForUser('circles'); $this->circlesManager = null; diff --git a/lib/Helper/UserHelper.php b/lib/Helper/UserHelper.php index e5be4f911..ca7aa7f51 100644 --- a/lib/Helper/UserHelper.php +++ b/lib/Helper/UserHelper.php @@ -45,7 +45,7 @@ private function getUser(string $userId): IUser { if ($user instanceof IUser) { return $user; } - throw new InternalError('User not found for '.$userId); + throw new InternalError('User not found for ' . $userId); } /** diff --git a/lib/Listener/BeforeTemplateRenderedListener.php b/lib/Listener/BeforeTemplateRenderedListener.php index d34836518..7bce96c24 100644 --- a/lib/Listener/BeforeTemplateRenderedListener.php +++ b/lib/Listener/BeforeTemplateRenderedListener.php @@ -18,7 +18,7 @@ */ class BeforeTemplateRenderedListener implements IEventListener { public function __construct( - protected IUserSession $userSession, + protected IUserSession $userSession, protected ContextService $contextService, ) { } diff --git a/lib/Listener/UserDeletedListener.php b/lib/Listener/UserDeletedListener.php index 05b8fbd20..a035deeab 100644 --- a/lib/Listener/UserDeletedListener.php +++ b/lib/Listener/UserDeletedListener.php @@ -34,10 +34,10 @@ public function handle(Event $event): void { try { $tables = $this->tableService->findAll($event->getUser()->getUID(), true, true, false); - $this->logger->info('event "user deleted" was triggered, will try to delete all data for the user: '.$event->getUser()->getUID().' ('.$event->getUser()->getDisplayName().')'); + $this->logger->info('event "user deleted" was triggered, will try to delete all data for the user: ' . $event->getUser()->getUID() . ' (' . $event->getUser()->getDisplayName() . ')'); // delete tables - $this->logger->debug('found '.count($tables).' tables for the user'); + $this->logger->debug('found ' . count($tables) . ' tables for the user'); foreach ($tables as $table) { $this->tableService->delete($table->getId(), $event->getUser()->getUID()); } diff --git a/lib/Listener/WhenRowDeletedAuditLogListener.php b/lib/Listener/WhenRowDeletedAuditLogListener.php index d565221d5..1f8627d7c 100644 --- a/lib/Listener/WhenRowDeletedAuditLogListener.php +++ b/lib/Listener/WhenRowDeletedAuditLogListener.php @@ -16,7 +16,9 @@ * @template-implements IEventListener */ final class WhenRowDeletedAuditLogListener implements IEventListener { - public function __construct(protected AuditLogServiceInterface $auditLogService) { + public function __construct( + protected AuditLogServiceInterface $auditLogService, + ) { } public function handle(Event $event): void { diff --git a/lib/Listener/WhenTableDeletedAuditLogListener.php b/lib/Listener/WhenTableDeletedAuditLogListener.php index 74b3095be..8c58b2c61 100644 --- a/lib/Listener/WhenTableDeletedAuditLogListener.php +++ b/lib/Listener/WhenTableDeletedAuditLogListener.php @@ -16,7 +16,9 @@ * @template-implements IEventListener */ final class WhenTableDeletedAuditLogListener implements IEventListener { - public function __construct(protected AuditLogServiceInterface $auditLogService) { + public function __construct( + protected AuditLogServiceInterface $auditLogService, + ) { } public function handle(Event $event): void { diff --git a/lib/Listener/WhenTableTransferredAuditLogListener.php b/lib/Listener/WhenTableTransferredAuditLogListener.php index bb7928de9..dcf6a6051 100644 --- a/lib/Listener/WhenTableTransferredAuditLogListener.php +++ b/lib/Listener/WhenTableTransferredAuditLogListener.php @@ -16,7 +16,9 @@ * @template-implements IEventListener */ final class WhenTableTransferredAuditLogListener implements IEventListener { - public function __construct(protected AuditLogServiceInterface $auditLogService) { + public function __construct( + protected AuditLogServiceInterface $auditLogService, + ) { } public function handle(Event $event): void { diff --git a/lib/Listener/WhenViewDeletedAuditLogListener.php b/lib/Listener/WhenViewDeletedAuditLogListener.php index 0ad2a7eae..6e0db1348 100644 --- a/lib/Listener/WhenViewDeletedAuditLogListener.php +++ b/lib/Listener/WhenViewDeletedAuditLogListener.php @@ -16,7 +16,9 @@ * @template-implements IEventListener */ final class WhenViewDeletedAuditLogListener implements IEventListener { - public function __construct(protected AuditLogServiceInterface $auditLogService) { + public function __construct( + protected AuditLogServiceInterface $auditLogService, + ) { } public function handle(Event $event): void { diff --git a/lib/Middleware/PermissionMiddleware.php b/lib/Middleware/PermissionMiddleware.php index 4170f2752..fb4f6a1a5 100644 --- a/lib/Middleware/PermissionMiddleware.php +++ b/lib/Middleware/PermissionMiddleware.php @@ -29,9 +29,9 @@ class PermissionMiddleware extends Middleware { public function __construct( IControllerMethodReflector $reflector, - PermissionsService $permissionsService, - IRequest $request, - ?string $userId, + PermissionsService $permissionsService, + IRequest $request, + ?string $userId, ) { $this->reflector = $reflector; diff --git a/lib/Migration/NewDbStructureRepairStep.php b/lib/Migration/NewDbStructureRepairStep.php index 7c230ae66..64ac8219d 100644 --- a/lib/Migration/NewDbStructureRepairStep.php +++ b/lib/Migration/NewDbStructureRepairStep.php @@ -50,22 +50,22 @@ public function getName(): string { * @param IOutput $output */ public function run(IOutput $output) { - $legacyRowTransferRunComplete = $this->config->getAppValue('tables', 'legacyRowTransferRunComplete', "false"); + $legacyRowTransferRunComplete = $this->config->getAppValue('tables', 'legacyRowTransferRunComplete', 'false'); - if ($legacyRowTransferRunComplete === "true") { + if ($legacyRowTransferRunComplete === 'true') { return; } - $output->info("Look for tables"); + $output->info('Look for tables'); try { $tables = $this->tableService->findAll('', true, true, false); - $output->info("Found ". count($tables) . " table(s)"); + $output->info('Found ' . count($tables) . ' table(s)'); } catch (InternalError $e) { - $output->warning("Error while fetching tables. Will aboard."); + $output->warning('Error while fetching tables. Will aboard.'); return; } $this->transferDataForTables($tables, $output); - $this->config->setAppValue('tables', 'legacyRowTransferRunComplete', "true"); + $this->config->setAppValue('tables', 'legacyRowTransferRunComplete', 'true'); } /** @@ -75,12 +75,12 @@ public function run(IOutput $output) { private function transferDataForTables(array $tables, IOutput $output) { $i = 1; foreach ($tables as $table) { - $output->info("-- Start transfer for table " . $table->getId() . " (" . $table->getTitle() . ") [" . $i . "/" . count($tables) . "]"); + $output->info('-- Start transfer for table ' . $table->getId() . ' (' . $table->getTitle() . ') [' . $i . '/' . count($tables) . ']'); try { $this->transferTable($table, $output); } catch (InternalError|PermissionError|Exception|Throwable $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - $output->warning("Could not transfer data. Continue with next table. The logs will have more information about the error: " . $e->getMessage()); + $output->warning('Could not transfer data. Continue with next table. The logs will have more information about the error: ' . $e->getMessage()); } $i++; } @@ -93,10 +93,10 @@ private function transferDataForTables(array $tables, IOutput $output) { */ private function transferTable(Table $table, IOutput $output) { $columns = $this->columnService->findAllByTable($table->getId(), null, ''); - $output->info("---- Found " . count($columns) . " columns"); + $output->info('---- Found ' . count($columns) . ' columns'); $legacyRows = $this->legacyRowMapper->findAllByTable($table->getId()); - $output->info("---- Found " . count($legacyRows) . " rows"); + $output->info('---- Found ' . count($legacyRows) . ' rows'); $output->startProgress(count($legacyRows)); foreach ($legacyRows as $legacyRow) { diff --git a/lib/Migration/Version000000Date20210921000000.php b/lib/Migration/Version000000Date20210921000000.php index 71935daaf..4dc55a254 100644 --- a/lib/Migration/Version000000Date20210921000000.php +++ b/lib/Migration/Version000000Date20210921000000.php @@ -63,7 +63,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ]); $table->setPrimaryKey(['id']); - $table->addIndex(["ownership"], 'tables_tables_ownership'); + $table->addIndex(['ownership'], 'tables_tables_ownership'); } $table = 'tables_columns'; diff --git a/lib/Migration/Version000700Date20230916000000.php b/lib/Migration/Version000700Date20230916000000.php index 0c4694662..8173ff70b 100644 --- a/lib/Migration/Version000700Date20230916000000.php +++ b/lib/Migration/Version000700Date20230916000000.php @@ -66,8 +66,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt } private function createRowValueTable(ISchemaWrapper $schema, string $name, string $type) { - if (!$schema->hasTable('tables_row_cells_'.$name)) { - $table = $schema->createTable('tables_row_cells_'.$name); + if (!$schema->hasTable('tables_row_cells_' . $name)) { + $table = $schema->createTable('tables_row_cells_' . $name); $table->addColumn('id', Types::INTEGER, [ 'autoincrement' => true, 'notnull' => true, diff --git a/lib/Migration/Version000800Date20240712000000.php b/lib/Migration/Version000800Date20240712000000.php index 677903849..b3c4d8e2d 100644 --- a/lib/Migration/Version000800Date20240712000000.php +++ b/lib/Migration/Version000800Date20240712000000.php @@ -27,8 +27,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt } private function createUserGroupTable(ISchemaWrapper $schema, string $name, string $type): ?ISchemaWrapper { - if (!$schema->hasTable('tables_row_cells_'.$name)) { - $table = $schema->createTable('tables_row_cells_'.$name); + if (!$schema->hasTable('tables_row_cells_' . $name)) { + $table = $schema->createTable('tables_row_cells_' . $name); $table->addColumn('id', Types::INTEGER, [ 'autoincrement' => true, 'notnull' => true, diff --git a/lib/Model/Public/Row.php b/lib/Model/Public/Row.php index ad4924eda..d21db098b 100644 --- a/lib/Model/Public/Row.php +++ b/lib/Model/Public/Row.php @@ -28,9 +28,9 @@ public function __construct( /** @readonly */ public int $rowId, /** @readonly */ - public null|array $previousValues = null, + public ?array $previousValues = null, /** @readonly */ - public null|array $values = null, + public ?array $values = null, ) { } diff --git a/lib/Model/TableScheme.php b/lib/Model/TableScheme.php index 0557e7bb4..ca82f7117 100644 --- a/lib/Model/TableScheme.php +++ b/lib/Model/TableScheme.php @@ -16,7 +16,7 @@ class TableScheme implements JsonSerializable { protected ?string $title = null; protected ?string $emoji = null; - /** @var Column[]|null */ + /** @var Column[]|null */ protected ?array $columns = null; /** @var View[]|null */ diff --git a/lib/Reference/ContentReferenceHelper.php b/lib/Reference/ContentReferenceHelper.php index 9ea5455e5..ae161bf7f 100644 --- a/lib/Reference/ContentReferenceHelper.php +++ b/lib/Reference/ContentReferenceHelper.php @@ -73,7 +73,7 @@ public function matchReference(string $referenceText, ?string $type = null): boo */ public function resolveReference(string $referenceText): ?IReference { if ($this->matchReference($referenceText)) { - if($this->matchReference($referenceText, 'table')) { + if ($this->matchReference($referenceText, 'table')) { $elementId = $this->getTableIdFromLink($referenceText); } elseif ($this->matchReference($referenceText, 'view')) { $elementId = $this->getViewIdFromLink($referenceText); @@ -84,16 +84,16 @@ public function resolveReference(string $referenceText): ?IReference { return $this->linkReferenceProvider->resolveReference($referenceText); } try { - if($this->matchReference($referenceText, 'table')) { + if ($this->matchReference($referenceText, 'table')) { $element = $this->tableService->find($elementId, false, $this->userId); } elseif ($this->matchReference($referenceText, 'view')) { $element = $this->viewService->find($elementId, false, $this->userId); } else { - $e = new Exception('Could not map '.$referenceText.' to any known type.'); + $e = new Exception('Could not map ' . $referenceText . ' to any known type.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } - } catch (Exception | Throwable $e) { + } catch (Exception|Throwable $e) { /** @psalm-suppress InvalidReturnStatement */ return $this->linkReferenceProvider->resolveReference($referenceText); } @@ -131,7 +131,7 @@ public function resolveReference(string $referenceText): ?IReference { // add Columns try { - if($this->matchReference($referenceText, 'table')) { + if ($this->matchReference($referenceText, 'table')) { $referenceInfo['columns'] = $this->columnService->findAllByTable($elementId); } elseif ($this->matchReference($referenceText, 'view')) { $referenceInfo['columns'] = $this->columnService->findAllByView($elementId); @@ -141,7 +141,7 @@ public function resolveReference(string $referenceText): ?IReference { // add rows data try { - if($this->matchReference($referenceText, 'table')) { + if ($this->matchReference($referenceText, 'table')) { $referenceInfo['rows'] = $this->rowService->findAllByTable($elementId, $this->userId, 100, 0); } elseif ($this->matchReference($referenceText, 'view')) { $referenceInfo['rows'] = $this->rowService->findAllByView($elementId, $this->userId, 100, 0); diff --git a/lib/Reference/ReferenceHelper.php b/lib/Reference/ReferenceHelper.php index a378a9084..034af148e 100644 --- a/lib/Reference/ReferenceHelper.php +++ b/lib/Reference/ReferenceHelper.php @@ -87,7 +87,7 @@ public function matchReference(string $referenceText, ?string $type = null): boo /** @psalm-suppress InvalidReturnType */ public function resolveReference(string $referenceText): ?IReference { if ($this->matchReference($referenceText)) { - if($this->matchReference($referenceText, 'table')) { + if ($this->matchReference($referenceText, 'table')) { $elementId = $this->getTableIdFromLink($referenceText); } elseif ($this->matchReference($referenceText, 'view')) { $elementId = $this->getViewIdFromLink($referenceText); @@ -99,16 +99,16 @@ public function resolveReference(string $referenceText): ?IReference { return $this->linkReferenceProvider->resolveReference($referenceText); } try { - if($this->matchReference($referenceText, 'table')) { + if ($this->matchReference($referenceText, 'table')) { $element = $this->tableService->find($elementId, false, $this->userId); } elseif ($this->matchReference($referenceText, 'view')) { $element = $this->viewService->find($elementId, false, $this->userId); } else { $e = new Exception('Neither table nor view is given.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } - } catch (Exception | Throwable $e) { + } catch (Exception|Throwable $e) { /** @psalm-suppress InvalidReturnStatement */ return $this->linkReferenceProvider->resolveReference($referenceText); } @@ -141,7 +141,7 @@ public function resolveReference(string $referenceText): ?IReference { // add rows data try { - if($this->matchReference($referenceText, 'table')) { + if ($this->matchReference($referenceText, 'table')) { $referenceInfo['rows'] = $this->rowService->findAllByTable($elementId, $this->userId, 10, 0); } elseif ($this->matchReference($referenceText, 'view')) { $referenceInfo['rows'] = $this->rowService->findAllByView($elementId, $this->userId, 10, 0); @@ -151,7 +151,7 @@ public function resolveReference(string $referenceText): ?IReference { } // set referenceType to { table, view } - if($this->matchReference($referenceText, 'table')) { + if ($this->matchReference($referenceText, 'table')) { $referenceInfo['type'] = 'table'; } elseif ($this->matchReference($referenceText, 'view')) { $referenceInfo['type'] = 'view'; @@ -180,7 +180,7 @@ public function getTableIdFromLink(string $url): ?int { preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/table\/(\d+)(?:\/[^\/]+)*$/i', $url, $matches); } if ($matches && count($matches) > 1) { - return (int) $matches[1]; + return (int)$matches[1]; } return null; @@ -199,7 +199,7 @@ public function getViewIdFromLink(string $url): ?int { preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/view\/(\d+)(?:\/[^\/]+)*$/i', $url, $matches); } if ($matches && count($matches) > 1) { - return (int) $matches[1]; + return (int)$matches[1]; } return null; diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index f605e0cde..104b55526 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -1,4 +1,5 @@ appManager = $appManager; @@ -77,7 +77,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { $limit = $query->getLimit(); $term = $query->getTerm(); $offset = $query->getCursor(); - $offset = $offset ? (int) $offset : 0; + $offset = $offset ? (int)$offset : 0; $appIconUrl = $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg') @@ -91,8 +91,8 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { $formattedTablesResults = array_map(function (Table $table) use ($appIconUrl): SearchResultEntry { return new SearchResultEntry( $appIconUrl, - $table->getEmoji() .' '. $table->getTitle(), - ($table->getOwnerDisplayName() ? $table->getOwnerDisplayName() : $table->getOwnership()) . ', ' . $this->l10n->n('%n row', '%n rows', $table->getRowsCount()).', '.$this->l10n->t('table'), + $table->getEmoji() . ' ' . $table->getTitle(), + ($table->getOwnerDisplayName() ? $table->getOwnerDisplayName() : $table->getOwnership()) . ', ' . $this->l10n->n('%n row', '%n rows', $table->getRowsCount()) . ', ' . $this->l10n->t('table'), $this->getInternalLink($table->getId(), 'table'), '', false @@ -104,8 +104,8 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { $formattedViewResults = array_map(function (View $view) use ($viewIconUrl): SearchResultEntry { return new SearchResultEntry( $viewIconUrl, - $view->getEmoji() .' '. $view->getTitle(), - ($view->getOwnerDisplayName() ? $view->getOwnerDisplayName(): $view->getOwnership()) . ', ' . $this->l10n->n('%n row', '%n rows', $view->getRowsCount()).', '.$this->l10n->t('table view'), + $view->getEmoji() . ' ' . $view->getTitle(), + ($view->getOwnerDisplayName() ? $view->getOwnerDisplayName(): $view->getOwnership()) . ', ' . $this->l10n->n('%n row', '%n rows', $view->getRowsCount()) . ', ' . $this->l10n->t('table view'), $this->getInternalLink($view->getId(), 'view'), '', false @@ -126,9 +126,9 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { */ protected function getInternalLink(int $nodeId, string $nodeType = 'table'): string { $allowedNodeTypes = ['table', 'view']; - if(in_array($nodeType, $allowedNodeTypes)) { + if (in_array($nodeType, $allowedNodeTypes)) { return $this->urlGenerator->linkToRouteAbsolute(Application::APP_ID . '.page.index') - . '#/'.$nodeType.'/' . $nodeId; + . '#/' . $nodeType . '/' . $nodeId; } else { return ''; } diff --git a/lib/Service/ColumnService.php b/lib/Service/ColumnService.php index dc8d034a9..ce8236e0f 100644 --- a/lib/Service/ColumnService.php +++ b/lib/Service/ColumnService.php @@ -48,7 +48,7 @@ public function __construct( ViewService $viewService, RowService $rowService, IL10N $l, - UserHelper $userHelper + UserHelper $userHelper, ) { parent::__construct($logger, $userId, $permissionsService); $this->mapper = $mapper; @@ -70,10 +70,10 @@ public function findAllByTable(int $tableId, ?int $viewId = null, ?string $userI return $this->enhanceColumns($this->mapper->findAllByTable($tableId)); } catch (\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } else { - throw new PermissionError('no read access to table id = '.$tableId); + throw new PermissionError('no read access to table id = ' . $tableId); } } @@ -91,13 +91,13 @@ public function findAllByView(int $viewId, ?string $userId = null): array { $view = $this->viewService->find($viewId, true, $userId); } catch (InternalError|MultipleObjectsReturnedException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (PermissionError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $viewColumnIds = $view->getColumnsArray(); $viewColumns = $this->mapper->findAll($viewColumnIds); @@ -124,7 +124,7 @@ public function find(int $id, ?string $userId = null): Column { // security if (!$this->permissionsService->canReadColumnsByTableId($column->getTableId(), $userId)) { - throw new PermissionError('PermissionError: can not read column with id '.$id); + throw new PermissionError('PermissionError: can not read column with id ' . $id); } return $this->enhanceColumn($column); @@ -155,7 +155,7 @@ public function create( ?int $tableId, ?int $viewId, ColumnDto $columnDto, - array $selectedViewIds = [] + array $selectedViewIds = [], ):Column { // security if ($viewId) { @@ -163,38 +163,38 @@ public function create( $view = $this->viewService->find($viewId); } catch (InternalError|MultipleObjectsReturnedException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (PermissionError $e) { throw new PermissionError('Can not load given view, no permission.'); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } try { $table = $this->tableMapper->find($view->getTableId()); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (MultipleObjectsReturnedException|\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } elseif ($tableId) { try { $table = $this->tableMapper->find($tableId); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (MultipleObjectsReturnedException|\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } else { throw new InternalError('Cannot create column without table or view in context'); } if (!$this->permissionsService->canCreateColumns($table)) { - throw new PermissionError('create column for the table id = '.$table->getId().' is not allowed.'); + throw new PermissionError('create column for the table id = ' . $table->getId() . ' is not allowed.'); } // Add number to title to avoid duplicate @@ -226,9 +226,9 @@ public function create( $entity = $this->mapper->insert($item); } catch (\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } - if(isset($view) && $view) { + if (isset($view) && $view) { // Add columns to view(s) $this->viewService->update($view->getId(), ['columns' => json_encode(array_merge($view->getColumnsArray(), [$entity->getId()]))], $userId, true); } @@ -237,12 +237,12 @@ public function create( $view = $this->viewService->find($viewId); } catch (InternalError|MultipleObjectsReturnedException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (PermissionError $e) { throw new PermissionError('Can not add column to view, no permission.'); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $this->viewService->update($viewId, ['columns' => json_encode(array_merge($view->getColumnsArray(), [$entity->getId()]))], $userId, true); } @@ -262,7 +262,7 @@ public function update( int $columnId, ?int $tableId, ?string $userId, - ColumnDto $columnDto + ColumnDto $columnDto, ):Column { try { /** @var Column $item */ @@ -270,7 +270,7 @@ public function update( // security if (!$this->permissionsService->canUpdateColumnsByTableId($item->getTableId())) { - throw new PermissionError('update column id = '.$columnId.' is not allowed.'); + throw new PermissionError('update column id = ' . $columnId . ' is not allowed.'); } if ($columnDto->getTitle() !== null) { @@ -371,15 +371,15 @@ public function delete(int $id, bool $skipRowCleanup = false, ?string $userId = $item = $this->mapper->find($id); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (MultipleObjectsReturnedException|\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canDeleteColumnsByTableId($item->getTableId(), $userId)) { - throw new PermissionError('delete column id = '.$id.' is not allowed.'); + throw new PermissionError('delete column id = ' . $id . ' is not allowed.'); } if (!$skipRowCleanup) { @@ -387,13 +387,13 @@ public function delete(int $id, bool $skipRowCleanup = false, ?string $userId = $this->rowService->deleteColumnDataFromRows($item); } catch (InternalError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } try { $table = $this->tableMapper->find($item->getTableId()); } catch (DoesNotExistException|MultipleObjectsReturnedException|\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $this->viewService->deleteColumnDataFromViews($id, $table); } @@ -402,7 +402,7 @@ public function delete(int $id, bool $skipRowCleanup = false, ?string $userId = $this->mapper->delete($item); } catch (\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } return $this->enhanceColumn($item); } @@ -425,7 +425,7 @@ public function delete(int $id, bool $skipRowCleanup = false, ?string $userId = public function findOrCreateColumnsByTitleForTableAsArray(?int $tableId, ?int $viewId, array $titles, array $dataTypes, ?string $userId, bool $createUnknownColumns, int &$countCreatedColumns, int &$countMatchingColumns): array { $result = []; - if($userId === null) { + if ($userId === null) { $userId = $this->userId; } if ($viewId) { @@ -435,14 +435,14 @@ public function findOrCreateColumnsByTitleForTableAsArray(?int $tableId, ?int $v } else { $e = new Exception('Either tableId nor viewId is given.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $i = -1; foreach ($titles as $title) { $i++; foreach ($allColumns as $column) { - if($column->getTitle() === $title) { + if ($column->getTitle() === $title) { $result[$i] = $column; $countMatchingColumns++; continue 2; @@ -450,11 +450,11 @@ public function findOrCreateColumnsByTitleForTableAsArray(?int $tableId, ?int $v $result[$i] = ''; } // if there are no columns at all - if(!isset($result[$i])) { + if (!isset($result[$i])) { $result[$i] = ''; } // if column was not found - if($result[$i] === '' && $createUnknownColumns) { + if ($result[$i] === '' && $createUnknownColumns) { $description = $this->l->t('This column was automatically created by the import service.'); $result[$i] = $this->create( $userId, @@ -487,7 +487,7 @@ public function getColumnsCount(int $tableId): int { if ($this->permissionsService->canReadColumnsByTableId($tableId)) { return $this->mapper->countColumns($tableId); } else { - throw new PermissionError('no read access for counting to table id = '.$tableId); + throw new PermissionError('no read access for counting to table id = ' . $tableId); } } diff --git a/lib/Service/ColumnTypes/DatetimeBusiness.php b/lib/Service/ColumnTypes/DatetimeBusiness.php index 24c9a8d70..2d03771b3 100644 --- a/lib/Service/ColumnTypes/DatetimeBusiness.php +++ b/lib/Service/ColumnTypes/DatetimeBusiness.php @@ -30,7 +30,7 @@ public function parseValue($value, ?Column $column = null): string { $dateTime = new DateTime($value); foreach ($allowedFormats as $format) { $tmp = $dateTime->format($format); - if($value === $tmp) { + if ($value === $tmp) { $newDateTime = $dateTime->format('Y-m-d H:i'); } } diff --git a/lib/Service/ColumnTypes/NumberProgressBusiness.php b/lib/Service/ColumnTypes/NumberProgressBusiness.php index 19db19281..e9f2337ec 100644 --- a/lib/Service/ColumnTypes/NumberProgressBusiness.php +++ b/lib/Service/ColumnTypes/NumberProgressBusiness.php @@ -17,7 +17,7 @@ class NumberProgressBusiness extends SuperBusiness implements IColumnTypeBusines * @return string */ public function parseValue($value, ?Column $column = null): string { - return json_encode((int) $value); + return json_encode((int)$value); } /** @@ -26,7 +26,7 @@ public function parseValue($value, ?Column $column = null): string { * @return bool */ public function canBeParsed($value, ?Column $column = null): bool { - return !$value || ((int) $value >= 0 && (int) $value <= 100); + return !$value || ((int)$value >= 0 && (int)$value <= 100); } } diff --git a/lib/Service/ColumnTypes/NumberStarsBusiness.php b/lib/Service/ColumnTypes/NumberStarsBusiness.php index 9d485c66a..a1d59443d 100644 --- a/lib/Service/ColumnTypes/NumberStarsBusiness.php +++ b/lib/Service/ColumnTypes/NumberStarsBusiness.php @@ -17,7 +17,7 @@ class NumberStarsBusiness extends SuperBusiness implements IColumnTypeBusiness { * @return string */ public function parseValue($value, ?Column $column = null): string { - return json_encode((int) $value); + return json_encode((int)$value); } /** @@ -26,7 +26,7 @@ public function parseValue($value, ?Column $column = null): string { * @return bool */ public function canBeParsed($value, ?Column $column = null): bool { - return !$value || in_array((int) $value, [0,1,2,3,4,5]); + return !$value || in_array((int)$value, [0,1,2,3,4,5]); } } diff --git a/lib/Service/ColumnTypes/SelectionBusiness.php b/lib/Service/ColumnTypes/SelectionBusiness.php index 108488bee..7f1be9414 100644 --- a/lib/Service/ColumnTypes/SelectionBusiness.php +++ b/lib/Service/ColumnTypes/SelectionBusiness.php @@ -17,8 +17,8 @@ class SelectionBusiness extends SuperBusiness implements IColumnTypeBusiness { * @return string */ public function parseValue($value, ?Column $column = null): string { - if(!$column) { - $this->logger->warning('No column given, but expected on '.__FUNCTION__.' within '.__CLASS__, ['exception' => new \Exception()]); + if (!$column) { + $this->logger->warning('No column given, but expected on ' . __FUNCTION__ . ' within ' . __CLASS__, ['exception' => new \Exception()]); return ''; } @@ -26,13 +26,13 @@ public function parseValue($value, ?Column $column = null): string { if ((string)$intValue === (string)$value) { // if it seems to be an option ID foreach ($column->getSelectionOptionsArray() as $option) { - if($option['id'] === $intValue && $option['label'] !== $value) { + if ($option['id'] === $intValue && $option['label'] !== $value) { return json_encode($option['id']); } } } else { foreach ($column->getSelectionOptionsArray() as $option) { - if($option['label'] === $value) { + if ($option['label'] === $value) { return json_encode($option['id']); } } @@ -47,25 +47,25 @@ public function parseValue($value, ?Column $column = null): string { * @return bool */ public function canBeParsed($value, ?Column $column = null): bool { - if(!$column) { - $this->logger->warning('No column given, but expected on '.__FUNCTION__.' within '.__CLASS__, ['exception' => new \Exception()]); + if (!$column) { + $this->logger->warning('No column given, but expected on ' . __FUNCTION__ . ' within ' . __CLASS__, ['exception' => new \Exception()]); return false; } - if($value === null) { + if ($value === null) { return true; } - $intValue = (int) $value; - if ((string) $intValue === (string) $value) { + $intValue = (int)$value; + if ((string)$intValue === (string)$value) { // if it seems to be an option ID foreach ($column->getSelectionOptionsArray() as $option) { - if($option['id'] === $intValue && $option['label'] !== $value) { + if ($option['id'] === $intValue && $option['label'] !== $value) { return true; } } } else { foreach ($column->getSelectionOptionsArray() as $option) { - if($option['label'] === $value) { + if ($option['label'] === $value) { return true; } } diff --git a/lib/Service/ColumnTypes/SelectionCheckBusiness.php b/lib/Service/ColumnTypes/SelectionCheckBusiness.php index 87f57ec76..8d396071f 100644 --- a/lib/Service/ColumnTypes/SelectionCheckBusiness.php +++ b/lib/Service/ColumnTypes/SelectionCheckBusiness.php @@ -29,7 +29,7 @@ public function parseValue($value, ?Column $column = null): string { * @return bool */ public function canBeParsed($value, ?Column $column = null): bool { - if($value === null) { + if ($value === null) { return true; } diff --git a/lib/Service/ColumnTypes/SelectionMultiBusiness.php b/lib/Service/ColumnTypes/SelectionMultiBusiness.php index 74567ea04..b6891531d 100644 --- a/lib/Service/ColumnTypes/SelectionMultiBusiness.php +++ b/lib/Service/ColumnTypes/SelectionMultiBusiness.php @@ -19,12 +19,12 @@ class SelectionMultiBusiness extends SuperBusiness implements IColumnTypeBusines * @return string */ public function parseValue($value, ?Column $column = null): string { - if(!$column) { - $this->logger->warning('No column given, but expected on '.__FUNCTION__.' within '.__CLASS__, ['exception' => new \Exception()]); + if (!$column) { + $this->logger->warning('No column given, but expected on ' . __FUNCTION__ . ' within ' . __CLASS__, ['exception' => new \Exception()]); return json_encode([]); } - if($value === null) { + if ($value === null) { return json_encode([]); } @@ -38,8 +38,8 @@ public function parseValue($value, ?Column $column = null): string { $result = []; foreach ($value as $wantedValue) { - if(!$wasString) { - $wantedValue = (int) $wantedValue; + if (!$wasString) { + $wantedValue = (int)$wantedValue; } if ($this->getOptionIdForValue($wantedValue) !== null) { $result[] = $this->getOptionIdForValue($wantedValue); @@ -54,17 +54,17 @@ public function parseValue($value, ?Column $column = null): string { * @return int|null return always the option ID or null */ private function getOptionIdForValue($value): ?int { - if($value === null) { + if ($value === null) { return null; } foreach ($this->options as $option) { - if(is_int($value)) { - if($option['id'] === $value) { + if (is_int($value)) { + if ($option['id'] === $value) { return $option['id']; } } else { - if($option['label'] === $value) { + if ($option['label'] === $value) { return $option['id']; } } @@ -78,12 +78,12 @@ private function getOptionIdForValue($value): ?int { * @return bool */ public function canBeParsed($value, ?Column $column = null): bool { - if(!$column) { - $this->logger->warning('No column given, but expected on '.__FUNCTION__.' within '.__CLASS__, ['exception' => new \Exception()]); + if (!$column) { + $this->logger->warning('No column given, but expected on ' . __FUNCTION__ . ' within ' . __CLASS__, ['exception' => new \Exception()]); return false; } - if($value === null) { + if ($value === null) { return true; } @@ -96,10 +96,10 @@ public function canBeParsed($value, ?Column $column = null): bool { } foreach ($value as $wantedValue) { - if(!$wasString) { - $wantedValue = (int) $wantedValue; + if (!$wasString) { + $wantedValue = (int)$wantedValue; } - if ($this->getOptionIdForValue((int) $wantedValue) === null) { + if ($this->getOptionIdForValue((int)$wantedValue) === null) { return false; } } diff --git a/lib/Service/ColumnTypes/SuperBusiness.php b/lib/Service/ColumnTypes/SuperBusiness.php index 4aaa06d94..c73f7af9d 100644 --- a/lib/Service/ColumnTypes/SuperBusiness.php +++ b/lib/Service/ColumnTypes/SuperBusiness.php @@ -43,7 +43,7 @@ protected function isValidDate(string $dateString, string $format): bool { $newString = $dateTime->format($format); return $newString === $dateString; } catch (\Exception $e) { - $this->logger->warning('Could not validate date: '.$e->getMessage().' Returning false.'); + $this->logger->warning('Could not validate date: ' . $e->getMessage() . ' Returning false.'); return false; } } diff --git a/lib/Service/ColumnTypes/TextLinkBusiness.php b/lib/Service/ColumnTypes/TextLinkBusiness.php index b3e9c3805..29f873ae0 100644 --- a/lib/Service/ColumnTypes/TextLinkBusiness.php +++ b/lib/Service/ColumnTypes/TextLinkBusiness.php @@ -33,7 +33,7 @@ public function parseValue($value, ?Column $column = null): string { // if is json (this is the default case, other formats are backward compatibility $data = json_decode($value, true); - if($data !== null) { + if ($data !== null) { if (isset($data['resourceUrl'])) { return json_encode(json_encode([ 'title' => $data['title'] ?? $data['resourceUrl'], @@ -42,10 +42,10 @@ public function parseValue($value, ?Column $column = null): string { ])); } // at least title and resUrl have to be set - if(isset($data['title']) && isset($data['value'])) { + if (isset($data['title']) && isset($data['value'])) { return json_encode($value); } else { - $this->logger->warning("Link cell value has incomplete json string."); + $this->logger->warning('Link cell value has incomplete json string.'); return ''; } } @@ -77,16 +77,16 @@ public function canBeParsed($value, ?Column $column = null): bool { } $data = json_decode($value, true); - if($data !== null) { + if ($data !== null) { if (!isset($data['resourceUrl']) && !isset($data['value'])) { - $this->logger->error('Value ' . $value . ' cannot be parsed as the column ' . $column->getId(). ' as it contains incomplete data'); + $this->logger->error('Value ' . $value . ' cannot be parsed as the column ' . $column->getId() . ' as it contains incomplete data'); return false; } // Validate url providers $allowedProviders = explode(',', $column->getTextAllowedPattern() ?? '') ?: []; if (isset($data['providerId']) && !in_array($data['providerId'], $allowedProviders)) { - $this->logger->error('Value ' . $value . ' cannot be parsed as the column ' . $column->getId(). ' does not allow the provider: ' . $data['providerId']); + $this->logger->error('Value ' . $value . ' cannot be parsed as the column ' . $column->getId() . ' does not allow the provider: ' . $data['providerId']); return false; } diff --git a/lib/Service/ColumnTypes/UsergroupBusiness.php b/lib/Service/ColumnTypes/UsergroupBusiness.php index 6131c42be..a74c480a3 100644 --- a/lib/Service/ColumnTypes/UsergroupBusiness.php +++ b/lib/Service/ColumnTypes/UsergroupBusiness.php @@ -24,12 +24,12 @@ class UsergroupBusiness extends SuperBusiness implements IColumnTypeBusiness { * @return string */ public function parseValue($value, ?Column $column = null): string { - if(!$column) { - $this->logger->warning('No column given, but expected on '.__FUNCTION__.' within '.__CLASS__, ['exception' => new \Exception()]); + if (!$column) { + $this->logger->warning('No column given, but expected on ' . __FUNCTION__ . ' within ' . __CLASS__, ['exception' => new \Exception()]); return json_encode([]); } - if($value === null) { + if ($value === null) { return json_encode([]); } @@ -42,12 +42,12 @@ public function parseValue($value, ?Column $column = null): string { * @return bool */ public function canBeParsed($value, ?Column $column = null): bool { - if(!$column) { - $this->logger->warning('No column given, but expected on '.__FUNCTION__.' within '.__CLASS__, ['exception' => new \Exception()]); + if (!$column) { + $this->logger->warning('No column given, but expected on ' . __FUNCTION__ . ' within ' . __CLASS__, ['exception' => new \Exception()]); return false; } - if($value === null) { + if ($value === null) { return true; } @@ -56,7 +56,7 @@ public function canBeParsed($value, ?Column $column = null): bool { } foreach ($value as $v) { - if((array_key_exists('id', $v) && !is_string($v['id'])) && (array_key_exists('type', $v) && !is_int($v['type']))) { + if ((array_key_exists('id', $v) && !is_string($v['id'])) && (array_key_exists('type', $v) && !is_int($v['type']))) { return false; } } diff --git a/lib/Service/ContextService.php b/lib/Service/ContextService.php index 07b102f26..e6064ed44 100644 --- a/lib/Service/ContextService.php +++ b/lib/Service/ContextService.php @@ -36,18 +36,18 @@ class ContextService { public function __construct( - private ContextMapper $contextMapper, + private ContextMapper $contextMapper, private ContextNodeRelationMapper $contextNodeRelMapper, - private PageMapper $pageMapper, - private PageContentMapper $pageContentMapper, - private LoggerInterface $logger, - private PermissionsService $permissionsService, - private IUserManager $userManager, - private IEventDispatcher $eventDispatcher, - private IDBConnection $dbc, - private ShareService $shareService, - private bool $isCLI, - protected INavigationManager $navigationManager, + private PageMapper $pageMapper, + private PageContentMapper $pageContentMapper, + private LoggerInterface $logger, + private PermissionsService $permissionsService, + private IUserManager $userManager, + private IEventDispatcher $eventDispatcher, + private IDBConnection $dbc, + private ShareService $shareService, + private bool $isCLI, + protected INavigationManager $navigationManager, protected IURLGenerator $urlGenerator, ) { } diff --git a/lib/Service/FavoritesService.php b/lib/Service/FavoritesService.php index 70931d31c..26c3e3d75 100644 --- a/lib/Service/FavoritesService.php +++ b/lib/Service/FavoritesService.php @@ -26,7 +26,7 @@ class FavoritesService { public function __construct( IDBConnection $connection, PermissionsService $permissionsService, - ?string $userId + ?string $userId, ) { $this->connection = $connection; $this->permissionsService = $permissionsService; diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php index 09813aa35..d1e36aeca 100644 --- a/lib/Service/ImportService.php +++ b/lib/Service/ImportService.php @@ -74,7 +74,7 @@ public function previewImport(?int $tableId, ?int $viewId, string $path): array } else { $e = new \Exception('Neither tableId nor viewId is given.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $this->createUnknownColumns = false; @@ -86,7 +86,7 @@ public function previewImport(?int $tableId, ?int $viewId, string $path): array if ($userFolder->nodeExists($path)) { $file = $userFolder->get($path); $tmpFileName = $file->getStorage()->getLocalFile($file->getInternalPath()); - if($tmpFileName) { + if ($tmpFileName) { $spreadsheet = IOFactory::load($tmpFileName); $previewData = $this->getPreviewData($spreadsheet->getActiveSheet()); } else { @@ -99,7 +99,7 @@ public function previewImport(?int $tableId, ?int $viewId, string $path): array $error = true; } - if($error) { + if ($error) { throw new NotFoundError('File for import could not be found.'); } @@ -215,32 +215,32 @@ public function import(?int $tableId, ?int $viewId, string $path, bool $createMi if ($viewId !== null) { $view = $this->viewService->find($viewId); if (!$this->permissionsService->canCreateRows($view)) { - throw new PermissionError('create row at the view id = '.$viewId.' is not allowed.'); + throw new PermissionError('create row at the view id = ' . $viewId . ' is not allowed.'); } if ($createMissingColumns && !$this->permissionsService->canManageTableById($view->getTableId())) { - throw new PermissionError('create columns at the view id = '.$viewId.' is not allowed.'); + throw new PermissionError('create columns at the view id = ' . $viewId . ' is not allowed.'); } $this->viewId = $viewId; } if ($tableId) { $table = $this->tableService->find($tableId); if (!$this->permissionsService->canCreateRows($table, 'table')) { - throw new PermissionError('create row at the view id = '. (string) $viewId .' is not allowed.'); + throw new PermissionError('create row at the view id = ' . (string)$viewId . ' is not allowed.'); } if ($createMissingColumns && !$this->permissionsService->canManageTable($table)) { - throw new PermissionError('create columns at the view id = '. (string) $viewId .' is not allowed.'); + throw new PermissionError('create columns at the view id = ' . (string)$viewId . ' is not allowed.'); } $this->tableId = $tableId; } if (!$this->tableId && !$this->viewId) { $e = new \Exception('Neither tableId nor viewId is given.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if ($this->tableId && $this->viewId) { $e = new \LogicException('Both table ID and view ID are provided, but only one of them is allowed'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if ($this->userId === null || $this->userManager->get($this->userId) === null) { @@ -258,7 +258,7 @@ public function import(?int $tableId, ?int $viewId, string $path, bool $createMi if ($userFolder->nodeExists($path)) { $file = $userFolder->get($path); $tmpFileName = $file->getStorage()->getLocalFile($file->getInternalPath()); - if($tmpFileName) { + if ($tmpFileName) { $spreadsheet = IOFactory::load($tmpFileName); $this->loop($spreadsheet->getActiveSheet()); } else { @@ -270,7 +270,7 @@ public function import(?int $tableId, ?int $viewId, string $path, bool $createMi } else { $error = true; } - if($error) { + if ($error) { throw new NotFoundError('File for import could not be found.'); } @@ -324,11 +324,11 @@ private function loop(Worksheet $worksheet): void { private function parseValueByColumnType(string $value, Column $column): string { try { $businessClassName = 'OCA\Tables\Service\ColumnTypes\\'; - $businessClassName .= ucfirst($column->getType()).ucfirst($column->getSubtype()).'Business'; + $businessClassName .= ucfirst($column->getType()) . ucfirst($column->getSubtype()) . 'Business'; /** @var IColumnTypeBusiness $columnBusiness */ $columnBusiness = Server::get($businessClassName); - if(!$columnBusiness->canBeParsed($value, $column)) { - $this->logger->warning('Value '.$value.' could not be parsed for column '.$column->getTitle()); + if (!$columnBusiness->canBeParsed($value, $column)) { + $this->logger->warning('Value ' . $value . ' could not be parsed for column ' . $column->getTitle()); $this->countParsingErrors++; return ''; } @@ -359,7 +359,7 @@ private function createRow(Row $row): void { $i++; // only add the dataset if column is known - if(!isset($this->columns[$i]) || $this->columns[$i] === '') { + if (!isset($this->columns[$i]) || $this->columns[$i] === '') { $this->logger->debug('Column unknown while fetching rows data for importing.'); continue; } @@ -368,9 +368,9 @@ private function createRow(Row $row): void { $column = $this->columns[$i]; // if cell is empty - if(!$cell || $cell->getValue() === null) { + if (!$cell || $cell->getValue() === null) { $this->logger->info('Cell is empty while fetching rows data for importing.'); - if($column->getMandatory()) { + if ($column->getMandatory()) { $this->logger->warning('Mandatory column was not set'); $this->countErrors++; return; @@ -432,7 +432,7 @@ private function createRow(Row $row): void { $this->countErrors++; } catch (NotFoundError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (\Throwable $e) { $this->countErrors++; $this->logger->error('Error while creating new row for import.', ['exception' => $e]); @@ -588,7 +588,7 @@ private function parseColumnDataType(Cell $cell): array { 'number_suffix' => 'USD', ]; } elseif (is_float($value)) { - $decimals = strlen(substr(strrchr((string)$value, "."), 1)); + $decimals = strlen(substr(strrchr((string)$value, '.'), 1)); $dataType = [ 'type' => 'number', 'number_decimals' => $decimals, diff --git a/lib/Service/PermissionsService.php b/lib/Service/PermissionsService.php index e35c972a0..6fdd88a3c 100644 --- a/lib/Service/PermissionsService.php +++ b/lib/Service/PermissionsService.php @@ -49,14 +49,14 @@ class PermissionsService { public function __construct( LoggerInterface $logger, - ?string $userId, - TableMapper $tableMapper, - ViewMapper $viewMapper, - ShareMapper $shareMapper, - ContextMapper $contextMapper, - UserHelper $userHelper, - CircleHelper $circleHelper, - bool $isCLI + ?string $userId, + TableMapper $tableMapper, + ViewMapper $viewMapper, + ShareMapper $shareMapper, + ContextMapper $contextMapper, + UserHelper $userHelper, + CircleHelper $circleHelper, + bool $isCLI, ) { $this->tableMapper = $tableMapper; $this->viewMapper = $viewMapper; @@ -84,7 +84,7 @@ public function preCheckUserId(?string $userId = null, bool $canBeEmpty = true): if ($userId === null) { $e = new \Exception(); - $error = 'PreCheck for userId failed, requested in '. get_class($this) .'.'; + $error = 'PreCheck for userId failed, requested in ' . get_class($this) . '.'; $this->logger->debug($error, ['exception' => new \Exception()]); throw new InternalError($error); } @@ -199,7 +199,7 @@ public function canManageElementById(int $elementId, string $nodeType = 'table', } elseif ($nodeType === 'context') { return $this->canManageContextById($elementId, $userId); } else { - throw new InternalError('Cannot read permission for node type '.$nodeType); + throw new InternalError('Cannot read permission for node type ' . $nodeType); } } @@ -230,7 +230,7 @@ public function canManageTableById(int $tableId, ?string $userId = null): bool { $this->logger->warning('No table was found for this id'); return false; } catch (Exception $e) { - $this->logger->warning('Error occurred: '.$e->getMessage()); + $this->logger->warning('Error occurred: ' . $e->getMessage()); return false; } return $this->canManageTable($table, $userId); @@ -245,8 +245,8 @@ public function canManageViewById(int $viewId, ?string $userId = null): bool { } catch (DoesNotExistException $e) { $this->logger->warning('No table was found for this id'); return false; - } catch (InternalError | Exception $e) { - $this->logger->warning('Error occurred: '.$e->getMessage()); + } catch (InternalError|Exception $e) { + $this->logger->warning('Error occurred: ' . $e->getMessage()); return false; } return $this->canManageView($view, $userId); @@ -434,14 +434,14 @@ public function getSharedPermissionsIfSharedWithMe(int $elementId, string $eleme try { $shares = $this->shareMapper->findAllSharesForNodeFor($elementType, $elementId, $userId); } catch (Exception $e) { - $this->logger->warning('Exception occurred: '.$e->getMessage().' Permission denied.'); + $this->logger->warning('Exception occurred: ' . $e->getMessage() . ' Permission denied.'); return new Permissions(); } try { $userGroups = $this->userHelper->getGroupsForUser($userId); } catch (InternalError $e) { - $this->logger->warning('Exception occurred: '.$e->getMessage().' Permission denied.'); + $this->logger->warning('Exception occurred: ' . $e->getMessage() . ' Permission denied.'); return new Permissions(); } $groupShares = []; @@ -449,7 +449,7 @@ public function getSharedPermissionsIfSharedWithMe(int $elementId, string $eleme try { $groupShares[] = $this->shareMapper->findAllSharesForNodeFor($elementType, $elementId, $userGroup->getGid(), 'group'); } catch (Exception $e) { - $this->logger->warning('Exception occurred: '.$e->getMessage().' Permission denied.'); + $this->logger->warning('Exception occurred: ' . $e->getMessage() . ' Permission denied.'); return new Permissions(); } } @@ -503,7 +503,7 @@ public function getSharedPermissionsIfSharedWithMe(int $elementId, string $eleme manage: $manage, ); } - throw new NotFoundError('No share for '.$elementType.' and given user ID found.'); + throw new NotFoundError('No share for ' . $elementType . ' and given user ID found.'); } // private methods ========================================================================== @@ -571,7 +571,7 @@ private function hasPermission(int $existingPermissions, string $permissionName) * @return bool */ private function checkPermission(Table|View|Context $element, string $nodeType, string $permission, ?string $userId = null): bool { - if($this->basisCheck($element, $nodeType, $userId)) { + if ($this->basisCheck($element, $nodeType, $userId)) { return true; } @@ -604,7 +604,7 @@ private function checkPermission(Table|View|Context $element, string $nodeType, * @return bool */ private function checkPermissionById(int $elementId, string $nodeType, string $permission, ?string $userId = null): bool { - if($this->basisCheckById($elementId, $nodeType, $userId)) { + if ($this->basisCheckById($elementId, $nodeType, $userId)) { return true; } if ($userId) { @@ -671,7 +671,7 @@ private function basisCheckById(int $elementId, string $nodeType, ?string &$user $element = $nodeType === 'table' ? $this->tableMapper->find($elementId) : $this->viewMapper->find($elementId); return $this->basisCheck($element, $nodeType, $userId); } catch (DoesNotExistException|MultipleObjectsReturnedException|\Exception $e) { - $this->logger->warning('Exception occurred: '.$e->getMessage()); + $this->logger->warning('Exception occurred: ' . $e->getMessage()); } return false; } diff --git a/lib/Service/RowService.php b/lib/Service/RowService.php index 0f0398a99..2bcdcc01a 100644 --- a/lib/Service/RowService.php +++ b/lib/Service/RowService.php @@ -52,7 +52,7 @@ public function __construct( ViewMapper $viewMapper, TableMapper $tableMapper, Row2Mapper $row2Mapper, - IEventDispatcher $eventDispatcher + IEventDispatcher $eventDispatcher, ) { parent::__construct($logger, $userId, $permissionsService); $this->columnMapper = $columnMapper; @@ -85,7 +85,7 @@ public function findAllByTable(int $tableId, string $userId, ?int $limit = null, $tableColumns = $this->columnMapper->findAllByTable($tableId); return $this->row2Mapper->findAll($tableColumns, $tableColumns, $tableId, $limit, $offset, null, null, $userId); } else { - throw new PermissionError('no read access to table id = '.$tableId); + throw new PermissionError('no read access to table id = ' . $tableId); } } catch (Exception $e) { $this->logger->error($e->getMessage()); @@ -114,7 +114,7 @@ public function findAllByView(int $viewId, string $userId, ?int $limit = null, ? return $this->row2Mapper->findAll($tableColumns, $filterColumns, $view->getTableId(), $limit, $offset, $view->getFilterArray(), $view->getSortArray(), $userId); } else { - throw new PermissionError('no read access to view id = '.$viewId); + throw new PermissionError('no read access to view id = ' . $viewId); } } catch (Exception $e) { $this->logger->error($e->getMessage()); @@ -135,22 +135,22 @@ public function find(int $id): Row2 { $columns = $this->columnMapper->findAllByTable($id); } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } try { $row = $this->row2Mapper->find($id, $columns); } catch (InternalError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage(), $e->getCode(), $e); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage(), $e->getCode(), $e); } catch (NotFoundError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canReadRowsByElementId($row->getTableId(), 'table')) { - throw new PermissionError('PermissionError: can not read row with id '.$id); + throw new PermissionError('PermissionError: can not read row with id ' . $id); } return $row; @@ -171,7 +171,7 @@ public function create(?int $tableId, ?int $viewId, RowDataInput|array $data): R if ($this->userId === null || $this->userId === '') { $e = new \Exception('No user id in context, but needed.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if ($viewId) { @@ -179,15 +179,15 @@ public function create(?int $tableId, ?int $viewId, RowDataInput|array $data): R $view = $this->viewMapper->find($viewId); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError("Given view could not be found. More details can be found in the log."); + throw new NotFoundError('Given view could not be found. More details can be found in the log.'); } catch (InternalError|Exception|MultipleObjectsReturnedException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canCreateRows($view)) { - throw new PermissionError('create row at the view id = '.$viewId.' is not allowed.'); + throw new PermissionError('create row at the view id = ' . $viewId . ' is not allowed.'); } $columns = $this->columnMapper->findMultiple($view->getColumnsArray()); @@ -197,15 +197,15 @@ public function create(?int $tableId, ?int $viewId, RowDataInput|array $data): R $table = $this->tableMapper->find($tableId); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError("Given table could not be found. More details can be found in the log."); + throw new NotFoundError('Given table could not be found. More details can be found in the log.'); } catch (MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canCreateRows($table, 'table')) { - throw new PermissionError('create row at the table id = '.$tableId.' is not allowed.'); + throw new PermissionError('create row at the table id = ' . $tableId . ' is not allowed.'); } $columns = $this->columnMapper->findAllByTable($tableId); @@ -230,7 +230,7 @@ public function create(?int $tableId, ?int $viewId, RowDataInput|array $data): R return $insertedRow; } catch (InternalError|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -246,24 +246,24 @@ public function create(?int $tableId, ?int $viewId, RowDataInput|array $data): R private function cleanupData(RowDataInput|array $data, array $columns, ?int $tableId, ?int $viewId): array { $out = []; foreach ($data as $entry) { - $column = $this->getColumnFromColumnsArray((int) $entry['columnId'], $columns); + $column = $this->getColumnFromColumnsArray((int)$entry['columnId'], $columns); // check if it is allowed to insert a value for the requested column if (!$column && $viewId) { - throw new InternalError('Column with id '.$entry['columnId'].' is not part of view with id '.$viewId); + throw new InternalError('Column with id ' . $entry['columnId'] . ' is not part of view with id ' . $viewId); } elseif (!$column && $tableId) { - throw new InternalError('Column with id '.$entry['columnId'].' is not part of table with id '.$tableId); + throw new InternalError('Column with id ' . $entry['columnId'] . ' is not part of table with id ' . $tableId); } if (!$column) { $e = new \Exception('No column found, can not parse value.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // parse given value to respect the column type value format $out[] = [ - 'columnId' => (int) $entry['columnId'], + 'columnId' => (int)$entry['columnId'], 'value' => $this->parseValueByColumnType($column, $entry['value']) ]; } @@ -278,16 +278,16 @@ private function cleanupData(RowDataInput|array $data, array $columns, ?int $tab private function parseValueByColumnType(Column $column, $value = null) { try { $businessClassName = 'OCA\Tables\Service\ColumnTypes\\'; - $businessClassName .= ucfirst($column->getType()).ucfirst($column->getSubtype()).'Business'; + $businessClassName .= ucfirst($column->getType()) . ucfirst($column->getSubtype()) . 'Business'; /** @var IColumnTypeBusiness $columnBusiness */ $columnBusiness = Server::get($businessClassName); - if($columnBusiness->canBeParsed($value, $column)) { + if ($columnBusiness->canBeParsed($value, $column)) { return json_decode($columnBusiness->parseValue($value, $column), true); } } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) { $this->logger->debug('Column type business class not found', ['exception' => $e]); } - $this->logger->warning('Value could not be parsed for column '.$column->getTitle(), [$value]); + $this->logger->warning('Value could not be parsed for column ' . $column->getTitle(), [$value]); return null; } @@ -298,7 +298,7 @@ private function parseValueByColumnType(Column $column, $value = null) { */ private function getColumnFromColumnsArray(int $columnId, array $columns): ?Column { foreach ($columns as $column) { - if($column->getId() === $columnId) { + if ($column->getId() === $columnId) { return $column; } } @@ -318,16 +318,16 @@ private function getRowById(int $rowId): Row2 { if ($this->row2Mapper->getTableIdForRow($rowId) === null) { $e = new \Exception('No table id in row, but needed.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $row = $this->row2Mapper->find($rowId, $this->columnMapper->findAllByTable($this->row2Mapper->getTableIdForRow($rowId))); $row->markAsLoaded(); } catch (InternalError|DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (NotFoundError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $this->tmpRows[$rowId] = $row; return $row; @@ -351,16 +351,16 @@ public function updateSet( int $id, ?int $viewId, array $data, - string $userId + string $userId, ): Row2 { try { $item = $this->getRowById($id); } catch (InternalError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (NotFoundError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if ($viewId) { @@ -368,29 +368,29 @@ public function updateSet( if (!$this->permissionsService->canReadRowsByElementId($viewId, 'view', $userId)) { $e = new \Exception('Row not found.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if (!$this->permissionsService->canUpdateRowsByViewId($viewId)) { $e = new \Exception('Update row is not allowed.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } try { $view = $this->viewMapper->find($viewId); } catch (InternalError|MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // is row in view? - if(!$this->row2Mapper->isRowInViewPresent($id, $view, $userId)) { + if (!$this->row2Mapper->isRowInViewPresent($id, $view, $userId)) { $e = new \Exception('Update row is not allowed.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // fetch all needed columns @@ -398,7 +398,7 @@ public function updateSet( $columns = $this->columnMapper->findMultiple($view->getColumnsArray()); } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } else { // if no view id is set, we assume a table and take the tableId from the row @@ -408,18 +408,18 @@ public function updateSet( if (!$this->permissionsService->canReadRowsByElementId($item->getTableId(), 'table', $userId)) { $e = new \Exception('Row not found.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if (!$this->permissionsService->canUpdateRowsByTableId($tableId)) { $e = new \Exception('Update row is not allowed.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } try { $columns = $this->columnMapper->findAllByTable($tableId); } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -432,7 +432,7 @@ public function updateSet( if ($column) { $item->insertOrUpdateCell($entry); } else { - $this->logger->warning("Column to update row not found, will continue and ignore this."); + $this->logger->warning('Column to update row not found, will continue and ignore this.'); } } @@ -459,10 +459,10 @@ public function delete(int $id, ?int $viewId, string $userId): Row2 { $item = $this->getRowById($id); } catch (InternalError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (NotFoundError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if ($viewId) { @@ -470,35 +470,35 @@ public function delete(int $id, ?int $viewId, string $userId): Row2 { if (!$this->permissionsService->canReadRowsByElementId($viewId, 'view', $userId)) { $e = new \Exception('Row not found.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if (!$this->permissionsService->canDeleteRowsByViewId($viewId)) { $e = new \Exception('Update row is not allowed.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } try { $view = $this->viewMapper->find($viewId); } catch (InternalError|DoesNotExistException|MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } - if(!$this->row2Mapper->isRowInViewPresent($id, $view, $userId)) { + if (!$this->row2Mapper->isRowInViewPresent($id, $view, $userId)) { $e = new \Exception('Update row is not allowed.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } else { // security if (!$this->permissionsService->canReadRowsByElementId($item->getTableId(), 'table', $userId)) { $e = new \Exception('Row not found.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } if (!$this->permissionsService->canDeleteRowsByTableId($item->getTableId())) { $e = new \Exception('Update row is not allowed.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -512,7 +512,7 @@ public function delete(int $id, ?int $viewId, string $userId): Row2 { return $this->filterRowResult($view ?? null, $deletedRow); } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -526,7 +526,7 @@ public function delete(int $id, ?int $viewId, string $userId): Row2 { public function deleteAllByTable(int $tableId, ?string $userId = null): void { // security if (!$this->permissionsService->canDeleteRowsByTableId($tableId, $userId)) { - throw new PermissionError('delete all rows for table id = '.$tableId.' is not allowed.'); + throw new PermissionError('delete all rows for table id = ' . $tableId . ' is not allowed.'); } $columns = $this->columnMapper->findAllByTable($tableId); @@ -558,7 +558,7 @@ public function getRowsCount(int $tableId): int { if ($this->permissionsService->canReadRowsByElementId($tableId, 'table')) { return $this->row2Mapper->countRowsForTable($tableId); } else { - throw new PermissionError('no read access for counting to table id = '.$tableId); + throw new PermissionError('no read access for counting to table id = ' . $tableId); } } @@ -578,7 +578,7 @@ public function getViewRowsCount(View $view, string $userId): int { return 0; } } else { - throw new PermissionError('no read access for counting to view id = '.$view->getId()); + throw new PermissionError('no read access for counting to view id = ' . $view->getId()); } } diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 7efa12be1..d7ac5934f 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -127,7 +127,7 @@ public function find(int $id):Share { } if (!$this->permissionsService->canReadShare($item)) { - throw new PermissionError('PermissionError: can not read share with id '.$id); + throw new PermissionError('PermissionError: can not read share with id ' . $id); } return $item; @@ -196,7 +196,7 @@ private function findElementsSharedWithMe(string $elementType = 'table', ?string } elseif ($elementType === 'view') { $element = $this->viewMapper->find($share->getNodeId()); } else { - throw new InternalError('Cannot find element of type '.$elementType); + throw new InternalError('Cannot find element of type ' . $elementType); } // Check if en element with this id is already in the result array $index = array_search($element->getId(), array_column($returnArray, 'id')); @@ -221,7 +221,7 @@ public function getSharedPermissionsIfSharedWithMe(int $elementId, string $eleme try { $userId = $this->permissionsService->preCheckUserId($userId); } catch (InternalError $e) { - $this->logger->warning('Could not pre check user: '.$e->getMessage().' Permission denied.'); + $this->logger->warning('Could not pre check user: ' . $e->getMessage() . ' Permission denied.'); return new Permissions(); } return $this->permissionsService->getSharedPermissionsIfSharedWithMe($elementId, $elementType, $userId); @@ -244,7 +244,7 @@ public function create(int $nodeId, string $nodeType, string $receiver, string $ if (!$this->userId) { $e = new \Exception('No user given.'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $time = new DateTime(); $item = new Share(); @@ -299,36 +299,36 @@ public function updatePermission(int $id, string $permission, bool $value): Shar $item = $this->mapper->find($id); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canManageElementById($item->getNodeId(), $item->getNodeType())) { - throw new PermissionError('PermissionError: can not update share with id '.$id); + throw new PermissionError('PermissionError: can not update share with id ' . $id); } $time = new DateTime(); - if ($permission === "read") { + if ($permission === 'read') { $item->setPermissionRead($value); } - if ($permission === "create") { + if ($permission === 'create') { $item->setPermissionCreate($value); } - if ($permission === "update") { + if ($permission === 'update') { $item->setPermissionUpdate($value); } - if ($permission === "delete") { + if ($permission === 'delete') { $item->setPermissionDelete($value); } - if ($permission === "manage") { + if ($permission === 'manage') { $item->setPermissionManage($value); } @@ -338,7 +338,7 @@ public function updatePermission(int $id, string $permission, bool $value): Shar $share = $this->mapper->update($item); } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } return $this->addReceiverDisplayName($share); } @@ -370,10 +370,10 @@ public function updateDisplayMode(int $shareId, int $displayMode, string $userId return $this->contextNavigationMapper->setDisplayModeByShareId($shareId, $displayMode, $userId); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (Exception|MultipleObjectsReturnedException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -389,15 +389,15 @@ public function delete(int $id): Share { $item = $this->mapper->find($id); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (MultipleObjectsReturnedException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canManageElementById($item->getNodeId(), $item->getNodeType())) { - throw new PermissionError('PermissionError: can not delete share with id '.$id); + throw new PermissionError('PermissionError: can not delete share with id ' . $id); } try { @@ -407,7 +407,7 @@ public function delete(int $id): Share { } } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } return $this->addReceiverDisplayName($item); } @@ -449,7 +449,7 @@ public function deleteAllForTable(Table $table):void { try { $this->mapper->deleteByNode($table->getId(), 'table'); } catch (Exception $e) { - $this->logger->error('something went wrong while deleting shares for table: '.$table->getId()); + $this->logger->error('something went wrong while deleting shares for table: ' . $table->getId()); } } @@ -457,7 +457,7 @@ public function deleteAllForView(View $view):void { try { $this->mapper->deleteByNode($view->getId(), 'view'); } catch (Exception $e) { - $this->logger->error('something went wrong while deleting shares for view: '.$view->getId()); + $this->logger->error('something went wrong while deleting shares for view: ' . $view->getId()); } } @@ -472,7 +472,7 @@ public function deleteAllForContext(Context $context): void { $this->mapper->deleteByNode($context->getId(), 'context'); }, $this->dbc); } catch (Exception $e) { - $this->logger->error('something went wrong while deleting shares for context: '.$context->getId()); + $this->logger->error('something went wrong while deleting shares for context: ' . $context->getId()); } } @@ -490,8 +490,8 @@ public function changeSenderForNode(string $nodeType, int $nodeId, string $newOw try { $this->mapper->update($share); } catch (Exception $e) { - $this->logger->warning("Could not update share to change the sender: ".$e->getMessage(), ['exception' => $e]); - throw new InternalError("Could not update share to change the sender"); + $this->logger->warning('Could not update share to change the sender: ' . $e->getMessage(), ['exception' => $e]); + throw new InternalError('Could not update share to change the sender'); } $newShares[] = $share; } diff --git a/lib/Service/Support/DefaultAuditLogService.php b/lib/Service/Support/DefaultAuditLogService.php index 5015d0a4d..68f43dc4b 100644 --- a/lib/Service/Support/DefaultAuditLogService.php +++ b/lib/Service/Support/DefaultAuditLogService.php @@ -11,7 +11,9 @@ use OCP\Log\Audit\CriticalActionPerformedEvent; final class DefaultAuditLogService implements AuditLogServiceInterface { - public function __construct(private IEventDispatcher $eventDispatcher) { + public function __construct( + private IEventDispatcher $eventDispatcher, + ) { } public function log(string $message, array $context): void { diff --git a/lib/Service/TableService.php b/lib/Service/TableService.php index ba70c9e7e..1b0462c74 100644 --- a/lib/Service/TableService.php +++ b/lib/Service/TableService.php @@ -36,22 +36,22 @@ class TableService extends SuperService { public function __construct( - PermissionsService $permissionsService, - LoggerInterface $logger, - ?string $userId, - private TableMapper $mapper, + PermissionsService $permissionsService, + LoggerInterface $logger, + ?string $userId, + private TableMapper $mapper, private TableTemplateService $tableTemplateService, - private ColumnService $columnService, - private RowService $rowService, - private ViewService $viewService, - private ShareService $shareService, - protected UserHelper $userHelper, - protected FavoritesService $favoritesService, - protected IEventDispatcher $eventDispatcher, - private ContextService $contextService, - protected IAppManager $appManager, - protected IL10N $l, - protected Defaults $themingDefaults, + private ColumnService $columnService, + private RowService $rowService, + private ViewService $viewService, + private ShareService $shareService, + protected UserHelper $userHelper, + protected FavoritesService $favoritesService, + protected IEventDispatcher $eventDispatcher, + private ContextService $contextService, + protected IAppManager $appManager, + protected IL10N $l, + protected Defaults $themingDefaults, ) { parent::__construct($logger, $userId, $permissionsService); } @@ -92,7 +92,7 @@ public function findAll(?string $userId = null, bool $skipTableEnhancement = fal $allTables[$tutorialTable->getId()] = $tutorialTable; } catch (InternalError|PermissionError|DoesNotExistException|MultipleObjectsReturnedException|OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -131,7 +131,7 @@ public function findAll(?string $userId = null, bool $skipTableEnhancement = fal } // if the table is shared with me, there are no other shares // will avoid showing the shared icon in the FE nav - if($table->getIsShared()) { + if ($table->getIsShared()) { $table->setHasShares(false); } } @@ -232,7 +232,7 @@ public function find(int $id, bool $skipTableEnhancement = false, ?string $userI // security if (!$this->permissionsService->canReadTable($table, $userId)) { - throw new PermissionError('PermissionError: can not read table with id '.$id); + throw new PermissionError('PermissionError: can not read table with id ' . $id); } if (!$skipTableEnhancement) { @@ -265,7 +265,7 @@ public function create(string $title, string $template, ?string $emoji, ?string $item = new Table(); $item->setTitle($title); $item->setDescription($description); - if($emoji) { + if ($emoji) { $item->setEmoji($emoji); } $item->setOwnership($userId); @@ -284,7 +284,7 @@ public function create(string $title, string $template, ?string $emoji, ?string $table = $this->tableTemplateService->makeTemplate($newTable, $template); } catch (InternalError|PermissionError|DoesNotExistException|MultipleObjectsReturnedException|OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } else { $table = $this->addOwnerDisplayName($newTable); @@ -294,7 +294,7 @@ public function create(string $title, string $template, ?string $emoji, ?string $this->enhanceTable($table, $userId); } catch (InternalError|PermissionError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } return $table; } @@ -319,15 +319,15 @@ public function setOwner(int $id, string $newOwnerUserId, ?string $userId = null $table = $this->mapper->find($id); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (MultipleObjectsReturnedException|OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canChangeElementOwner($table, $userId)) { - throw new PermissionError('PermissionError: can not change table owner with table id '.$id); + throw new PermissionError('PermissionError: can not change table owner with table id ' . $id); } $table->setOwnership($newOwnerUserId); @@ -335,7 +335,7 @@ public function setOwner(int $id, string $newOwnerUserId, ?string $userId = null $table = $this->mapper->update($table); } catch (OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // change owners of related shares @@ -344,7 +344,7 @@ public function setOwner(int $id, string $newOwnerUserId, ?string $userId = null } catch (InternalError $e) { $this->logger->error('Could not update related shares for a table transfer!'); $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $event = new TableOwnershipTransferredEvent( @@ -373,15 +373,15 @@ public function delete(int $id, ?string $userId = null): Table { $item = $this->mapper->find($id); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (MultipleObjectsReturnedException|OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canManageTable($item, $userId)) { - throw new PermissionError('PermissionError: can not delete table with id '.$id); + throw new PermissionError('PermissionError: can not delete table with id ' . $id); } // delete all rows for that table @@ -389,7 +389,7 @@ public function delete(int $id, ?string $userId = null): Table { $this->rowService->deleteAllByTable($id, $userId); } catch (PermissionError|OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // delete all views for that table @@ -399,7 +399,7 @@ public function delete(int $id, ?string $userId = null): Table { $this->viewService->deleteAllByTable($item, $userId); } catch (InternalError|PermissionError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // delete all columns for that table @@ -407,14 +407,14 @@ public function delete(int $id, ?string $userId = null): Table { $columns = $this->columnService->findAllByTable($id, null, $userId); } catch (InternalError|PermissionError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } foreach ($columns as $column) { try { $this->columnService->delete($column->id, true, $userId); } catch (InternalError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -430,7 +430,7 @@ public function delete(int $id, ?string $userId = null): Table { $this->mapper->delete($item); } catch (OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } $event = new TableDeletedEvent(table: $item); @@ -458,15 +458,15 @@ public function update(int $id, ?string $title, ?string $emoji, ?string $descrip $table = $this->mapper->find($id); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (MultipleObjectsReturnedException|OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canUpdateTable($table, $userId)) { - throw new PermissionError('PermissionError: can not update table with id '.$id); + throw new PermissionError('PermissionError: can not update table with id ' . $id); } $time = new DateTime(); @@ -488,13 +488,13 @@ public function update(int $id, ?string $title, ?string $emoji, ?string $descrip $table = $this->mapper->update($table); } catch (OcpDbException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } try { $this->enhanceTable($table, $userId); } catch (InternalError|PermissionError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } return $table; } @@ -515,7 +515,7 @@ public function search(string $term, int $limit = 100, int $offset = 0, ?string $this->enhanceTable($table, $userId); } return $tables; - } catch (InternalError | PermissionError | OcpDbException $e) { + } catch (InternalError|PermissionError|OcpDbException $e) { return []; } } @@ -528,7 +528,7 @@ public function search(string $term, int $limit = 100, int $offset = 0, ?string public function getScheme(int $id): TableScheme { $columns = $this->columnService->findAllByTable($id); $table = $this->find($id); - return new TableScheme($table->getTitle(), $table->getEmoji(), $columns, $table->getViews(), $table->getDescription(), $this->appManager->getAppVersion("tables")); + return new TableScheme($table->getTitle(), $table->getEmoji(), $columns, $table->getViews(), $table->getDescription(), $this->appManager->getAppVersion('tables')); } // PRIVATE FUNCTIONS --------------------------------------------------------------- diff --git a/lib/Service/TableTemplateService.php b/lib/Service/TableTemplateService.php index 800e023e3..099f3060e 100644 --- a/lib/Service/TableTemplateService.php +++ b/lib/Service/TableTemplateService.php @@ -467,8 +467,8 @@ private function makeVacationRequests(Table $table):void { 'title' => $this->l->t('Create Vacation Request'), 'emoji' => '️➕', 'columns' => json_encode([$columns['employee']->getId(), $columns['from']->getId(), $columns['to']->getId(), $columns['workingDays']->getId(), $columns['dateRequest']->getId()]), - 'sort' => json_encode([["columnId" => Column::TYPE_META_UPDATED_AT, "mode" => "ASC"]]), - 'filter' => json_encode([[["columnId" => Column::TYPE_META_CREATED_BY, "operator" => "is-equal", "value" => "@my-name"], ["columnId" => $columns['approved']->getId(), "operator" => "is-empty", "value" => ""]]]), + 'sort' => json_encode([['columnId' => Column::TYPE_META_UPDATED_AT, 'mode' => 'ASC']]), + 'filter' => json_encode([[['columnId' => Column::TYPE_META_CREATED_BY, 'operator' => 'is-equal', 'value' => '@my-name'], ['columnId' => $columns['approved']->getId(), 'operator' => 'is-empty', 'value' => '']]]), ] ); $this->createView($table, @@ -478,8 +478,8 @@ private function makeVacationRequests(Table $table):void { 'columns' => json_encode(array_values(array_map(function ($col) { return $col->getId(); }, $columns))), - 'sort' => json_encode([["columnId" => $columns['from']->getId(), "mode" => "ASC"]]), - 'filter' => json_encode([[["columnId" => $columns['approved']->getId(), "operator" => "is-empty", "value" => ""]]]), + 'sort' => json_encode([['columnId' => $columns['from']->getId(), 'mode' => 'ASC']]), + 'filter' => json_encode([[['columnId' => $columns['approved']->getId(), 'operator' => 'is-empty', 'value' => '']]]), ] ); $this->createView($table, @@ -489,8 +489,8 @@ private function makeVacationRequests(Table $table):void { 'columns' => json_encode(array_values(array_map(function ($col) { return $col->getId(); }, $columns))), - 'sort' => json_encode([["columnId" => Column::TYPE_META_UPDATED_BY, "mode" => "ASC"]]), - 'filter' => json_encode([[["columnId" => Column::TYPE_META_CREATED_BY, "operator" => "is-equal", "value" => "@my-name"]]]), + 'sort' => json_encode([['columnId' => Column::TYPE_META_UPDATED_BY, 'mode' => 'ASC']]), + 'filter' => json_encode([[['columnId' => Column::TYPE_META_CREATED_BY, 'operator' => 'is-equal', 'value' => '@my-name']]]), ] ); $this->createView($table, @@ -500,8 +500,8 @@ private function makeVacationRequests(Table $table):void { 'columns' => json_encode(array_values(array_map(function ($col) { return $col->getId(); }, $columns))), - 'sort' => json_encode([["columnId" => Column::TYPE_META_UPDATED_BY, "mode" => "ASC"]]), - 'filter' => json_encode([[["columnId" => $columns['approved']->getId(), "operator" => "is-equal", "value" => "@checked"]], [["columnId" => $columns['approved']->getId(), "operator" => "is-equal", "value" => "@unchecked"]]]), + 'sort' => json_encode([['columnId' => Column::TYPE_META_UPDATED_BY, 'mode' => 'ASC']]), + 'filter' => json_encode([[['columnId' => $columns['approved']->getId(), 'operator' => 'is-equal', 'value' => '@checked']], [['columnId' => $columns['approved']->getId(), 'operator' => 'is-equal', 'value' => '@unchecked']]]), ] ); } @@ -819,19 +819,19 @@ private function createRow(Table $table, array $values): void { $data = []; foreach ($values as $columnId => $value) { $data[] = [ - 'columnId' => (int) $columnId, + 'columnId' => (int)$columnId, 'value' => $value ]; } try { $this->rowService->create($table->getId(), null, $data); } catch (PermissionError $e) { - $this->logger->warning('Cannot create row, permission denied: '.$e->getMessage()); + $this->logger->warning('Cannot create row, permission denied: ' . $e->getMessage()); } catch (InternalError $e) { - $this->logger->warning('Exception occurred while creating a row: '.$e->getMessage()); + $this->logger->warning('Exception occurred while creating a row: ' . $e->getMessage()); } catch (NotFoundError $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -846,7 +846,7 @@ private function createView(Table $table, array $data): void { $view = $this->viewService->create($data['title'], $data['emoji'], $table); $this->viewService->update($view->getId(), $data); } catch (PermissionError $e) { - $this->logger->warning('Cannot create view, permission denied: '.$e->getMessage()); + $this->logger->warning('Cannot create view, permission denied: ' . $e->getMessage()); } } } diff --git a/lib/Service/ViewService.php b/lib/Service/ViewService.php index 6a52f580e..9b36bd884 100644 --- a/lib/Service/ViewService.php +++ b/lib/Service/ViewService.php @@ -60,7 +60,7 @@ public function __construct( FavoritesService $favoritesService, IEventDispatcher $eventDispatcher, ContextService $contextService, - IL10N $l + IL10N $l, ) { parent::__construct($logger, $userId, $permissionsService); $this->l = $l; @@ -86,7 +86,7 @@ public function findAll(Table $table, ?string $userId = null): array { try { // security if (!$this->permissionsService->canManageTable($table, $userId)) { - throw new PermissionError('PermissionError: can not read views for tableId '.$table->getId()); + throw new PermissionError('PermissionError: can not read views for tableId ' . $table->getId()); } $allViews = $this->mapper->findAll($table->getId()); @@ -128,18 +128,18 @@ public function find(int $id, bool $skipEnhancement = false, ?string $userId = n $view = $this->mapper->find($id); } catch (InternalError|\OCP\DB\Exception|MultipleObjectsReturnedException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canAccessView($view, $userId)) { - throw new PermissionError('PermissionError: can not read view with id '.$id); + throw new PermissionError('PermissionError: can not read view with id ' . $id); } - if(!$skipEnhancement) { + if (!$skipEnhancement) { $this->enhanceView($view, $userId); } @@ -204,7 +204,7 @@ public function create(string $title, ?string $emoji, Table $table, ?string $use $time = new DateTime(); $item = new View(); $item->setTitle($title); - if($emoji) { + if ($emoji) { $item->setEmoji($emoji); } $item->setDescription(''); @@ -311,15 +311,15 @@ public function delete(int $id, ?string $userId = null): View { $view = $this->mapper->find($id); } catch (InternalError|MultipleObjectsReturnedException|\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } catch (DoesNotExistException $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new NotFoundError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } // security if (!$this->permissionsService->canManageView($view, $userId)) { - throw new PermissionError('PermissionError: can not delete view with id '.$id); + throw new PermissionError('PermissionError: can not delete view with id ' . $id); } $this->shareService->deleteAllForView($view); @@ -336,7 +336,7 @@ public function delete(int $id, ?string $userId = null): View { return $deletedView; } catch (\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); + throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } @@ -354,7 +354,7 @@ public function deleteByObject(View $view, ?string $userId = null): View { try { // security if (!$this->permissionsService->canManageView($view, $userId)) { - throw new PermissionError('PermissionError: can not delete view with id '.$view->getId()); + throw new PermissionError('PermissionError: can not delete view with id ' . $view->getId()); } // delete all shares for that table $this->shareService->deleteAllForView($view); @@ -481,7 +481,7 @@ private function enhanceView(View $view, string $userId): void { public function deleteAllByTable(Table $table, ?string $userId = null): void { // security if (!$this->permissionsService->canManageTable($table, $userId)) { - throw new PermissionError('delete all rows for table id = '.$table->getId().' is not allowed.'); + throw new PermissionError('delete all rows for table id = ' . $table->getId() . ' is not allowed.'); } $views = $this->findAll($table, $userId); foreach ($views as $view) { @@ -551,7 +551,7 @@ public function search(string $term, int $limit = 100, int $offset = 0, ?string $this->enhanceView($view, $userId); } return $views; - } catch (InternalError | \OCP\DB\Exception $e) { + } catch (InternalError|\OCP\DB\Exception $e) { return []; } } diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 2d31bb536..c4528c2e4 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -148,7 +148,7 @@ public function userFetchesTableInfo($user, $tableName) { $this->sendOcsRequest( 'GET', - '/apps/tables/api/2/tables/'.$tableId, + '/apps/tables/api/2/tables/' . $tableId, ); $tableToVerify = $this->getDataFromResponse($this->response)['ocs']['data']; @@ -255,7 +255,7 @@ public function updateTableV2(string $user, string $tableName, ?string $title = $this->sendOcsRequest( 'GET', - '/apps/tables/api/2/tables/'.$this->tableIds[$tableName], + '/apps/tables/api/2/tables/' . $this->tableIds[$tableName], ); $previousData = $this->getDataFromResponse($this->response)['ocs']['data']; @@ -273,7 +273,7 @@ public function updateTableV2(string $user, string $tableName, ?string $title = $this->sendOcsRequest( 'PUT', - '/apps/tables/api/2/tables/'.$this->tableIds[$tableName], + '/apps/tables/api/2/tables/' . $this->tableIds[$tableName], $data ); @@ -287,7 +287,7 @@ public function updateTableV2(string $user, string $tableName, ?string $title = $this->sendOcsRequest( 'GET', - '/apps/tables/api/2/tables/'.$updatedTable['id'], + '/apps/tables/api/2/tables/' . $updatedTable['id'], ); $tableToVerify = $this->getDataFromResponse($this->response)['ocs']['data']; @@ -314,7 +314,7 @@ public function transferTableV2(string $user, string $newUser, string $tableName $this->sendOcsRequest( 'PUT', - '/apps/tables/api/2/tables/'.$this->tableIds[$tableName].'/transfer', + '/apps/tables/api/2/tables/' . $this->tableIds[$tableName] . '/transfer', $data ); @@ -339,7 +339,7 @@ public function checkTableOwnershipV2(string $user, string $tableName): void { $this->sendOcsRequest( 'GET', - '/apps/tables/api/2/tables/'.$this->tableIds[$tableName] + '/apps/tables/api/2/tables/' . $this->tableIds[$tableName] ); $table = $this->getDataFromResponse($this->response)['ocs']['data']; @@ -360,7 +360,7 @@ public function deleteTableV2(string $user, string $tableName): void { $this->sendOcsRequest( 'DELETE', - '/apps/tables/api/2/tables/'.$this->tableIds[$tableName] + '/apps/tables/api/2/tables/' . $this->tableIds[$tableName] ); $deletedTable = $this->getDataFromResponse($this->response)['ocs']['data']; @@ -369,7 +369,7 @@ public function deleteTableV2(string $user, string $tableName): void { $this->sendOcsRequest( 'GET', - '/apps/tables/api/2/tables/'.$deletedTable['id'], + '/apps/tables/api/2/tables/' . $deletedTable['id'], ); Assert::assertEquals(404, $this->response->getStatusCode()); @@ -392,15 +392,15 @@ public function createColumnV2(string $nodeType, string $nodeName, string $colum $props = [ 'baseNodeType' => $nodeType, ]; - if($nodeType === 'table') { + if ($nodeType === 'table') { $props['baseNodeId'] = $this->tableIds[$nodeName]; } - if($nodeType === 'view') { + if ($nodeType === 'view') { $props['baseNodeId'] = $this->viewIds[$nodeName]; } $title = null; foreach ($properties->getRows() as $row) { - if($row[0] === 'title') { + if ($row[0] === 'title') { $title = $row[1]; } $props[$row[0]] = $row[1]; @@ -408,7 +408,7 @@ public function createColumnV2(string $nodeType, string $nodeName, string $colum $this->sendOcsRequest( 'POST', - '/apps/tables/api/2/columns/'.$columnType, + '/apps/tables/api/2/columns/' . $columnType, $props ); @@ -420,7 +420,7 @@ public function createColumnV2(string $nodeType, string $nodeName, string $colum $this->sendOcsRequest( 'GET', - '/apps/tables/api/2/columns/'.$newColumn['id'], + '/apps/tables/api/2/columns/' . $newColumn['id'], ); $columnToVerify = $this->getDataFromResponse($this->response)['ocs']['data']; @@ -437,16 +437,16 @@ public function createColumnV2(string $nodeType, string $nodeName, string $colum */ public function columnsForNodeV2(string $nodeType, string $nodeName, ?TableNode $body = null): void { $nodeId = null; - if($nodeType === 'table') { + if ($nodeType === 'table') { $nodeId = $this->tableIds[$nodeName]; } - if($nodeType === 'view') { + if ($nodeType === 'view') { $nodeId = $this->viewIds[$nodeName]; } $this->sendOcsRequest( 'GET', - '/apps/tables/api/2/columns/'.$nodeType.'/'.$nodeId + '/apps/tables/api/2/columns/' . $nodeType . '/' . $nodeId ); $data = $this->getDataFromResponse($this->response)['ocs']['data']; @@ -498,7 +498,7 @@ public function uploadFile(string $user, string $file): void { */ public function createCsvFile(string $user, string $file, ?TableNode $table = null): void { $this->setCurrentUser($user); - $url = $this->baseUrl.'remote.php/dav/files/'.$user.$file; + $url = $this->baseUrl . 'remote.php/dav/files/' . $user . $file; $body = $this->tableNodeToCsv($table); $headers = ['Content-Type' => 'text/csv']; @@ -511,8 +511,8 @@ private function tableNodeToCsv(TableNode $node): string { $out = ''; foreach ($node->getRows() as $row) { foreach ($row as $value) { - if($out !== '' && substr($out, -1) !== "\n") { - $out .= ","; + if ($out !== '' && substr($out, -1) !== "\n") { + $out .= ','; } $out .= trim($value); } @@ -529,7 +529,7 @@ private function tableNodeToCsv(TableNode $node): string { public function importTable(string $file): void { $this->sendRequest( 'POST', - '/apps/tables/api/1/import/table/'.$this->tableId, + '/apps/tables/api/1/import/table/' . $this->tableId, [ 'path' => $file, 'createMissingColumns' => true, @@ -577,7 +577,7 @@ public function printRegister(): void { public function checkRowsExists(TableNode $table): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/tables/'.$this->tableId.'/rows/simple', + '/apps/tables/api/1/tables/' . $this->tableId . '/rows/simple', ); $allRows = $this->getDataFromResponse($this->response); @@ -653,7 +653,7 @@ public function tableViews(string $tableName, string $user, ?TableNode $body = n $this->sendRequest( 'GET', - '/apps/tables/api/1/tables/'.$this->tableIds[$tableName].'/views' + '/apps/tables/api/1/tables/' . $this->tableIds[$tableName] . '/views' ); $data = $this->getDataFromResponse($this->response); @@ -689,7 +689,7 @@ public function createView(string $user, string $title, string $tableName, strin $this->setCurrentUser($user); $this->sendRequest( 'POST', - '/apps/tables/api/1/tables/'.$this->tableIds[$tableName].'/views', + '/apps/tables/api/1/tables/' . $this->tableIds[$tableName] . '/views', [ 'title' => $title, 'emoji' => $emoji @@ -710,7 +710,7 @@ public function createView(string $user, string $title, string $tableName, strin $this->sendRequest( 'GET', - '/apps/tables/api/1/views/'.$newItem['id'], + '/apps/tables/api/1/views/' . $newItem['id'], ); $itemToVerify = $this->getDataFromResponse($this->response); @@ -750,7 +750,7 @@ public function createTable(string $user, string $title, string $tableName, ?str $this->sendRequest( 'GET', - '/apps/tables/api/1/tables/'.$newTable['id'], + '/apps/tables/api/1/tables/' . $newTable['id'], ); $tableToVerify = $this->getDataFromResponse($this->response); @@ -763,7 +763,7 @@ public function createTable(string $user, string $title, string $tableName, ?str private function getTableByKeyword(string $keyword) { $this->sendRequest( 'GET', - '/apps/tables/api/1/tables?keyword='.$keyword + '/apps/tables/api/1/tables?keyword=' . $keyword ); $tables = $this->getDataFromResponse($this->response); @@ -773,7 +773,7 @@ private function getTableByKeyword(string $keyword) { private function getTableById(int $tableId): array { $this->sendRequest( 'GET', - '/apps/tables/api/1/tables/'.$tableId + '/apps/tables/api/1/tables/' . $tableId ); return $this->getDataFromResponse($this->response); @@ -798,7 +798,7 @@ public function updateTable(string $user, string $title, ?string $emoji, string $this->sendRequest( 'PUT', - '/apps/tables/api/1/tables/'.$table['id'], + '/apps/tables/api/1/tables/' . $table['id'], $data ); @@ -811,7 +811,7 @@ public function updateTable(string $user, string $title, ?string $emoji, string $this->sendRequest( 'GET', - '/apps/tables/api/1/tables/'.$updatedTable['id'], + '/apps/tables/api/1/tables/' . $updatedTable['id'], ); $tableToVerify = $this->getDataFromResponse($this->response); @@ -839,7 +839,7 @@ public function updateView(string $user, string $viewName, string $title, ?strin $this->sendRequest( 'PUT', - '/apps/tables/api/1/views/'.$this->viewIds[$viewName], + '/apps/tables/api/1/views/' . $this->viewIds[$viewName], [ 'data' => $data ] ); @@ -851,7 +851,7 @@ public function updateView(string $user, string $viewName, string $title, ?strin $this->sendRequest( 'GET', - '/apps/tables/api/1/views/'.$updatedItem['id'], + '/apps/tables/api/1/views/' . $updatedItem['id'], ); $itemToVerify = $this->getDataFromResponse($this->response); @@ -901,7 +901,7 @@ public function deleteView(string $user, string $viewName): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/views/'.$deletedItem['id'], + '/apps/tables/api/1/views/' . $deletedItem['id'], ); Assert::assertEquals(404, $this->response->getStatusCode()); @@ -916,7 +916,7 @@ public function deleteViewWithoutAssertion(string $user, string $viewName): bool $this->sendRequest( 'DELETE', - '/apps/tables/api/1/views/'.$this->viewIds[$viewName] + '/apps/tables/api/1/views/' . $this->viewIds[$viewName] ); return true; } @@ -933,7 +933,7 @@ public function deleteTable(string $user, string $keyword): void { $this->sendRequest( 'DELETE', - '/apps/tables/api/1/tables/'.$table['id'] + '/apps/tables/api/1/tables/' . $table['id'] ); $deletedTable = $this->getDataFromResponse($this->response); @@ -947,7 +947,7 @@ public function deleteTable(string $user, string $keyword): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/tables/'.$deletedTable['id'], + '/apps/tables/api/1/tables/' . $deletedTable['id'], ); Assert::assertEquals(404, $this->response->getStatusCode()); @@ -998,7 +998,7 @@ public function shareTableWithUser(string $user, string $receiver): void { ]; $this->sendRequest( 'POST', - '/apps/tables/api/1/tables/'.$table['id'].'/shares', + '/apps/tables/api/1/tables/' . $table['id'] . '/shares', array_merge($permissions, [ 'receiverType' => 'user', 'receiver' => $receiver @@ -1020,7 +1020,7 @@ public function shareTableWithUser(string $user, string $receiver): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/shares/'.$share['id'], + '/apps/tables/api/1/shares/' . $share['id'], ); $shareToVerify = $this->getDataFromResponse($this->response); @@ -1055,7 +1055,7 @@ public function shareTableWithGroup(string $user, string $receiver): void { ]; $this->sendRequest( 'POST', - '/apps/tables/api/1/tables/'.$table['id'].'/shares', + '/apps/tables/api/1/tables/' . $table['id'] . '/shares', array_merge($permissions, [ 'receiverType' => 'group', 'receiver' => $receiver @@ -1077,7 +1077,7 @@ public function shareTableWithGroup(string $user, string $receiver): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/shares/'.$share['id'], + '/apps/tables/api/1/shares/' . $share['id'], ); $shareToVerify = $this->getDataFromResponse($this->response); @@ -1097,7 +1097,7 @@ public function shareTableWithGroup(string $user, string $receiver): void { private function getShareById(int $shareId): array { $this->sendRequest( 'GET', - '/apps/tables/api/1/shares/'.$shareId + '/apps/tables/api/1/shares/' . $shareId ); return $this->getDataFromResponse($this->response); @@ -1138,7 +1138,7 @@ public function updateSharePermission(string $user, string $permissionType, bool $share = $this->getDataFromResponse($this->response); Assert::assertEquals(200, $this->response->getStatusCode()); - Assert::assertEquals($share['permission'.ucfirst($permissionType)], $value); + Assert::assertEquals($share['permission' . ucfirst($permissionType)], $value); } // COLUMNS -------------------------- @@ -1157,7 +1157,7 @@ public function createColumn(string $title, ?TableNode $properties = null): void $this->sendRequest( 'POST', - '/apps/tables/api/1/tables/'.$this->tableId.'/columns', + '/apps/tables/api/1/tables/' . $this->tableId . '/columns', $props ); @@ -1170,7 +1170,7 @@ public function createColumn(string $title, ?TableNode $properties = null): void $this->sendRequest( 'GET', - '/apps/tables/api/1/columns/'.$newColumn['id'], + '/apps/tables/api/1/columns/' . $newColumn['id'], ); $columnToVerify = $this->getDataFromResponse($this->response); @@ -1188,7 +1188,7 @@ public function createColumn(string $title, ?TableNode $properties = null): void public function tableColumns(?TableNode $body = null): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/tables/'.$this->tableId.'/columns' + '/apps/tables/api/1/tables/' . $this->tableId . '/columns' ); $data = $this->getDataFromResponse($this->response); @@ -1218,7 +1218,7 @@ public function tableColumns(?TableNode $body = null): void { public function tableTypedColumns(?TableNode $body = null): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/tables/'.$this->tableId.'/columns' + '/apps/tables/api/1/tables/' . $this->tableId . '/columns' ); $data = $this->getDataFromResponse($this->response); @@ -1246,7 +1246,7 @@ public function tableTypedColumns(?TableNode $body = null): void { public function deleteColumn(): void { $this->sendRequest( 'DELETE', - '/apps/tables/api/1/columns/'.$this->columnId + '/apps/tables/api/1/columns/' . $this->columnId ); $column = $this->getDataFromResponse($this->response); @@ -1255,7 +1255,7 @@ public function deleteColumn(): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/columns/'.$column['id'], + '/apps/tables/api/1/columns/' . $column['id'], ); Assert::assertEquals(404, $this->response->getStatusCode()); } @@ -1273,7 +1273,7 @@ public function updateColumn(?TableNode $properties = null): void { $this->sendRequest( 'PUT', - '/apps/tables/api/1/columns/'.$this->columnId, + '/apps/tables/api/1/columns/' . $this->columnId, $props ); @@ -1293,7 +1293,7 @@ public function updateColumn(?TableNode $properties = null): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/columns/'.$column['id'], + '/apps/tables/api/1/columns/' . $column['id'], ); $columnToVerify = $this->getDataFromResponse($this->response); @@ -1326,7 +1326,7 @@ public function createRow(?TableNode $properties = null): void { $this->sendRequest( 'POST', - '/apps/tables/api/1/tables/'.$this->tableId.'/rows', + '/apps/tables/api/1/tables/' . $this->tableId . '/rows', ['data' => $props] ); @@ -1340,7 +1340,7 @@ public function createRow(?TableNode $properties = null): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/rows/'.$newRow['id'], + '/apps/tables/api/1/rows/' . $newRow['id'], ); $rowToVerify = $this->getDataFromResponse($this->response); @@ -1455,7 +1455,7 @@ public function createRowLegacy(?TableNode $properties = null): void { $this->sendRequest( 'POST', - '/apps/tables/api/1/tables/'.$this->tableId.'/rows', + '/apps/tables/api/1/tables/' . $this->tableId . '/rows', ['data' => json_encode($props)] ); @@ -1469,7 +1469,7 @@ public function createRowLegacy(?TableNode $properties = null): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/rows/'.$newRow['id'], + '/apps/tables/api/1/rows/' . $newRow['id'], ); $rowToVerify = $this->getDataFromResponse($this->response); @@ -1485,7 +1485,7 @@ public function createRowLegacy(?TableNode $properties = null): void { public function deleteRow(): void { $this->sendRequest( 'DELETE', - '/apps/tables/api/1/rows/'.$this->rowId + '/apps/tables/api/1/rows/' . $this->rowId ); $row = $this->getDataFromResponse($this->response); @@ -1494,7 +1494,7 @@ public function deleteRow(): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/rows/'.$row['id'], + '/apps/tables/api/1/rows/' . $row['id'], ); Assert::assertEquals(404, $this->response->getStatusCode()); } @@ -1513,7 +1513,7 @@ public function updateRow(?TableNode $properties = null): void { $this->sendRequest( 'PUT', - '/apps/tables/api/1/rows/'.$this->rowId, + '/apps/tables/api/1/rows/' . $this->rowId, ['data' => $props] ); @@ -1526,7 +1526,7 @@ public function updateRow(?TableNode $properties = null): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/rows/'.$row['id'], + '/apps/tables/api/1/rows/' . $row['id'], ); $rowToVerify = $this->getDataFromResponse($this->response); @@ -1560,7 +1560,7 @@ public function updateRowLegacy(?TableNode $properties = null): void { $this->sendRequest( 'PUT', - '/apps/tables/api/1/rows/'.$this->rowId, + '/apps/tables/api/1/rows/' . $this->rowId, ['data' => json_encode($props)] ); @@ -1573,7 +1573,7 @@ public function updateRowLegacy(?TableNode $properties = null): void { $this->sendRequest( 'GET', - '/apps/tables/api/1/rows/'.$row['id'], + '/apps/tables/api/1/rows/' . $row['id'], ); $rowToVerify = $this->getDataFromResponse($this->response); @@ -1935,7 +1935,7 @@ public function userAddsTheTableToFavorites($user, $tableName) { $this->sendOcsRequest( 'POST', - '/apps/tables/api/2/favorites/' . $nodeType. '/' . $tableId, + '/apps/tables/api/2/favorites/' . $nodeType . '/' . $tableId, ); if ($this->response->getStatusCode() === 200) { $this->userFetchesTableInfo($user, $tableName); @@ -1952,7 +1952,7 @@ public function userRemovesTheTableFromFavorites($user, $tableName) { $this->sendOcsRequest( 'DELETE', - '/apps/tables/api/2/favorites/' . $nodeType. '/' . $tableId, + '/apps/tables/api/2/favorites/' . $nodeType . '/' . $tableId, ); if ($this->response->getStatusCode() === 200) { $this->userFetchesTableInfo($user, $tableName); @@ -2090,13 +2090,13 @@ public function theFetchedContextHasFollowingData(string $contextAlias, TableNod foreach ($expectedData as $field => $value) { switch ($field) { - case "name": + case 'name': Assert::assertEquals($value, $actualData['name']); break; - case "icon": + case 'icon': Assert::assertEquals($value, $actualData['iconName']); break; - case "node": + case 'node': [$strType, $alias, $strPermission] = explode(':', $value); $nodeType = $strType === 'table' ? 0 : 1; $nodeId = $nodeType === 0 ? $this->tableIds[$alias] : $this->viewIds[$alias]; @@ -2109,7 +2109,7 @@ public function theFetchedContextHasFollowingData(string $contextAlias, TableNod } Assert::assertTrue($found); break; - case "page": + case 'page': [$pageType, $contentNodesCount] = explode(':', $value); $found = false; foreach ($actualData['pages'] as $actualPageData) { @@ -2130,13 +2130,13 @@ public function theFetchedContextDoesNotContainFollowingData(string $contextAlia foreach ($expectedData as $field => $value) { switch ($field) { - case "name": + case 'name': Assert::assertNotEquals($value, $actualData['name']); break; - case "icon": + case 'icon': Assert::assertNotEquals($value, $actualData['iconName']); break; - case "node": + case 'node': [$strType, $alias, $strPermission] = explode(':', $value); $nodeType = $strType === 'table' ? 0 : 1; $nodeId = $nodeType === 0 ? $this->tableIds[$alias] : $this->viewIds[$alias]; @@ -2149,7 +2149,7 @@ public function theFetchedContextDoesNotContainFollowingData(string $contextAlia } Assert::assertFalse($found); break; - case "page": + case 'page': [$pageType, $contentNodesCount] = explode(':', $value); $found = false; foreach ($actualData['pages'] as $actualPageData) { diff --git a/tests/phan-config.php b/tests/phan-config.php index a64213c58..3e7afe9a3 100644 --- a/tests/phan-config.php +++ b/tests/phan-config.php @@ -10,7 +10,7 @@ 'lib/', 'vendor/', ], - "exclude_analysis_directory_list" => [ + 'exclude_analysis_directory_list' => [ 'vendor/', ], ]; diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php index 985cdfea6..4ff11d2ee 100644 --- a/tests/unit/bootstrap.php +++ b/tests/unit/bootstrap.php @@ -9,7 +9,7 @@ define('PHPUNIT_RUN', 1); } -require_once __DIR__.'/../../../../lib/base.php'; +require_once __DIR__ . '/../../../../lib/base.php'; \OC::$loader->addValidRoot(\OC::$SERVERROOT . '/tests'); \OC_App::loadApp('tables');