]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Remove obsolete resource typing
authorCôme Chilliet <come.chilliet@nextcloud.com>
Thu, 4 Apr 2024 14:14:06 +0000 (16:14 +0200)
committerCôme Chilliet <91878298+come-nc@users.noreply.github.com>
Tue, 9 Apr 2024 08:01:47 +0000 (10:01 +0200)
In PHP>=8.1, LDAP and FTP resources are always typed objects

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
13 files changed:
apps/files_external/lib/Lib/Storage/FtpConnection.php
apps/user_ldap/lib/Access.php
apps/user_ldap/lib/Connection.php
apps/user_ldap/lib/Group_LDAP.php
apps/user_ldap/lib/Group_Proxy.php
apps/user_ldap/lib/IGroupLDAP.php
apps/user_ldap/lib/ILDAPWrapper.php
apps/user_ldap/lib/IUserLDAP.php
apps/user_ldap/lib/LDAP.php
apps/user_ldap/lib/LDAPProvider.php
apps/user_ldap/lib/User_LDAP.php
apps/user_ldap/lib/User_Proxy.php
apps/user_ldap/lib/Wizard.php

index cca03ddda65d6ae96fc2012e8b4c333d87b959ad..fa7302d0460551c1160213dc04032aa88be74921 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 declare(strict_types=1);
+
 /**
  * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
  *
@@ -27,8 +28,7 @@ namespace OCA\Files_External\Lib\Storage;
  * Low level wrapper around the ftp functions that smooths over some difference between servers
  */
 class FtpConnection {
-       /** @var resource|\FTP\Connection */
-       private $connection;
+       private \FTP\Connection $connection;
 
        public function __construct(bool $secure, string $hostname, int $port, string $username, string $password) {
                if ($secure) {
index a51dfc3b349f58ce601e491aab26a4bd1ff1d161..70332cb1c165df9aa061cd5276293d1f6c44f2bb 100644 (file)
@@ -1136,7 +1136,7 @@ class Access extends LDAPUtility {
        /**
         * processes an LDAP paged search operation
         *
-        * @param resource|\LDAP\Result|resource[]|\LDAP\Result[] $sr the array containing the LDAP search resources
+        * @param \LDAP\Result|\LDAP\Result[] $sr the array containing the LDAP search resources
         * @param int $foundItems number of results in the single search operation
         * @param int $limit maximum results to be counted
         * @param bool $pagedSearchOK whether a paged search has been executed
@@ -1249,7 +1249,7 @@ class Access extends LDAPUtility {
        }
 
        /**
-        * @param resource|\LDAP\Result|resource[]|\LDAP\Result[] $sr
+        * @param \LDAP\Result|\LDAP\Result[] $sr
         * @return int
         * @throws ServerNotAvailableException
         */
index 788344b4e7d035a057b4f2706d9c481d49210f96..212bb2fd3364180f14d3d951815ece4af728e499 100644 (file)
@@ -86,30 +86,15 @@ use Psr\Log\LoggerInterface;
  * @property string ldapAdminGroup
  */
 class Connection extends LDAPUtility {
-       /**
-        * @var resource|\LDAP\Connection|null
-        */
-       private $ldapConnectionRes = null;
-
-       /**
-        * @var string
-        */
-       private $configPrefix;
-
-       /**
-        * @var ?string
-        */
-       private $configID;
-
-       /**
-        * @var bool
-        */
-       private $configured = false;
+       private ?\LDAP\Connection $ldapConnectionRes = null;
+       private string $configPrefix;
+       private ?string $configID;
+       private bool $configured = false;
 
        /**
         * @var bool whether connection should be kept on __destruct
         */
-       private $dontDestruct = false;
+       private bool $dontDestruct = false;
 
        /**
         * @var bool runtime flag that indicates whether supported primary groups are available
@@ -241,9 +226,9 @@ class Connection extends LDAPUtility {
        }
 
        /**
-        * @return resource|\LDAP\Connection The LDAP resource
+        * @return \LDAP\Connection The LDAP resource
         */
-       public function getConnectionResource() {
+       public function getConnectionResource(): \LDAP\Connection {
                if (!$this->ldapConnectionRes) {
                        $this->init();
                } elseif (!$this->ldap->isResource($this->ldapConnectionRes)) {
@@ -263,7 +248,7 @@ class Connection extends LDAPUtility {
        /**
         * resets the connection resource
         */
-       public function resetConnectionResource() {
+       public function resetConnectionResource(): void {
                if (!is_null($this->ldapConnectionRes)) {
                        @$this->ldap->unbind($this->ldapConnectionRes);
                        $this->ldapConnectionRes = null;
@@ -273,9 +258,8 @@ class Connection extends LDAPUtility {
 
        /**
         * @param string|null $key
-        * @return string
         */
-       private function getCacheKey($key) {
+       private function getCacheKey($key): string {
                $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
                if (is_null($key)) {
                        return $prefix;
@@ -332,9 +316,8 @@ class Connection extends LDAPUtility {
         * Caches the general LDAP configuration.
         * @param bool $force optional. true, if the re-read should be forced. defaults
         * to false.
-        * @return null
         */
-       private function readConfiguration($force = false) {
+       private function readConfiguration(bool $force = false): void {
                if ((!$this->configured || $force) && !is_null($this->configID)) {
                        $this->configuration->readConfiguration();
                        $this->configured = $this->validateConfiguration();
@@ -406,7 +389,7 @@ class Connection extends LDAPUtility {
                return $result;
        }
 
-       private function doSoftValidation() {
+       private function doSoftValidation(): void {
                //if User or Group Base are not set, take over Base DN setting
                foreach (['ldapBaseUsers', 'ldapBaseGroups'] as $keyBase) {
                        $val = $this->configuration->$keyBase;
@@ -461,10 +444,7 @@ class Connection extends LDAPUtility {
                }
        }
 
-       /**
-        * @return bool
-        */
-       private function doCriticalValidation() {
+       private function doCriticalValidation(): bool {
                $configurationOK = true;
                $errorStr = 'Configuration Error (prefix '.
                        (string)$this->configPrefix .'): ';
@@ -552,7 +532,7 @@ class Connection extends LDAPUtility {
         * Validates the user specified configuration
         * @return bool true if configuration seems OK, false otherwise
         */
-       private function validateConfiguration() {
+       private function validateConfiguration(): bool {
                if ($this->doNotValidate) {
                        //don't do a validation if it is a new configuration with pure
                        //default values. Will be allowed on changes via __set or
@@ -575,7 +555,7 @@ class Connection extends LDAPUtility {
         *
         * @throws ServerNotAvailableException
         */
-       private function establishConnection() {
+       private function establishConnection(): ?bool {
                if (!$this->configuration->ldapConfigurationActive) {
                        return null;
                }
@@ -663,10 +643,9 @@ class Connection extends LDAPUtility {
        /**
         * @param string $host
         * @param string $port
-        * @return bool
         * @throws \OC\ServerNotAvailableException
         */
-       private function doConnect($host, $port) {
+       private function doConnect($host, $port): bool {
                if ($host === '') {
                        return false;
                }
index 699205cf501b511f1119a687619b89fa242f401c..09bdbd6db963da5e8ee6983131b77a3c0708864e 100644 (file)
@@ -1374,10 +1374,10 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
         * of the current access.
         *
         * @param string $gid
-        * @return resource|\LDAP\Connection The LDAP connection
+        * @return \LDAP\Connection The LDAP connection
         * @throws ServerNotAvailableException
         */
-       public function getNewLDAPConnection($gid) {
+       public function getNewLDAPConnection($gid): \LDAP\Connection {
                $connection = clone $this->access->getConnection();
                return $connection->getConnectionResource();
        }
index 7410aa6a6e9d078ffda5c3c010f953681648bb3d..1544d5f91e9e477a881f129d1d141ff26c38884d 100644 (file)
@@ -371,9 +371,9 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
         * The connection needs to be closed manually.
         *
         * @param string $gid
-        * @return resource|\LDAP\Connection The LDAP connection
+        * @return \LDAP\Connection The LDAP connection
         */
-       public function getNewLDAPConnection($gid) {
+       public function getNewLDAPConnection($gid): \LDAP\Connection {
                return $this->handleRequest($gid, 'getNewLDAPConnection', [$gid]);
        }
 
index 2face1aa90748c31f98bb1b212da71250c970edb..ee83c18a8c6a9db4a7f084a922b6fce8db153b12 100644 (file)
@@ -36,7 +36,7 @@ interface IGroupLDAP {
        /**
         * Return a new LDAP connection for the specified group.
         * @param string $gid
-        * @return resource|\LDAP\Connection The LDAP connection
+        * @return \LDAP\Connection The LDAP connection
         */
        public function getNewLDAPConnection($gid);
 }
index 6ec88effa5f2c3249fccd899c44ba9ed0d81a390..8151c0207524362d6463bea2f813dbc71b4a9eef 100644 (file)
@@ -34,7 +34,7 @@ interface ILDAPWrapper {
 
        /**
         * Bind to LDAP directory
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @param string $dn an RDN to log in with
         * @param string $password the password
         * @return bool true on success, false otherwise
@@ -47,14 +47,14 @@ interface ILDAPWrapper {
         * connect to an LDAP server
         * @param string $host The host to connect to
         * @param string $port The port to connect to
-        * @return resource|\LDAP\Connection|false a link resource on success, otherwise false
+        * @return \LDAP\Connection|false a link resource on success, otherwise false
         */
        public function connect($host, $port);
 
        /**
         * Retrieve the LDAP pagination cookie
-        * @param resource|\LDAP\Connection $link LDAP link resource
-        * @param resource|\LDAP\Result $result LDAP result resource
+        * @param \LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Result $result LDAP result resource
         * @param string &$cookie structure sent by LDAP server
         * @return bool true on success, false otherwise
         *
@@ -64,22 +64,22 @@ interface ILDAPWrapper {
 
        /**
         * Count the number of entries in a search
-        * @param resource|\LDAP\Connection $link LDAP link resource
-        * @param resource|\LDAP\Result $result LDAP result resource
+        * @param \LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Result $result LDAP result resource
         * @return int|false number of results on success, false otherwise
         */
        public function countEntries($link, $result);
 
        /**
         * Return the LDAP error number of the last LDAP command
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @return int error code
         */
        public function errno($link);
 
        /**
         * Return the LDAP error message of the last LDAP command
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @return string error message
         */
        public function error($link);
@@ -95,69 +95,69 @@ interface ILDAPWrapper {
 
        /**
         * Return first result id
-        * @param resource|\LDAP\Connection $link LDAP link resource
-        * @param resource|\LDAP\Result $result LDAP result resource
-        * @return resource|\LDAP\ResultEntry an LDAP entry resource
+        * @param \LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Result $result LDAP result resource
+        * @return \LDAP\ResultEntry an LDAP entry resource
         * */
        public function firstEntry($link, $result);
 
        /**
         * Get attributes from a search result entry
-        * @param resource|\LDAP\Connection $link LDAP link resource
-        * @param resource|\LDAP\ResultEntry $result LDAP result resource
+        * @param \LDAP\Connection $link LDAP link resource
+        * @param \LDAP\ResultEntry $result LDAP result resource
         * @return array|false containing the results, false on error
         * */
        public function getAttributes($link, $result);
 
        /**
         * Get the DN of a result entry
-        * @param resource|\LDAP\Connection $link LDAP link resource
-        * @param resource|\LDAP\ResultEntry $result LDAP result resource
+        * @param \LDAP\Connection $link LDAP link resource
+        * @param \LDAP\ResultEntry $result LDAP result resource
         * @return string|false containing the DN, false on error
         */
        public function getDN($link, $result);
 
        /**
         * Get all result entries
-        * @param resource|\LDAP\Connection $link LDAP link resource
-        * @param resource|\LDAP\Result $result LDAP result resource
+        * @param \LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Result $result LDAP result resource
         * @return array|false containing the results, false on error
         */
        public function getEntries($link, $result);
 
        /**
         * Return next result id
-        * @param resource|\LDAP\Connection $link LDAP link resource
-        * @param resource|\LDAP\ResultEntry $result LDAP result resource
-        * @return resource|\LDAP\ResultEntry an LDAP entry resource
+        * @param \LDAP\Connection $link LDAP link resource
+        * @param \LDAP\ResultEntry $result LDAP result resource
+        * @return \LDAP\ResultEntry an LDAP entry resource
         * */
        public function nextEntry($link, $result);
 
        /**
         * Read an entry
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @param string $baseDN The DN of the entry to read from
         * @param string $filter An LDAP filter
         * @param array $attr array of the attributes to read
-        * @return resource|\LDAP\Result an LDAP search result resource
+        * @return \LDAP\Result an LDAP search result resource
         */
        public function read($link, $baseDN, $filter, $attr);
 
        /**
         * Search LDAP tree
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @param string $baseDN The DN of the entry to read from
         * @param string $filter An LDAP filter
         * @param array $attr array of the attributes to read
         * @param int $attrsOnly optional, 1 if only attribute types shall be returned
         * @param int $limit optional, limits the result entries
-        * @return resource|\LDAP\Result|false an LDAP search result resource, false on error
+        * @return \LDAP\Result|false an LDAP search result resource, false on error
         */
        public function search($link, string $baseDN, string $filter, array $attr, int $attrsOnly = 0, int $limit = 0, int $pageSize = 0, string $cookie = '');
 
        /**
         * Replace the value of a userPassword by $password
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @param string $userDN the DN of the user whose password is to be replaced
         * @param string $password the new value for the userPassword
         * @return bool true on success, false otherwise
@@ -166,14 +166,14 @@ interface ILDAPWrapper {
 
        /**
         * Performs a PASSWD extended operation.
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @return bool|string The generated password if new_password is empty or omitted. Otherwise true on success and false on failure.
         */
        public function exopPasswd($link, string $userDN, string $oldPassword, string $password);
 
        /**
         * Sets the value of the specified option to be $value
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @param int $option a defined LDAP Server option
         * @param mixed $value the new value for the option
         * @return bool true on success, false otherwise
@@ -182,14 +182,14 @@ interface ILDAPWrapper {
 
        /**
         * establish Start TLS
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @return bool true on success, false otherwise
         */
        public function startTls($link);
 
        /**
         * Unbind from LDAP directory
-        * @param resource|\LDAP\Connection $link LDAP link resource
+        * @param \LDAP\Connection $link LDAP link resource
         * @return bool true on success, false otherwise
         */
        public function unbind($link);
index dfba11c5d34348dadbf62b6df1f61f45ba97091f..b4df16728a2e80cb1e970e7d94908f6ad2baae1d 100644 (file)
@@ -37,7 +37,7 @@ interface IUserLDAP {
        /**
         * Return a new LDAP connection for the specified user.
         * @param string $uid
-        * @return resource|\LDAP\Connection of the LDAP connection
+        * @return \LDAP\Connection of the LDAP connection
         */
        public function getNewLDAPConnection($uid);
 
index 8e63422b1ac4b64143d01b0b649734405cbc63a6..01f4e16ab10006649c9d8bc8f2f442da94f6c918 100644 (file)
@@ -360,7 +360,7 @@ class LDAP implements ILDAPWrapper {
        /**
         * Analyzes the returned LDAP error and acts accordingly if not 0
         *
-        * @param resource|\LDAP\Connection $resource the LDAP Connection resource
+        * @param \LDAP\Connection $resource the LDAP Connection resource
         * @throws ConstraintViolationException
         * @throws ServerNotAvailableException
         * @throws \Exception
index 751ebf68768472e15a2afdb7dd106e1bdfdddcb4..353eefb7be4f492691082a036dd79fba3d60cc5c 100644 (file)
@@ -149,7 +149,7 @@ class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport {
         * Return a new LDAP connection resource for the specified user.
         * The connection must be closed manually.
         * @param string $uid user id
-        * @return resource|\LDAP\Connection The LDAP connection
+        * @return \LDAP\Connection The LDAP connection
         * @throws \Exception if user id was not found in LDAP
         */
        public function getLDAPConnection($uid) {
@@ -163,7 +163,7 @@ class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport {
         * Return a new LDAP connection resource for the specified user.
         * The connection must be closed manually.
         * @param string $gid group id
-        * @return resource|\LDAP\Connection The LDAP connection
+        * @return \LDAP\Connection The LDAP connection
         * @throws \Exception if group id was not found in LDAP
         */
        public function getGroupLDAPConnection($gid) {
index d787bfea4d40c7b7320e59688e09f1d7a22f3659..7d5562f0ee013de80b303eb54dca61982dd224d2 100644 (file)
@@ -622,7 +622,7 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
         * The cloned connection needs to be closed manually.
         * of the current access.
         * @param string $uid
-        * @return resource|\LDAP\Connection The LDAP connection
+        * @return \LDAP\Connection The LDAP connection
         */
        public function getNewLDAPConnection($uid) {
                $connection = clone $this->access->getConnection();
index 934bed7d450474b4548b4f0ba9a84dc00f0ac64a..96415491e412900c2a9951cda9842f4f087d257a 100644 (file)
@@ -438,7 +438,7 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP
         * The connection needs to be closed manually.
         *
         * @param string $uid
-        * @return resource|\LDAP\Connection The LDAP connection
+        * @return \LDAP\Connection The LDAP connection
         */
        public function getNewLDAPConnection($uid) {
                return $this->handleRequest($uid, 'getNewLDAPConnection', [$uid]);
index 1f4794f164e6f1defc8c0d464edf5009a792fa2c..be83be66786a57a821fbad442d58b1af052de20e 100644 (file)
@@ -48,8 +48,7 @@ use Psr\Log\LoggerInterface;
 class Wizard extends LDAPUtility {
        protected static ?IL10N $l = null;
        protected Access $access;
-       /** @var resource|\LDAP\Connection|null */
-       protected $cr;
+       protected ?\LDAP\Connection $cr = null;
        protected Configuration $configuration;
        protected WizardResult $result;
        protected LoggerInterface $logger;
@@ -361,7 +360,7 @@ class Wizard extends LDAPUtility {
                if (!$this->ldap->isResource($rr)) {
                        return false;
                }
-               /** @var resource|\LDAP\Result $rr */
+               /** @var \LDAP\Result $rr */
                $er = $this->ldap->firstEntry($cr, $rr);
                $attributes = $this->ldap->getAttributes($cr, $er);
                if ($attributes === false) {
@@ -649,7 +648,7 @@ class Wizard extends LDAPUtility {
                if (!$this->ldap->isResource($cr)) {
                        throw new \Exception('connection error');
                }
-               /** @var resource|\LDAP\Connection $cr */
+               /** @var \LDAP\Connection $cr */
 
                if (mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8')
                        === false) {
@@ -819,7 +818,7 @@ class Wizard extends LDAPUtility {
                if (!$this->ldap->isResource($rr)) {
                        return false;
                }
-               /** @var resource|\LDAP\Result $rr */
+               /** @var \LDAP\Result $rr */
                $er = $this->ldap->firstEntry($cr, $rr);
                while ($this->ldap->isResource($er)) {
                        $this->ldap->getDN($cr, $er);
@@ -866,7 +865,7 @@ class Wizard extends LDAPUtility {
                        );
                        return false;
                }
-               /** @var resource|\LDAP\Result $rr */
+               /** @var \LDAP\Result $rr */
                $entries = $this->ldap->countEntries($cr, $rr);
                return ($entries !== false) && ($entries > 0);
        }
@@ -929,7 +928,7 @@ class Wizard extends LDAPUtility {
                                                        if (!$this->ldap->isResource($rr)) {
                                                                continue;
                                                        }
-                                                       /** @var resource|\LDAP\Result $rr */
+                                                       /** @var \LDAP\Result $rr */
                                                        $er = $this->ldap->firstEntry($cr, $rr);
                                                        $attrs = $this->ldap->getAttributes($cr, $er);
                                                        $dn = $this->ldap->getDN($cr, $er);
@@ -1073,7 +1072,7 @@ class Wizard extends LDAPUtility {
                if (!$this->ldap->isResource($cr)) {
                        throw new \Exception(self::$l->t('Invalid Host'));
                }
-               /** @var resource|\LDAP\Connection $cr */
+               /** @var \LDAP\Connection $cr */
 
                //set LDAP options
                $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
@@ -1169,7 +1168,7 @@ class Wizard extends LDAPUtility {
                if (!$this->ldap->isResource($cr)) {
                        return false;
                }
-               /** @var resource|\LDAP\Connection $cr */
+               /** @var \LDAP\Connection $cr */
                $lastFilter = null;
                if (isset($filters[count($filters) - 1])) {
                        $lastFilter = $filters[count($filters) - 1];
@@ -1184,7 +1183,7 @@ class Wizard extends LDAPUtility {
                        if (!$this->ldap->isResource($rr)) {
                                continue;
                        }
-                       /** @var resource|\LDAP\Result $rr */
+                       /** @var \LDAP\Result $rr */
                        $entries = $this->ldap->countEntries($cr, $rr);
                        $getEntryFunc = 'firstEntry';
                        if (($entries !== false) && ($entries > 0)) {
@@ -1310,9 +1309,9 @@ class Wizard extends LDAPUtility {
        }
 
        /**
-        * @return resource|\LDAP\Connection|false a link resource on success, otherwise false
+        * @return \LDAP\Connection|false a link resource on success, otherwise false
         */
-       private function getConnection() {
+       private function getConnection(): \LDAP\Connection|false {
                if (!is_null($this->cr)) {
                        return $this->cr;
                }