From 91b3421cdd69b723c2cb7d1fa04f883317cb6a84 Mon Sep 17 00:00:00 2001 From: Robin Appelman <robin@icewind.nl> Date: Thu, 4 Mar 2021 11:19:26 +0100 Subject: [PATCH] stubs for psalm --- lib/Controller/TestController.php | 7 ++-- psalm.xml | 22 ++----------- tests/psalm-baseline.xml | 10 ------ tests/stub.phpstub | 55 +++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 31 deletions(-) delete mode 100644 tests/psalm-baseline.xml create mode 100644 tests/stub.phpstub diff --git a/lib/Controller/TestController.php b/lib/Controller/TestController.php index c50c4d0..be4ae48 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 2378f39..ef98532 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 011d002..0000000 --- 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 0000000..2132437 --- /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 { + + } +} -- GitLab