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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
build/
phpDocumentor.phar
vendor/
vendor-bin/*/vendor
tests/.phpunit.cache/test-results
6 changes: 6 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ path = ["img/circles-dark.svg", "img/circles.svg"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2018-2024 Google LLC"
SPDX-License-Identifier = "Apache-2.0"

[[annotations]]
path = ["vendor-bin/psalm/composer.json", "vendor-bin/psalm/composer.lock"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2025 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"
23 changes: 16 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"autoloader-suffix": "Circles",
"platform": {
"php": "8.1"
},
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
},
"authors": [
Expand All @@ -25,20 +28,26 @@
"scripts": {
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar --threads=1 --update-baseline",
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
"psalm:clear": "psalm.phar --clear-cache && psalm.phar --clear-global-cache",
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"psalm": "vendor-bin/psalm/vendor/vimeo/psalm/psalm --threads=1",
"psalm:update-baseline": "vendor-bin/psalm/vendor/vimeo/psalm/psalm --threads=1 --update-baseline",
"psalm:clear": "vendor-bin/psalm/vendor/vimeo/psalm/psalm --clear-cache && psalm.phar --clear-global-cache",
"psalm:fix": "vendor-bin/psalm/vendor/vimeo/psalm/psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"test": [
"@test:unit"
],
"test:unit": "vendor/bin/phpunit -c tests/phpunit.xml",
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l"
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install --ansi"
],
"post-update-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all update --ansi"
]
},
"require-dev": {
"phpunit/phpunit": "^10.5",
"psalm/phar": "^5.22",
"nextcloud/ocp": "dev-stable31",
"nextcloud/coding-standard": "^1.2"
"nextcloud/coding-standard": "^1.2",
"bamarni/composer-bin-plugin": "^1.9"
}
}
94 changes: 58 additions & 36 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Model/BaseCircle.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function setSettings($settings, bool $all = false) {
*/
public function getSettings($json = false) {
if ($json) {
return json_encode($this->settings);
return json_encode($this->settings, flags: JSON_THROW_ON_ERROR);
}

$settings = $this->settings;
Expand Down
4 changes: 2 additions & 2 deletions lib/Model/SharingFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function setPayload($payload) {
*/
public function getPayload($asJson = false) {
if ($asJson) {
return json_encode($this->payload);
return json_encode($this->payload, flags: JSON_THROW_ON_ERROR);
}

return $this->payload;
Expand All @@ -173,7 +173,7 @@ public function setHeaders($headers) {
*/
public function getHeaders($asJson = false) {
if ($asJson) {
return json_encode($this->headers);
return json_encode($this->headers, flags: JSON_THROW_ON_ERROR);
}

return $this->headers;
Expand Down
37 changes: 37 additions & 0 deletions lib/Service/FederatedEventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
use OCA\Circles\Tools\Model\Request;
use OCA\Circles\Tools\Traits\TNCRequest;
use OCA\Circles\Tools\Traits\TStringTools;
use OCP\AppFramework\Http;
use OCP\Server;
use Psr\Log\LoggerInterface;
use ReflectionClass;
use ReflectionException;

Expand Down Expand Up @@ -428,10 +431,44 @@ public function initBroadcast(FederatedEvent $event): bool {
$this->e($e);
}

if (!$isLoopbackTest && !$this->isLoopbackSuccessful($request)) {
Server::get(LoggerInterface::class)->warning(
'Loopback request failed, processing event synchronously. Please check the loopback setup with occ circles:check',
['url' => $request->getCompleteUrl(), 'status' => $request->hasResult() ? $request->getResult()->getStatusCode() : 0]
);
$this->manageWrappersSynchronously($wrapper->getToken());
}

return true;
}


/**
* asyncBroadcast() closes the connection with an empty 200 before processing the event
*/
private function isLoopbackSuccessful(NCRequest $request): bool {
if (!$request->hasResult() || $request->getResult()->hasException()) {
return false;
}

$result = $request->getResult();

return $result->getStatusCode() === Http::STATUS_OK && $result->getContent() === '';
}

/**
* same process as EventWrapperController::asyncBroadcast()
*/
private function manageWrappersSynchronously(string $token): void {
// EventWrapperService depends on this service
$eventWrapperService = Server::get(EventWrapperService::class);
foreach ($this->eventWrapperRequest->getByToken($token) as $wrapper) {
$eventWrapperService->manageWrapper($wrapper);
}

$eventWrapperService->confirmStatus($token);
}

/**
* @param FederatedEvent $event
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Tools/Model/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public function addDataInt(string $k, int $v): Request {
* @return string
*/
public function getDataBody(): string {
return json_encode($this->getData());
return json_encode($this->getData(), flags: JSON_THROW_ON_ERROR);
}

/**
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="tests/psalm-baseline.xml"
phpVersion="8.1"
findUnusedCode="false"
>
<stubs>
<file name="tests/stub.phpstub" preloadClasses="true"/>
Expand Down
44 changes: 33 additions & 11 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<files psalm-version="6.5.0@38fc8444edf0cebc9205296ee6e30e906ade783b">
<file src="lib/Activity/ProviderParser.php">
<TypeDoesNotContainType>
<code><![CDATA[str_starts_with($sK, '_')]]></code>
Expand Down Expand Up @@ -119,6 +119,16 @@
<code><![CDATA[CircleEventService]]></code>
</UndefinedDocblockClass>
</file>
<file src="lib/Listeners/CircleMemberRemoved.php">
<UndefinedClass>
<code><![CDATA[\OCA\GroupFolders\Folder\FolderManager]]></code>
</UndefinedClass>
</file>
<file src="lib/Listeners/GroupMemberRemoved.php">
<UndefinedClass>
<code><![CDATA[\OCA\GroupFolders\Folder\FolderManager]]></code>
</UndefinedClass>
</file>
<file src="lib/Migration/Version0022Date20220526111723.php">
<UndefinedClass>
<code><![CDATA[Connection]]></code>
Expand Down Expand Up @@ -385,11 +395,33 @@
<code><![CDATA[private $exception = null;]]></code>
</UndefinedDocblockClass>
</file>
<file src="lib/Tools/Model/Request.php">
<InvalidNullableReturnType>
<code><![CDATA[string]]></code>
<code><![CDATA[string]]></code>
</InvalidNullableReturnType>
<NullableReturnStatement>
<code><![CDATA[preg_replace(
'/([(%5B)]{1})[0-9]+([(%5D)]{1})/', '$1$2', http_build_query($this->getData())
)]]></code>
<code><![CDATA[preg_replace(
'/([(%5B)]{1})[0-9]+([(%5D)]{1})/', '$1$2', http_build_query($this->getParams())
)]]></code>
</NullableReturnStatement>
</file>
<file src="lib/Tools/Model/SimpleDataStore.php">
<InvalidReturnStatement>
<code><![CDATA[$item]]></code>
</InvalidReturnStatement>
</file>
<file src="lib/Tools/Model/TreeNode.php">
<InvalidNullableReturnType>
<code><![CDATA[TreeNode]]></code>
</InvalidNullableReturnType>
<NullableReturnStatement>
<code><![CDATA[$this->currentChild]]></code>
</NullableReturnStatement>
</file>
<file src="lib/Tools/Traits/TArrayTools.php">
<TooManyArguments>
<code><![CDATA[getArray]]></code>
Expand Down Expand Up @@ -424,14 +456,4 @@
<code><![CDATA[$s[$e]]]></code>
</InvalidArrayOffset>
</file>
<file src="lib/Listeners/GroupMemberRemoved.php">
<UndefinedClass>
<code><![CDATA[\OCA\GroupFolders\Folder\FolderManager]]></code>
</UndefinedClass>
</file>
<file src="lib/Listeners/CircleMemberRemoved.php">
<UndefinedClass>
<code><![CDATA[\OCA\GroupFolders\Folder\FolderManager]]></code>
</UndefinedClass>
</file>
</files>
10 changes: 10 additions & 0 deletions vendor-bin/psalm/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"require-dev": {
"vimeo/psalm": "^6"
},
"config": {
"platform": {
"php": "8.1.17"
}
}
}
Loading
Loading