Skip to content

Commit 7a67509

Browse files
Fixes PSR test
1 parent 22c02e7 commit 7a67509

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+344
-183
lines changed

API.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*/
9+
810
namespace Piwik\Plugins\LoginLdap;
911

1012
use Piwik\Common;
@@ -95,9 +97,9 @@ public function getCountOfUsersMemberOf($memberOf)
9597

9698
$memberOfField = Config::getRequiredMemberOfField();
9799

98-
return $this->ldapUsers->getCountOfUsersMatchingFilter("(".$memberOfField."=?)", array($memberOf));
100+
return $this->ldapUsers->getCountOfUsersMatchingFilter("(" . $memberOfField . "=?)", array($memberOf));
99101
}
100-
102+
101103
/**
102104
* Returns count of users in LDAP that match an LDAP filter. If the filter is incorrect,
103105
* `null` is returned.
@@ -163,4 +165,4 @@ private function checkHttpMethodIsPost()
163165
throw new Exception("Invalid HTTP method.");
164166
}
165167
}
166-
}
168+
}

Auth/Base.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*/
9+
810
namespace Piwik\Plugins\LoginLdap\Auth;
911

1012
use Exception;
@@ -89,7 +91,7 @@ abstract class Base implements Auth
8991
*
9092
* @var string[]
9193
*/
92-
protected $userForLogin = null;
94+
protected $userForLogin = null;
9395

9496
/**
9597
* @var LoggerInterface
@@ -279,7 +281,7 @@ protected function getUserForLogin()
279281
if (empty($this->userForLogin)) {
280282
if (!empty($this->login)) {
281283
$this->userForLogin = $this->usersModel->getUser($this->login);
282-
} else if (!empty($this->token_auth)) {
284+
} elseif (!empty($this->token_auth)) {
283285
$this->userForLogin = $this->usersModel->getUserByTokenAuth($this->token_auth);
284286
} else {
285287
throw new Exception("Cannot get user details, neither login nor token auth are set.");
@@ -304,7 +306,7 @@ protected function tryFallbackAuth($onlySuperUsers = true, Auth $auth = null)
304306
$this->logger->debug("Auth\\Base::{func}: trying normal auth with user password", array('func' => __FUNCTION__));
305307

306308
$auth->setPassword($this->password);
307-
} else if (!empty($this->passwordHash)) {
309+
} elseif (!empty($this->passwordHash)) {
308310
$this->logger->debug("Auth\\Base::{func}: trying normal auth with hashed password", array('func' => __FUNCTION__));
309311

310312
$auth->setPasswordHash($this->passwordHash);
@@ -321,7 +323,8 @@ protected function tryFallbackAuth($onlySuperUsers = true, Auth $auth = null)
321323
'login' => $this->login
322324
));
323325

324-
if (!$onlySuperUsers
326+
if (
327+
!$onlySuperUsers
325328
|| $result->getCode() == AuthResult::SUCCESS_SUPERUSER_AUTH_CODE
326329
) {
327330
return $result;
@@ -384,10 +387,10 @@ public static function factory()
384387
{
385388
if (Config::shouldUseWebServerAuthentication()) {
386389
return WebServerAuth::makeConfigured();
387-
} else if (Config::getUseLdapForAuthentication()) {
390+
} elseif (Config::getUseLdapForAuthentication()) {
388391
return LdapAuth::makeConfigured();
389392
} else {
390393
return SynchronizedAuth::makeConfigured();
391394
}
392395
}
393-
}
396+
}

Auth/LdapAuth.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*/
9+
810
namespace Piwik\Plugins\LoginLdap\Auth;
911

1012
use Exception;
@@ -134,4 +136,4 @@ public static function makeConfigured()
134136
$result->setUserSynchronizer(UserSynchronizer::makeConfigured());
135137
return $result;
136138
}
137-
}
139+
}

Auth/SynchronizedAuth.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*/
9+
810
namespace Piwik\Plugins\LoginLdap\Auth;
911

1012
use Exception;
@@ -64,15 +66,19 @@ public function authenticate()
6466
}
6567

