8000 minor #32253 [Ldap] [5.0] add type-hint to interface and implementati… · symfony/symfony@a6677ca · GitHub
[go: up one dir, main page]

Skip to content

Commit a6677ca

Browse files
committed
minor #32253 [Ldap] [5.0] add type-hint to interface and implementation (Simperfit)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Ldap] [5.0] add type-hint to interface and implementation | Q | A | ------------- | --- | Branch? | 5.0 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | Contribute to #32179 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> This adds the type-hint to the Ldap interfaces and implementation Commits ------- 03f2e90 [Ldap] [5.0] add type-hint to interface and implementation
2 parents eead643 + 03f2e90 commit a6677ca

File tree

11 files changed

+27
-49
lines changed

11 files changed

+27
-49
lines changed

src/Symfony/Component/Ldap/Adapter/AdapterInterface.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ public function getConnection();
2626
/**
2727
* Creates a new Query.
2828
*
29-
* @param string $dn
30-
* @param string $query
31-
* @param array $options
32-
*
3329
* @return QueryInterface
3430
*/
35-
public function createQuery($dn, $query, array $options = []);
31+
public function createQuery(string $dn, string $query, array $options = []);
3632

3733
/**
3834
* Fetches the entry manager instance.
@@ -44,11 +40,7 @@ public function getEntryManager();
4440
/**
4541
* Escape a string for use in an LDAP filter or DN.
4642
*
47-
* @param string $subject
48-
* @param string $ignore
49-
* @param int $flags
50-
*
5143
* @return string
5244
*/
53-
public function escape($subject, $ignore = '', $flags = 0);
45+
public function escape(string $subject, string $ignore = '', int $flags = 0);
5446
}

src/Symfony/Component/Ldap/Adapter/ConnectionInterface.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ interface ConnectionInterface
2424
public function isBound();
2525

2626
/**
27-
* Binds the connection against a DN and password.
28-
*
29-
* @param string $dn The user's DN
30-
* @param string $password The associated password
27+
* Binds the connection against a user's DN and password.
3128
*/
32-
public function bind($dn = null, $password = null);
29+
public function bind(string $dn = null, string $password = null);
3330
}

src/Symfony/Component/Ldap/Adapter/ExtLdap/Adapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public function getEntryManager()
5959
/**
6060
* {@inheritdoc}
6161
*/
62-
public function createQuery($dn, $query, array $options = [])
62+
public function createQuery(string $dn, string $query, array $options = [])
6363
{
6464
return new Query($this->getConnection(), $dn, $query, $options);
6565
}
6666

