Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"psalm": "psalm --no-diff",
"test:unit": "phpunit -c tests/phpunit.xml",
"test:integration": "phpunit -c tests/phpunit.xml",
"psalm:fix": "psalm --alter --php-version=8.1 --issues=MissingReturnType,InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType",
"psalm:fix": "psalm --alter --issues=MissingReturnType,InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType",
"psalm:info": "psalm --no-diff --show-info=true",
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
"psalm:baseline:update": "psalm --update-baseline",
Expand Down
5 changes: 3 additions & 2 deletions lib/Controller/BaseApiV2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* SPDX-FileCopyrightText: 2024 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Polls\Controller;

use Closure;
Expand All @@ -21,6 +20,7 @@

/**
* @psalm-api
* @psalm-import-type HttpStatusCode from \OCA\Polls\Types
*/
class BaseApiV2Controller extends OCSController {
public function __construct(
Expand All @@ -36,6 +36,7 @@ public function __construct(
/**
* response
* @param Closure $callback Callback function
* @psalm-param HttpStatusCode $successStatus HTTP status code for success
*/
#[NoAdminRequired]
protected function response(Closure $callback, int $successStatus = Http::STATUS_OK): DataResponse {
Expand All @@ -48,7 +49,7 @@ protected function response(Closure $callback, int $successStatus = Http::STATUS
} catch (Exception $e) {

if ($e->getStatus() === Http::STATUS_NOT_MODIFIED) {
return new DataResponse(statusCode: $e->getStatus());
return new DataResponse(statusCode: Http::STATUS_NOT_MODIFIED);
}

throw new OCSBadRequestException($e->getMessage());
Expand Down
9 changes: 6 additions & 3 deletions lib/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

/**
* @psalm-api
* @psalm-import-type HttpStatusCode from \OCA\Polls\Types
*/
class BaseController extends Controller {
public function __construct(
Expand All @@ -30,7 +31,7 @@ public function __construct(
/**
* response
* @param Closure $callback Callback function
* @param int $successStatus HTTP status code for success
* @psalm-param HttpStatusCode $successStatus HTTP status code for success
*/
#[NoAdminRequired]
protected function response(
Expand All @@ -42,10 +43,12 @@ protected function response(
} catch (Exception $e) {

if ($e->getStatus() === Http::STATUS_NOT_MODIFIED) {
return new JSONResponse(statusCode: $e->getStatus());
return new JSONResponse(statusCode: Http::STATUS_NOT_MODIFIED);
}

return new JSONResponse(['message' => $e->getMessage()], $e->getStatus());
/** @var HttpStatusCode $status */
$status = $e->getStatus();
return new JSONResponse(['message' => $e->getMessage()], $status);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function __construct(
#[OpenAPI(OpenAPI::SCOPE_IGNORE)]
#[FrontpageRoute(verb: 'GET', url: '/search/users/{query}')]
public function userSearch(string $query, string $types): JSONResponse {
$types = explode(',', $types);
$types = array_map('intval', explode(',', $types));
// $types = explode(',', $types);
return new JSONResponse([
'siteusers' => $this->systemService->getSiteUsersAndGroups($query, $types),
'types' => $types
Expand Down
19 changes: 0 additions & 19 deletions lib/Exceptions/DuplicateEntryException.php

This file was deleted.

12 changes: 5 additions & 7 deletions lib/Model/Settings/SystemSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,20 @@ public function getShareCreateAllowed(): bool {
// get group exceptions
$exceptionGroups = $this->getCoreLimitSharingGroups();

if ($groupExceptionMode === 'allowGroup') {
// exception mode is 'Limit sharing to some groups'
// if user is in exception group, allow share creation
return $this->userSession->getCurrentUser()->getIsInGroupArray($exceptionGroups);
} elseif ($groupExceptionMode === 'denyGroup') {
if ($groupExceptionMode === 'denyGroup') {
// exception mode is 'Exclude some Groups from sharing'
// if user is in exception group, deny share creation
return !$this->userSession->getCurrentUser()->getIsInGroupArray($exceptionGroups);
}

return true;
// exception mode is 'Limit sharing to some groups'
// if user is in exception group, allow share creation
return $this->userSession->getCurrentUser()->getIsInGroupArray($exceptionGroups);
}

/**
* Get share group exception mode
* @return string
* @return 'open'|'closed'|'archived'
* @psalm-return 'denyGroup'|'allowGroup'|'off'
* Take value from the core setting 'shareapi_exclude_groups' and translate
* 'yes' => 'denyGroup' ('Exclude some groups from sharing') existing groups are handeled as deny groups
Expand Down
3 changes: 1 addition & 2 deletions lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public static function extractEmailAddressAndName($eMailString): array {
preg_match(self::REGEX_PARSE_MAIL_AND_NAME, $eMailString, $matches);

// Check if the found element is a valid email address
$emailAddress = !empty($matches[1]) ? trim($matches[1]) : null;

$emailAddress = (isset($matches[1]) && trim($matches[1]) !== '') ? trim($matches[1]) : null;
if ($emailAddress !== null && filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
// Extract the name based on the input string
$displayName = trim(str_replace(['<', '>'], '', str_replace($emailAddress, '', $eMailString)));
Expand Down
7 changes: 1 addition & 6 deletions lib/Service/OptionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use OCA\Polls\Event\OptionUnconfirmedEvent;
use OCA\Polls\Event\OptionUpdatedEvent;
use OCA\Polls\Event\PollOptionReorderedEvent;
use OCA\Polls\Exceptions\DuplicateEntryException;
use OCA\Polls\Exceptions\InvalidPollTypeException;
use OCA\Polls\Model\Sequence;
use OCA\Polls\Model\SimpleOption;
Expand Down Expand Up @@ -168,11 +167,7 @@ public function addBulk(int $pollId, string $bulkText = ''): array {

foreach ($newOptionsTexts as $pollOptionText) {
if ($pollOptionText) {
try {
$this->add($pollId, new SimpleOption($pollOptionText, 0));
} catch (DuplicateEntryException $e) {
continue;
}
$this->add($pollId, new SimpleOption($pollOptionText, 0));
}
}

Expand Down
10 changes: 6 additions & 4 deletions lib/Service/PollService.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,22 @@ public function takeover(int $pollId, ?UserBase $targetUser = null): Poll {
/**
* Transfer ownership of a poll
* @param int|Poll $poll poll or pollId of poll to transfer ownership
* @param null|string|UserBase $targetUser User to transfer polls to. If null the current user will be used
* @param string|UserBase $targetUser User to transfer polls to. If null the current user will be used
*/
public function transferPoll(int|Poll $poll, null|string|UserBase $targetUser): Poll {
public function transferPoll(int|Poll $poll, string|UserBase $targetUser): Poll {
if (!($poll instanceof Poll)) {
$poll = $this->pollMapper->find($poll);
}

$poll->request(Poll::PERMISSION_POLL_CHANGE_OWNER);

if (!($targetUser instanceof UserBase)) {
$userId = $targetUser;
try {
$targetUser = $this->userMapper->getUserFromUserBase($targetUser);
$targetUser = $this->userMapper->getUserFromUserBase($userId);
} catch (UserNotFoundException $e) {
throw new InvalidUsernameException('The user id "' . $targetUser . '" for the target user is not valid.');
// to keep psalm quiet
throw new InvalidUsernameException('The user id "' . $userId . '" for the target user is not valid.');
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/Service/SystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function getGroups(string $query = ''): array {
/**
* Get a combined list of users, groups, circles, contact groups and contacts
*
* @param list<int> $types list of types to search for
* @return (Circle|Email|Group|User|Contact|ContactGroup|mixed)[]
*
* @psalm-return array<array-key, Circle|Email|Group|User|Contact|ContactGroup|mixed>
Expand Down
19 changes: 19 additions & 0 deletions lib/Types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Polls;

/**
* @psalm-type HttpStatusCode =
* 100|101|102|200|201|202|203|204|205|206|207|208|226|
* 300|301|302|303|304|305|306|307|
* 400|401|402|403|404|405|406|407|408|409|410|411|412|413|414|415|416|417|418|422|423|424|426|428|429|431|
* 500|501|502|503|504|505|506|507|508|509|510|511
* @psalm-api
*/
interface Types {
}
11 changes: 0 additions & 11 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="lib/Exceptions/DuplicateEntryException.php">
<UnusedClass>
<code><![CDATA[DuplicateEntryException]]></code>
</UnusedClass>
</file>
<file src="lib/Model/Group/Circle.php">
<UndefinedClass>
<code><![CDATA[$this->circle]]></code>
<code><![CDATA[CirclesCircle]]></code>
</UndefinedClass>
</file>
<file src="lib/Service/MailService.php">
<PossiblyUnusedMethod>
<code><![CDATA[parseEmailStrings]]></code>
Expand Down
4 changes: 4 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
cacheDirectory=".psalm.cache"
findUnusedBaselineEntry="true"
findUnusedCode="true"
phpVersion="8.1"
>
<projectFiles>
<directory name="lib" />
Expand All @@ -23,6 +24,9 @@
<extraFiles>
<directory name="vendor" />
</extraFiles>
<stubs>
<file name="stubs/circles-stubs.php"/>
</stubs>
<issueHandlers>
<LessSpecificReturnStatement errorLevel="error"/>
<LessSpecificReturnType errorLevel="error"/>
Expand Down
16 changes: 16 additions & 0 deletions stubs/circles-stubs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Circles\Model;

/**
* @psalm-immutable
*/
final class Circle {
public function getUrl() {
}
}