Skip to content

Commit

Permalink
psalm fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian Steffens committed Aug 9, 2023
1 parent 1e4a978 commit 51b8c01
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getTable(int $tableId): DataResponse {
*/
public function updateTable(int $id, string $title = null, string $emoji = null): DataResponse {
return $this->handleError(function () use ($id, $title, $emoji) {
return $this->service->update($id, $title, $emoji, $this->userId);
return $this->tableService->update($id, $title, $emoji, $this->userId);
});
}

Expand Down Expand Up @@ -468,7 +468,7 @@ public function deleteColumn(int $columnId): DataResponse {
*/
public function indexTableRowsSimple(int $tableId, ?int $limit, ?int $offset): DataResponse {
return $this->handleError(function () use ($tableId, $limit, $offset) {
return $this->v1Api->getData($tableId, $limit, $offset, $this->userId);
return $this->v1Api->getData($tableId, $limit, $offset);
});
}

Expand Down
5 changes: 4 additions & 1 deletion lib/Db/ColumnMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;

/** @template-extends QBMapper<Column> */
class ColumnMapper extends QBMapper {
protected string $table = 'tables_columns';
private LoggerInterface $logger;

public function __construct(IDBConnection $db) {
public function __construct(IDBConnection $db, LoggerInterface $logger) {
parent::__construct($db, $this->table, Column::class);
$this->logger = $logger;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/ColumnTypes/IColumnTypeQB.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace OCA\Tables\DB\ColumnTypes;
namespace OCA\Tables\Db\ColumnTypes;

use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/ColumnTypes/SuperColumnQB.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
}

public function setPlatform(int $platform) {
public function setPlatform(int $platform): void {
$this->platform = $platform;
}

Expand Down
23 changes: 13 additions & 10 deletions lib/Db/RowMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
Expand Down Expand Up @@ -79,7 +80,7 @@ public function find(int $id): Row {
return $this->findEntity($qb);
}

private function buildFilterByColumnType($qb, array $filter, string $filterId): string {
private function buildFilterByColumnType($qb, array $filter, string $filterId): ?IQueryFunction {
try {
$columnQbClassName = 'OCA\Tables\Db\ColumnTypes\\';
$type = explode("-", $filter['columnType'])[0];
Expand All @@ -92,7 +93,7 @@ private function buildFilterByColumnType($qb, array $filter, string $filterId):
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
$this->logger->debug('Column type query builder class not found');
}
return '';
return null;
}

private function getInnerFilterExpressions($qb, $filterGroup, int $groupIndex): array {
Expand Down Expand Up @@ -123,14 +124,15 @@ private function resolveSearchValue(string $unresolvedSearchValue, string $userI
case 'stars-3': return '3';
case 'stars-4': return '4';
case 'stars-5': return '5';
case 'datetime-date-today': return date('Y-m-d');
case 'datetime-date-start-of-year': return date('Y-01-01');
case 'datetime-date-start-of-month': return date('Y-m-01');
case 'datetime-date-today': return date('Y-m-d') ? date('Y-m-d') : '';
case 'datetime-date-start-of-year': return date('Y-01-01') ? date('Y-01-01') : '';
case 'datetime-date-start-of-month': return date('Y-m-01') ? date('Y-m-01') : '';
case 'datetime-date-start-of-week':
$day = date('w');
return date('m-d-Y', strtotime('-'.$day.' days'));
$result = date('m-d-Y', strtotime('-'.$day.' days'));
return $result ?: '';
case 'datetime-time-now': return date('H:i');
case 'datetime-now': return date('Y-m-d H:i');
case 'datetime-now': return date('Y-m-d H:i') ? date('Y-m-d H:i') : '';
default: return $unresolvedSearchValue;
}
}
Expand Down Expand Up @@ -203,7 +205,7 @@ public function countRowsForView(View $view, $userId): int {
public function getRowIdsOfView(View $view, $userId): array {
$qb = $this->db->getQueryBuilder();
$qb->select('t1.id')
->from($this->table,'t1')
->from($this->table, 't1')
->where($qb->expr()->eq('table_id', $qb->createNamedParameter($view->getTableId(), IQueryBuilder::PARAM_INT)));

$neededColumnIds = $this->getAllColumnIdsFromView($view, $qb);
Expand Down Expand Up @@ -306,7 +308,7 @@ public function findAllByView(View $view, string $userId, ?int $limit = null, ?i
}
$rows = $this->findEntities($qb);
foreach ($rows as &$row) {
$row->setDataArray(array_filter($row->getDataArray(), function($item) use ($view) {
$row->setDataArray(array_filter($row->getDataArray(), function ($item) use ($view) {
return in_array($item['columnId'], $view->getColumnsArray());
}));
}
Expand All @@ -329,7 +331,8 @@ private function getAllColumnIdsFromView(View $view, IQueryBuilder $qb): array {
if ($this->platform === IColumnTypeQB::DB_PLATFORM_PGSQL) {
foreach ($neededColumnIds as $columnId) {
if ($columnId >= 0) {
$qb->leftJoin("t1", $qb->createFunction('json_array_elements(t1.data)'), 'c' . intval($columnId),$qb->createFunction("CAST(c".intval($columnId).".value->>'columnId' AS int) = ".$columnId));
/** @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));
// TODO Security
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Reference/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function resolveReference(string $referenceText): ?IReference {
return $this->linkReferenceProvider->resolveReference($referenceText);
}
try {
$view = $this->viewService->find($viewId, $this->userId);
$view = $this->viewService->find($viewId, false, $this->userId);
} catch (Exception | Throwable $e) {
/** @psalm-suppress InvalidReturnStatement */
return $this->linkReferenceProvider->resolveReference($referenceText);
Expand Down Expand Up @@ -100,7 +100,7 @@ public function resolveReference(string $referenceText): ?IReference {

// add rows data
try {
$viewReferenceInfo['rows'] = $this->rowService->findAllByView($viewId, 10, 0);
$viewReferenceInfo['rows'] = $this->rowService->findAllByView($viewId, $this->userId, 10, 0);
} catch (InternalError $e) {
} catch (PermissionError $e) {
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ColumnTypes/NumberBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function parseValue(string $value, ?Column $column = null): string {
}

public function canBeParsed(string $value, ?Column $column = null): bool {
return !$value || is_numeric(floatval($value));
return !$value || floatval($value);
}

}
2 changes: 0 additions & 2 deletions lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public function __construct(PermissionsService $permissionsService, LoggerInterf

/**
* @throws InternalError
*
* @psalm-param 'table' $nodeType
*/
public function findAll(string $nodeType, int $nodeId, ?string $userId = null): array {
$userId = $this->permissionsService->preCheckUserId($userId);
Expand Down
12 changes: 5 additions & 7 deletions lib/Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private function enhanceView(View $view, string $userId): void {
$canManageTable = $manageTableShare['manage'] ?? false;
} catch (NotFoundError $e) {
} catch (\Exception $e) {
throw new InternalError($e);
throw new InternalError($e->getMessage());
}
$view->setOnSharePermissions([
'read' => $permissions['read'] ?? false,
Expand Down Expand Up @@ -347,10 +347,8 @@ private function enhanceView(View $view, string $userId): void {
if(!$view->getOnSharePermissions()['manageTable']) {
$view->setFilterArray(
array_map(function ($filterGroup) {
return array_map(function (){
// Instead of filter just indicate that there is a filter, but hide details
return null;
},$filterGroup);
// Instead of filter just indicate that there is a filter, but hide details
return array_map(null, $filterGroup);
},
$view->getFilterArray()));
$view->setSortArray(
Expand All @@ -369,7 +367,7 @@ private function enhanceView(View $view, string $userId): void {
/**
* @param Table $table
* @param null|string $userId
* @return View
* @return void
* @throws InternalError
* @throws PermissionError
*/
Expand Down Expand Up @@ -405,7 +403,7 @@ public function deleteColumnDataFromViews(int $columnId, Table $table) {
return array_filter($filterGroup, function ($filter) use ($columnId) {
return $filter['columnId'] !== $columnId;
});
}, $view->getFilterArray()), fn($filterGroup) => !empty($filterGroup));
}, $view->getFilterArray()), fn ($filterGroup) => !empty($filterGroup));
$data = [
'columns' => json_encode(array_values(array_diff($view->getColumnsArray(), [$columnId]))),
'sort' => json_encode($filteredSortingRules),
Expand Down

0 comments on commit 51b8c01

Please sign in to comment.