diff --git a/lib/Controller/TestController.php b/lib/Controller/TestController.php index c50c4d01a353f6d6b75c0f4d482ed7e7fe2b6437..be4ae4804d4b0cc78cb651251fbf424b674e2596 100644 --- a/lib/Controller/TestController.php +++ b/lib/Controller/TestController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCA\NotifyPush\Controller; +use OC\AppFramework\Http\Request; use OCA\NotifyPush\Queue\IQueue; use OCA\NotifyPush\Queue\RedisQueue; use OCP\App\IAppManager; @@ -65,8 +66,10 @@ class TestController extends Controller { */ public function remote(): DataDisplayResponse { if ($this->queue instanceof RedisQueue) { - $this->queue->getConnection()->set("notify_push_forwarded_header", $this->request->getHeader('x-forwarded-for')); - $this->queue->getConnection()->set("notify_push_remote", $this->request->server['REMOTE_ADDR']); + if ($this->request instanceof Request) { + $this->queue->getConnection()->set("notify_push_forwarded_header", $this->request->getHeader('x-forwarded-for')); + $this->queue->getConnection()->set("notify_push_remote", $this->request->server['REMOTE_ADDR']); + } } return new DataDisplayResponse($this->request->getRemoteAddress()); } diff --git a/psalm.xml b/psalm.xml index 2378f3951b06328cd8ddeb458a45458821e23f36..ef9853256f18017596cc8a04f6fb06a8f1ca9d16 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,7 +4,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config" - errorBaseline="tests/psalm-baseline.xml" phpVersion="7.3" > <projectFiles> @@ -13,22 +12,7 @@ <extraFiles> <directory name="vendor/christophwurst/nextcloud"/> </extraFiles> - <issueHandlers> - <UndefinedClass> - <errorLevel type="suppress"> - <referencedClass name="OC" /> - <referencedClass name="OC\RedisFactory" /> - </errorLevel> - </UndefinedClass> - <UndefinedDocblockClass> - <errorLevel type="suppress"> - <referencedClass name="OC\RedisFactory"/> - </errorLevel> - </UndefinedDocblockClass> - <MissingDependency> - <errorLevel type="suppress"> - <file name="lib/AppInfo/Application.php"/> - </errorLevel> - </MissingDependency> - </issueHandlers> + <stubs> + <file name="tests/stub.phpstub" preloadClasses="true"/> + </stubs> </psalm> diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml deleted file mode 100644 index 011d002a660502d07c68cffc679c1dab099c4b61..0000000000000000000000000000000000000000 --- a/tests/psalm-baseline.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<files psalm-version="4.x-dev@"> - <file src="lib/AppInfo/Application.php"> - <InvalidArgument occurrences="3"> - <code>addListener</code> - <code>addListener</code> - <code>addListener</code> - </InvalidArgument> - </file> -</files> diff --git a/tests/stub.phpstub b/tests/stub.phpstub new file mode 100644 index 0000000000000000000000000000000000000000..21324377bdbe46e2b63a87ce553206addee01640 --- /dev/null +++ b/tests/stub.phpstub @@ -0,0 +1,55 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace { + class OC { + /** @var string */ + public static $configDir; + } +} + +namespace OC { + class RedisFactory { + public function getInstance(): \Redis {} + public function isAvailable(){} + } +} + +namespace OC\AppFramework\Http { + + use OCP\IRequest; + + abstract class Request implements IRequest { + public $server = []; + } +} + +namespace OC\Files\Cache { + + use OCP\EventDispatcher\Event; + use OCP\Files\Cache\ICacheEvent; + + abstract class AbstractCacheEvent extends Event implements ICacheEvent { + + } +}