6668
if (!$this->synchronizeUsersAfterSuccessfulLogin) {
67-
$this->logger->debug("SynchronizedAuth::{func}: synchronizing users after login disabled, not attempting LDAP authenticate for '{login}'.",
68-
array('func' => __FUNCTION__, 'login' => $this->login));
69+
$this->logger->debug(
70+
"SynchronizedAuth::{func}: synchronizing users after login disabled, not attempting LDAP authenticate for '{login}'.",
71+
array('func' => __FUNCTION__, 'login' => $this->login)
72+
);
6973

7074
return $this->makeAuthFailure();
7175
}
7276

7377
if (empty($this->password)) {
74-
$this->logger->debug("SynchronizedAuth::{func}: cannot attempt fallback LDAP login for '{login}', password not set.",
75-
array('func' => __FUNCTION__, 'login' => $this->login));
78+
$this->logger->debug(
79+
"SynchronizedAuth::{func}: cannot attempt fallback LDAP login for '{login}', password not set.",
80+
array('func' => __FUNCTION__, 'login' => $this->login)
81+
);
7682

7783
return $this->makeAuthFailure();
7884
}
@@ -147,4 +153,4 @@ public static function makeConfigured()
147153

148154
return $result;
149155
}
150-
}
156+
}

Auth/WebServerAuth.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*/
9+
810
namespace Piwik\Plugins\LoginLdap\Auth;
911

1012
use Exception;

Commands/SynchronizeUsers.php

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*/
9+
810
namespace Piwik\Plugins\LoginLdap\Commands;
911

1012
use Exception;
@@ -47,13 +49,24 @@ protected function configure()
4749
{
4850
$this->setName('loginldap:synchronize-users');
4951
$this->setDescription('Synchronizes one, multiple or all LDAP users that the current config has access to.');
50-
$this->addRequiredValueOption('login', null,
51-
'List of users to synchronize. If not specified, all users in LDAP are synchronized.', null, true);
52-
$this->addNoValueOption('skip-existing', null,
52+
$this->addRequiredValueOption(
53+
'login',
54+
null,
55+
'List of users to synchronize. If not specified, all users in LDAP are synchronized.',
56+
null,
57+
true
58+
);
59+
$this->addNoValueOption(
60+
'skip-existing',
61+
null,
5362
"Skip users that have been synchronized at least once. Using this option will be much faster, but will not "
54-
. "update user info if it has changed in LDAP.");
55-
$this->addNoValueOption('purge-non-existent-users', null,
56-
"Purge users from Matomo that no longer exist in LDAP.");
63+
. "update user info if it has changed in LDAP."
64+
);
65+
$this->addNoValueOption(
66+
'purge-non-existent-users',
67+
null,
68+
"Purge users from Matomo that no longer exist in LDAP."
69+
);
5770
}
5871

5972
/**
@@ -75,7 +88,8 @@ protected function doExecute(): int
7588
$failed = [];
7689

7790
foreach ($logins as $login) {
78-
if ($skipExisting
91+
if (
92+
$skipExisting
7993
&& $this->userExistsInPiwik($login)
8094
) {
8195
$output->write("Skipping '$login', already exists in Piwik...");
@@ -130,4 +144,4 @@ private function userExistsInPiwik($login)
130144
{
131145
return $this->usersManagerAPI->userExists($login);
132146
}
133-
}
147+
}

Config.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*/
9+
810
namespace Piwik\Plugins\LoginLdap;
911

1012
use Exception;
@@ -71,7 +73,7 @@ public static function getConfigOptionFrom($config, $optionName)
7173
{
7274
if (isset($config[$optionName])) {
7375
return $config[$optionName];
74-
} else if (isset(self::$alternateOptionNames[$optionName])) {
76+
} elseif (isset(self::$alternateOptionNames[$optionName])) {
7577
foreach (self::$alternateOptionNames[$optionName] as $alternateName) {
7678
if (isset($config[$alternateName])) {
7779
return $config[$alternateName];
@@ -255,7 +257,8 @@ public static function getPluginOptionValuesWithDefaults()
255257
$actualValue = Config::getConfigOption($name);
256258

257259
// special check for useKerberos which can be a string
258-
if ($name == 'use_webserver_auth'
260+
if (
261+
$name == 'use_webserver_auth'
259262
&& $actualValue === 'false'
260263
) {
261264
$actualValue = 0;
@@ -290,7 +293,7 @@ public static function saveLdapServerConfigs($servers)
290293

291294
$serverNames[] = $serverInfo['name'];
292295
}
293-
PiwikConfig::getInstance()->LoginLdap['servers']= $serverNames;
296+
PiwikConfig::getInstance()->LoginLdap['servers'] = $serverNames;
294297

295298
PiwikConfig::getInstance()->forceSave();
296299
}

Controller.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*/
9+
810
namespace Piwik\Plugins\LoginLdap;
911

1012
use Exception;
@@ -89,5 +91,4 @@ public function confirmPassword()
8991

9092
$this->passwordVerify->setPasswordVerifiedCorrectly();
9193
}
92-
93-
}
94+
}

Ldap/Client.php

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*
89
*/
10+
911
namespace Piwik\Plugins\LoginLdap\Ldap;
1012

1113
use Exception;
@@ -18,7 +20,7 @@
1820
*/
1921
class Client
2022
{
21-
const DEFAULT_TIMEOUT_SECS = 15;
23+
public const DEFAULT_TIMEOUT_SECS = 15;
2224

2325
private static $initialBindErrorCodesToIgnore = array(
2426
7, // LDAP_AUTH_METHOD_NOT_SUPPORTED
@@ -48,9 +50,12 @@ class Client
4850
* @param int $port The server port to use.
4951
* @throws Exception if a connection is attempted and it fails.
5052
*/
51-
public function __construct($serverHostName = null, $port = ServerInfo::DEFAULT_LDAP_PORT, $timeout = self::DEFAULT_TIMEOUT_SECS,
52-
LoggerInterface $logger = null)
53-
{
53+
public function __construct(
54+
$serverHostName = null,
55+
$port = ServerInfo::DEFAULT_LDAP_PORT,
56+
$timeout = self::DEFAULT_TIMEOUT_SECS,
57+
LoggerInterface $logger = null
58+
) {
5459
$this->logger = $logger ?: StaticContainer::get(LoggerInterface::class);
5560

5661
if (!empty($serverHostName)) {
@@ -97,9 +102,9 @@ public function connect($serverHostName, $port = ServerInfo::DEFAULT_LDAP_PORT,
97102
// to test the connection
98103
try {
99104
if ($startTLS) {
100-
if (!ldap_start_tls($this->connectionResource)) {
101-
throw new Exception("ldap_start_tls failed: " . ldap_error($this->connectionResource));
102-
}
105+
if (!ldap_start_tls($this->connectionResource)) {
106+
throw new Exception("ldap_start_tls failed: " . ldap_error($this->connectionResource));
107+
}
103108
}
104109
ldap_bind($this->connectionResource);
105110

@@ -339,7 +344,8 @@ private function transformLdapInfo($ldapInfo)
339344

340345
if (is_array($value)) { // index is for array, ie 0 => array(...)
341346
$result[$i] = $this->transformLdapInfo($value);
342-
} else if (!is_numeric($value)
347+
} elseif (
348+
!is_numeric($value)
343349
&& isset($ldapInfo[$value])
344350
) { // index is for name of attribute, ie 0 => 'cn', 'cn' => array(...)
345351
$key = strtolower($value);
@@ -408,7 +414,8 @@ public static function escapeFilterParameter($value)
408414
if (function_exists('ldap_escape')) { // available in PHP 5.6
409415
return ldap_escape($value, $ignoreChars = "", LDAP_ESCAPE_FILTER);
410416
} else {
411-
return preg_replace_callback("/[*()\\\\]/", function ($matches) { // replace special filter characters
417+
return preg_replace_callback("/[*()\\\\]/", function ($matches) {
418+
// replace special filter characters
412419
return "\\" . bin2hex($matches[0]);
413420
}, $value);
414421
}

Ldap/Exceptions/ConnectionException.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
56
* @link https://matomo.org
67
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
78
*
89
*/
10+
911
namespace Piwik\Plugins\LoginLdap\Ldap\Exceptions;
1012

1113
use RuntimeException;
@@ -15,4 +17,4 @@
1517
*/
1618
class ConnectionException extends RuntimeException
1719
{
18-
}
20+
}

0 commit comments

Comments
 (0)