6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public function escape($subject, $ignore = '', $flags = 0)
70+
public function escape(string $subject, string $ignore = '', int $flags = 0)
7171
{
7272
$value = ldap_escape($subject, $ignore, $flags);
7373

src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function isBound()
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function bind($dn = null, $password = null)
54+
public function bind(string $dn = null, string $password = null)
5555
{
5656
if (!$this->connection) {
5757
$this->connect();
@@ -85,14 +85,14 @@ public function getResource()
8585
return $this->connection;
8686
}
8787

88-
public function setOption($name, $value)
88+
public function setOption(string $name, $value)
8989
{
9090
if (!@ldap_set_option($this->connection, ConnectionOptions::getOption($name), $value)) {
9191
throw new LdapException(sprintf('Could not set value "%s" for option "%s".', $value, $name));
9292
}
9393
}
9494

95-
public function getOption($name)
95+
public function getOption(string $name)
9696
{
9797
if (!@ldap_get_option($this->connection, ConnectionOptions::getOption($name), $ret)) {
9898
throw new LdapException(sprintf('Could not retrieve value for option "%s".', $name));

src/Symfony/Component/Ldap/Adapter/ExtLdap/ConnectionOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class ConnectionOptions
4545
const X_SASL_AUTHCID = 0x6102;
4646
const X_SASL_AUTHZID = 0x6103;
4747

48-
public static function getOptionName($name): string
48+
public static function getOptionName(string $name): string
4949
{
5050
return sprintf('%s::%s', self::class, strtoupper($name));
5151
}
@@ -58,7 +58,7 @@ public static function getOptionName($name): string
5858
*
5959
* @throws LdapException
6060
*/
61-
public static function getOption($name): int
61+
public static function getOption(string $name): int
6262
{
6363
// Convert
6464
$constantName = self::getOptionName($name);
@@ -70,7 +70,7 @@ public static function getOption($name): int
7070
return \constant($constantName);
7171
}
7272

73-
public static function isOption($name): bool
73+
public static function isOption(string $name): bool
7474
{
7575
return \defined(self::getOptionName($name));
7676
}

src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function removeAttributeValues(Entry $entry, string $attribute, array $va
101101
/**
102102
* {@inheritdoc}
103103
*/
104-
public function rename(Entry $entry, $newRdn, $removeOldRdn = true)
104+
public function rename(Entry $entry, string $newRdn, bool $removeOldRdn = true)
105105
{
106106
$con = $this->getConnectionResource();
107107

src/Symfony/Component/Ldap/Entry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getDn()
4242
*
4343
* @return bool
4444
*/
45-
public function hasAttribute($name)
45+
public function hasAttribute(string $name)
4646
{
4747
return isset($this->attributes[$name]);
4848
}
@@ -57,7 +57,7 @@ public function hasAttribute($name)
5757
*
5858
* @return array|null
5959
*/
60-
public function getAttribute($name)
60+
public function getAttribute(string $name)
6161
{
6262
return isset($this->attributes[$name]) ? $this->attributes[$name] : null;
6363
}
@@ -78,7 +78,7 @@ public function getAttributes()
7878
* @param string $name
7979
* @param array $value
8080
*/
81-
public function setAttribute($name, array $value)
81+
public function setAttribute(string $name, array $value)
8282
{
8383
$this->attributes[$name] = $value;
8484
}
@@ -88,7 +88,7 @@ public function setAttribute($name, array $value)
8888
*
8989
* @param string $name
9090
*/
91-
public function removeAttribute($name)
91+
public function removeAttribute(string $name)
9292
{
9393
unset($this->attributes[$name]);
9494
}

src/Symfony/Component/Ldap/Ldap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct(AdapterInterface $adapter)
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function bind($dn = null, $password = null)
38+
public function bind(string $dn = null, string $password = null)
3939
{
4040
$this->adapter->getConnection()->bind($dn, $password);
4141
}
4242

4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function query($dn, $query, array $options = []): ?QueryInterface
46+
public function query(string $dn, string $query, array $options = []): ?QueryInterface
4747
{
4848
return $this->adapter->createQuery($dn, $query, $options);
4949
}
@@ -59,7 +59,7 @@ public function getEntryManager(): ?EntryManagerInterface
5959
/**
6060
* {@inheritdoc}
6161
*/
62-
public function escape($subject, $ignore = '', $flags = 0): ?string
62+
public function escape(string $subject, string $ignore = '', int $flags = 0): ?string
6363
{
6464
return $this->adapter->escape($subject, $ignore, $flags);
6565
}
@@ -72,7 +72,7 @@ public function escape($subject, $ignore = '', $flags = 0): ?string
7272
*
7373
* @return static
7474
*/
75-
public static function create($adapter, array $config = []): self
75+
public static function create(string $adapter, array $config = []): self
7676
{
7777
if (!isset(self::$adapterMap[$adapter])) {
7878
throw new DriverNotFoundException(sprintf(

src/Symfony/Component/Ldap/LdapInterface.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,16 @@ interface LdapInterface
2828
/**
2929
* Return a connection bound to the ldap.
3030
*
31-
* @param string $dn A LDAP dn
32-
* @param string $password A password
33-
*
3431
* @throws ConnectionException if dn / password could not be bound
3532
*/
36-
public function bind($dn = null, $password = null);
33+
public function bind(string $dn = null, string $password = null);
3734

3835
/**
3936
* Queries a ldap server for entries matching the given criteria.
4037
*
41-
* @param string $dn
42-
* @param string $query
43-
* @param array $options
44-
*
4538
* @return QueryInterface
4639
*/
47-
public function query($dn, $query, array $options = []);
40+
public function query(string $dn, string $query, array $options = []);
4841

4942
/**
5043
* @return EntryManagerInterface
@@ -54,11 +47,7 @@ public function getEntryManager();
5447
/**
5548
* Escape a string for use in an LDAP filter or DN.
5649
*
57-
* @param string $subject
58-
* @param string $ignore
59-
* @param int $flags
60-
*
6150
* @return string
6251
*/
63-
public function escape($subject, $ignore = '', $flags = 0);
52+
public function escape(string $subject, string $ignore = '', int $flags = 0);
6453
}

src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testLdapEscape()
3434
{
3535
$ldap = new Adapter();
3636

37-
$this->assertEquals('\20foo\3dbar\0d(baz)*\20', $ldap->escape(" foo=bar\r(baz)* ", null, LdapInterface::ESCAPE_DN));
37+
$this->assertEquals('\20foo\3dbar\0d(baz)*\20', $ldap->escape(" foo=bar\r(baz)* ", '', LdapInterface::ESCAPE_DN));
3838
}
3939

4040
/**

src/Symfony/Component/Ldap/Tests/LdapTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public function testLdapEscape()
5252
$this->adapter
5353
->expects($this->once())
5454
->method('escape')
55-
->with('foo', 'bar', 'baz')
55+
->with('foo', 'bar', 0)
5656
;
57-
$this->ldap->escape('foo', 'bar', 'baz');
57+
$this->ldap->escape('foo', 'bar', 0);
5858
}
5959

6060
public function testLdapQuery()

0 commit comments

Comments
 (0)
0