Commit 0ece5b21 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚑 fix(ldap) Add strict_types declare and fix phpstan errors

The code now passes phpstan level 8.

issue #1
parent 6053e3ff
......@@ -18,6 +18,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
declare(strict_types=1);
namespace FusionDirectory\Ldap;
class Acl
......
......@@ -18,6 +18,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
declare(strict_types=1);
namespace FusionDirectory\Ldap;
class Exception extends \Exception
......
......@@ -18,6 +18,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
declare(strict_types=1);
namespace FusionDirectory\Ldap;
class Link
......@@ -54,7 +56,7 @@ class Link
ldap_start_tls($cid);
}
if (ldap_sasl_bind($cid, NULL, NULL, 'EXTERNAL') !== TRUE) {
if (ldap_sasl_bind($cid, '', '', 'EXTERNAL') !== TRUE) {
throw new Exception('Failed to bind to '.$this->hostname);
}
......@@ -70,6 +72,8 @@ class Link
$functions = ['base' => 'ldap_read','one' => 'ldap_list','subtree' => 'ldap_search'];
if (isset($controls)) {
/* @phpstan-ignore-next-line
* phpstan has an outdated signature for php-ldap functions */
$result = @$functions[strtolower($scope)]($this->cid, $basedn, $filter, $attrs, 0, 0, 0, LDAP_DEREF_NEVER, $controls);
} else {
$result = @$functions[strtolower($scope)]($this->cid, $basedn, $filter, $attrs);
......@@ -213,8 +217,8 @@ class Link
}
/* Remove ' and " if needed */
$value = preg_replace('/^[\'"]/', '', $value);
$value = preg_replace('/[\'"] *$/', '', $value);
$value = (preg_replace('/^[\'"]/', '', $value) ?? '');
$value = (preg_replace('/[\'"] *$/', '', $value) ?? '');
$value = rtrim($value);
/* Convert to array if $ is inside... */
......
......@@ -18,6 +18,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
declare(strict_types=1);
namespace FusionDirectory\Ldap;
/**
......@@ -90,6 +92,7 @@ class Result implements \Iterator,\Countable
public function current ()
{
assert(is_resource($this->cur));
$att = [];
for ($a = ldap_first_attribute($this->link, $this->cur); $a !== FALSE; $a = ldap_next_attribute($this->link, $this->cur)) {
$att[$a] = ldap_get_values($this->link, $this->cur, $a);
......@@ -100,11 +103,13 @@ class Result implements \Iterator,\Countable
public function key ()
{
assert(is_resource($this->cur));
return trim(ldap_get_dn($this->link, $this->cur));
}
public function next (): void
{
assert(is_resource($this->cur));
$this->cur = ldap_next_entry($this->link, $this->cur);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment