Passed
Pull Request — 1.1 (#1122)
by Tim
07:39
created

LdapClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * AppserverIo\Ldap\Symfony\LdapClient
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2019 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/appserver
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Appserver\Ldap\Symfony;
22
23
use Symfony\Component\Ldap\LdapInterface;
24
use AppserverIo\Ldap\LdapClientInterface;
25
use Symfony\Component\Ldap\Entry;
26
27
/**
28
 * Symfony based LDAP client implementation.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2019 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/appserver-io/appserver
34
 * @link      http://www.appserver.io
35
 */
36
class LdapClient implements LdapClientInterface, LdapInterface
37
{
38
39
    /**
40
     * The Symfony LDAP client instance.
41
     *
42
     * @var \Symfony\Component\Ldap\LdapClientInterface
43
     */
44
    protected $ldapClient;
45
46
    /**
47
     * Initializes the Entity Manager with the Symfony LDAP client instance.
48
     *
49
     * @param \Symfony\Component\Ldap\LdapInterface $ldapClient The LDAP client instance
50
     */
51
    public function __construct(LdapInterface $ldapClient)
52
    {
53
        $this->ldapClient = $ldapClient;
0 ignored issues
show
Documentation Bug introduced by
$ldapClient is of type Symfony\Component\Ldap\LdapInterface, but the property $ldapClient was declared to be of type Symfony\Component\Ldap\LdapClientInterface. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
54
    }
55
56
    /**
57
     * Return a connection bound to the ldap.
58
     *
59
     * @param string $dn       A LDAP dn
60
     * @param string $password A password
61
     *
62
     * @return void
63
     * @throws \Symfony\Component\Ldap\Exception\ConnectionException if dn / password could not be bound
64
     */
65
    public function bind($dn = null, $password = null)
66
    {
67
        return $this->ldapClient->bind($dn, $password);
68
    }
69
70
    /**
71
     * Queries a ldap server for entries matching the given criteria.
72
     *
73
     * @param string $dn      The DN to query
74
     * @param string $query   The query itself
75
     * @param array  $options The query options
76
     *
77
     * @return \Symfony\Component\Ldap\Adapter\CollectionInterface|\Symfony\Component\Ldap\Entry[] The query result
78
     * @throws \Symfony\Component\Ldap\Exception\ConnectionException
79
     */
80
    public function query($dn, $query, array $options = array())
81
    {
82
        return $this->ldapClient->query($dn, $query, $options);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->ldapClient...($dn, $query, $options) returns the type Symfony\Component\Ldap\Adapter\QueryInterface which is incompatible with the documented return type Symfony\Component\Ldap\E...ter\CollectionInterface.
Loading history...
83
    }
84
85
    /**
86
     * @return \Symfony\Component\Ldap\Adapter\EntryManagerInterface
87
     */
88
    public function getEntryManager()
89
    {
90
        return $this->ldapClient->getEntryManager();
91
    }
92
93
    /**
94
     * Escape a string for use in an LDAP filter or DN.
95
     *
96
     * @param string $subject The subject to escape
97
     * @param string $ignore  Do not ignore
98
     * @param int    $flags   The flags
99
     *
100
     * @return string The escaped string
101
     */
102
    public function escape($subject, $ignore = '', $flags = 0)
103
    {
104
        return $this->ldapClient->escape($subject, $ignore, $flags);
105
    }
106
}
107