Repository: sabre-io/dav (php)
Issue: Latest phpstan is reporting missing return statements
phpstan is reporting various functions that have return types documented but do not always return the documented type.

This is causing CI to fail.
Pull request description: Fix return types
Fixes #1361 

I have tried to minimize changes to real code, and o mostly just delete or adjust PHPdoc to match reality. That gets CI green with the minimum impact.

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ecf8e263..f41b3853 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -13,7 +13,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        php-versions: [ '7.1' ]
+        php-versions: [ '7.4' ]
     steps:
       - name: Checkout
         uses: actions/checkout@v2
@@ -124,4 +124,4 @@ jobs:
           RUN_TEST_WITH_STREAMING_PROPFIND: "true"
 
       - uses: codecov/codecov-action@v2
-        if: matrix.coverage != 'none'
\ No newline at end of file
+        if: matrix.coverage != 'none'
diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php
index da172049..98f4f554 100644
--- a/lib/CalDAV/Plugin.php
+++ b/lib/CalDAV/Plugin.php
@@ -243,7 +243,7 @@ class Plugin extends DAV\ServerPlugin
      * @param mixed  $report
      * @param mixed  $path
      *
-     * @return bool
+     * @return bool|null
      */
     public function report($reportName, $report, $path)
     {
diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index 38a7ca96..3cc360f1 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -735,9 +735,7 @@ class Plugin extends ServerPlugin
 
     /**
      * This method is responsible for parsing a free-busy query request and
-     * returning it's result.
-     *
-     * @return string
+     * returning its result in $response.
      */
     protected function handleFreeBusyRequest(IOutbox $outbox, VObject\Component $vObject, RequestInterface $request, ResponseInterface $response)
     {
diff --git a/lib/CalDAV/Subscriptions/Subscription.php b/lib/CalDAV/Subscriptions/Subscription.php
index 3be1b609..8d56e644 100644
--- a/lib/CalDAV/Subscriptions/Subscription.php
+++ b/lib/CalDAV/Subscriptions/Subscription.php
@@ -75,7 +75,7 @@ class Subscription extends Collection implements ISubscription, IACL
     /**
      * Returns the last modification time.
      *
-     * @return int
+     * @return int|null
      */
     public function getLastModified()
     {
diff --git a/lib/DAV/Auth/Plugin.php b/lib/DAV/Auth/Plugin.php
index 68adbede..eb4f27ca 100644
--- a/lib/DAV/Auth/Plugin.php
+++ b/lib/DAV/Auth/Plugin.php
@@ -113,8 +113,6 @@ class Plugin extends ServerPlugin
 
     /**
      * This method is called before any HTTP method and forces users to be authenticated.
-     *
-     * @return bool
      */
     public function beforeMethod(RequestInterface $request, ResponseInterface $response)
     {
@@ -204,8 +202,6 @@ class Plugin extends ServerPlugin
      * This method will for example cause a HTTP Basic backend to set a
      * WWW-Authorization header, indicating to the client that it should
      * authenticate.
-     *
-     * @return array
      */
     public function challenge(RequestInterface $request, ResponseInterface $response)
     {
diff --git a/lib/DAV/Browser/Plugin.php b/lib/DAV/Browser/Plugin.php
index 2f155d9e..89495e5d 100644
--- a/lib/DAV/Browser/Plugin.php
+++ b/lib/DAV/Browser/Plugin.php
@@ -85,8 +85,6 @@ class Plugin extends DAV\ServerPlugin
     /**
      * This method intercepts GET requests that have ?sabreAction=info
      * appended to the URL.
-     *
-     * @return bool
      */
     public function httpGetEarly(RequestInterface $request, ResponseInterface $response)
     {
diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index 6f071927..46d680e1 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -927,8 +927,6 @@ class Plugin extends DAV\ServerPlugin
      * Triggered before properties are looked up in specific nodes.
      *
      * @TODO really should be broken into multiple methods, or even a class.
-     *
-     * @return bool
      */
     public function propFind(DAV\PropFind $propFind, DAV\INode $node)
     {
@@ -1070,8 +1068,6 @@ class Plugin extends DAV\ServerPlugin
      * @param string $reportName
      * @param mixed  $report
      * @param mixed  $path
-     *
-     * @return bool
      */
     public function report($reportName, $report, $path)
     {
diff --git a/lib/DAVACL/PrincipalBackend/AbstractBackend.php b/lib/DAVACL/PrincipalBackend/AbstractBackend.php
index 03a9c4ba..f61a0c95 100644
--- a/lib/DAVACL/PrincipalBackend/AbstractBackend.php
+++ b/lib/DAVACL/PrincipalBackend/AbstractBackend.php
@@ -33,7 +33,7 @@ abstract class AbstractBackend implements BackendInterface
      * @param string $uri
      * @param string $principalPrefix
      *
-     * @return string
+     * @return string|null
      */
     public function findByUri($uri, $principalPrefix)
     {
diff --git a/lib/DAVACL/Xml/Property/Principal.php b/lib/DAVACL/Xml/Property/Principal.php
index 24aeffad..52092128 100644
--- a/lib/DAVACL/Xml/Property/Principal.php
+++ b/lib/DAVACL/Xml/Property/Principal.php
@@ -142,6 +142,8 @@ class Principal extends DAV\Xml\Property\Href
             case self::ALL:
                 return '<em>all</em>';
         }
+
+        return '<em>unknown</em>';
     }
 
     /**


Test patch:
diff --git a/tests/Sabre/CalDAV/Backend/AbstractTest.php b/tests/Sabre/CalDAV/Backend/AbstractTest.php
index 0ea16165..56751d4e 100644
--- a/tests/Sabre/CalDAV/Backend/AbstractTest.php
+++ b/tests/Sabre/CalDAV/Backend/AbstractTest.php
@@ -140,6 +140,8 @@ class AbstractMock extends AbstractBackend
                     ],
                 ];
         }
+
+        return [];
     }
 
     public function getCalendarObject($calendarId, $objectUri)
diff --git a/tests/Sabre/CalDAV/Backend/MockScheduling.php b/tests/Sabre/CalDAV/Backend/MockScheduling.php
index ac799ca2..40901c5c 100644
--- a/tests/Sabre/CalDAV/Backend/MockScheduling.php
+++ b/tests/Sabre/CalDAV/Backend/MockScheduling.php
@@ -30,6 +30,8 @@ class MockScheduling extends Mock implements SchedulingSupport
         if (isset($this->schedulingObjects[$principalUri][$objectUri])) {
             return $this->schedulingObjects[$principalUri][$objectUri];
         }
+
+        return [];
     }
 
     /**
diff --git a/tests/Sabre/CardDAV/Backend/Mock.php b/tests/Sabre/CardDAV/Backend/Mock.php
index 630465cc..6a570b15 100644
--- a/tests/Sabre/CardDAV/Backend/Mock.php
+++ b/tests/Sabre/CardDAV/Backend/Mock.php
@@ -253,5 +253,7 @@ class Mock extends AbstractBackend
     public function deleteCard($addressBookId, $cardUri)
     {
         unset($this->cards[$addressBookId][$cardUri]);
+
+        return true;
     }
 }
diff --git a/tests/Sabre/DAV/Mock/PropertiesCollection.php b/tests/Sabre/DAV/Mock/PropertiesCollection.php
index 23d236cc..42468f99 100644
--- a/tests/Sabre/DAV/Mock/PropertiesCollection.php
+++ b/tests/Sabre/DAV/Mock/PropertiesCollection.php
@@ -39,8 +39,6 @@ class PropertiesCollection extends Collection implements IProperties
      *
      * To update specific properties, call the 'handle' method on this object.
      * Read the PropPatch documentation for more information.
-     *
-     * @return bool|array
      */
     public function propPatch(PropPatch $proppatch)
     {
diff --git a/tests/Sabre/DAVACL/PrincipalBackend/Mock.php b/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
index c12710c9..359e6781 100644
--- a/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
+++ b/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
@@ -65,6 +65,8 @@ class Mock extends AbstractBackend
                 return $principal;
             }
         }
+
+        return [];
     }
 
     public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof')
diff --git a/tests/Sabre/DAVACL/Xml/Property/PrincipalTest.php b/tests/Sabre/DAVACL/Xml/Property/PrincipalTest.php
index 694e015e..9c1ee628 100644
--- a/tests/Sabre/DAVACL/Xml/Property/PrincipalTest.php
+++ b/tests/Sabre/DAVACL/Xml/Property/PrincipalTest.php
@@ -170,6 +170,10 @@ class PrincipalTest extends \PHPUnit\Framework\TestCase
                 new Principal(Principal::HREF, 'principals/admin'),
                 '<a href="/principals/admin/">/principals/admin/</a>',
             ],
+            [
+                new Principal(42),
+                '<em>unknown</em>',
+            ],
         ];
     }
 }