Skip to content
Snippets Groups Projects
Commit bb01677b authored by Florent Torregrosa's avatar Florent Torregrosa Committed by Florent Torregrosa
Browse files

Issue #3311202 by Grimreaper: Fix PHPMND, PHPCS Fixer

parent 19b71053
No related branches found
No related tags found
No related merge requests found
...@@ -37,14 +37,14 @@ function i18n_sso_schema() : array { ...@@ -37,14 +37,14 @@ function i18n_sso_schema() : array {
'token' => [ 'token' => [
'description' => 'The token used to connect user. Deleted after usage.', 'description' => 'The token used to connect user. Deleted after usage.',
'type' => 'varchar', 'type' => 'varchar',
'length' => 255, 'length' => (int) 255,
'not null' => TRUE, 'not null' => TRUE,
'default' => '', 'default' => '',
], ],
'user_ip' => [ 'user_ip' => [
'description' => 'The IP the token has been generated for.', 'description' => 'The IP the token has been generated for.',
'type' => 'varchar', 'type' => 'varchar',
'length' => 63, 'length' => (int) 63,
'not null' => TRUE, 'not null' => TRUE,
'default' => '', 'default' => '',
], ],
......
...@@ -13,8 +13,6 @@ use Symfony\Component\HttpFoundation\RequestStack; ...@@ -13,8 +13,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
/** /**
* Allow to manage token. * Allow to manage token.
*
* @package Drupal\i18n_sso\Controller
*/ */
class TokenController extends ControllerBase { class TokenController extends ControllerBase {
...@@ -48,7 +46,7 @@ class TokenController extends ControllerBase { ...@@ -48,7 +46,7 @@ class TokenController extends ControllerBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create(ContainerInterface $container) : self { public static function create(ContainerInterface $container): self {
return new self( return new self(
$container->get('i18n_sso.token'), $container->get('i18n_sso.token'),
$container->get('request_stack') $container->get('request_stack')
...@@ -118,7 +116,7 @@ class TokenController extends ControllerBase { ...@@ -118,7 +116,7 @@ class TokenController extends ControllerBase {
if (!empty($uid)) { if (!empty($uid)) {
/** @var \Drupal\user\UserInterface $user */ /** @var \Drupal\user\UserInterface $user */
$user = $this->entityTypeManager()->getStorage('user')->load($uid); $user = $this->entityTypeManager()->getStorage('user')->load($uid);
user_login_finalize($user); \user_login_finalize($user);
$data = []; $data = [];
$data['success'] = TRUE; $data['success'] = TRUE;
$data['message'] = $this->t('You have been successfully logged in. Please wait for the page to refresh.'); $data['message'] = $this->t('You have been successfully logged in. Please wait for the page to refresh.');
......
...@@ -37,7 +37,7 @@ class SsoAllowOrigin implements EventSubscriberInterface { ...@@ -37,7 +37,7 @@ class SsoAllowOrigin implements EventSubscriberInterface {
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* The event. * The event.
*/ */
public function onRespond(ResponseEvent $event) : void { public function onRespond(ResponseEvent $event): void {
/** @var array $allowedDomains */ /** @var array $allowedDomains */
$allowedDomains = $this->configFactory $allowedDomains = $this->configFactory
->getEditable('language.negotiation') ->getEditable('language.negotiation')
...@@ -52,9 +52,9 @@ class SsoAllowOrigin implements EventSubscriberInterface { ...@@ -52,9 +52,9 @@ class SsoAllowOrigin implements EventSubscriberInterface {
return; return;
} }
$domain = str_replace('http://', '', $origin); $domain = \str_replace('http://', '', $origin);
$domain = str_replace('https://', '', $domain); $domain = \str_replace('https://', '', $domain);
if (in_array($domain, $allowedDomains)) { if (\in_array($domain, $allowedDomains, TRUE)) {
$response->headers->set('Access-Control-Allow-Origin', $origin); $response->headers->set('Access-Control-Allow-Origin', $origin);
$response->headers->set('Access-Control-Allow-Headers', 'Accept,Origin,Content-Type,Cookie'); $response->headers->set('Access-Control-Allow-Headers', 'Accept,Origin,Content-Type,Cookie');
$response->headers->set('Access-Control-Allow-Credentials', 'true'); $response->headers->set('Access-Control-Allow-Credentials', 'true');
......
...@@ -15,12 +15,12 @@ class Token { ...@@ -15,12 +15,12 @@ class Token {
/** /**
* The table used to store the tokens. * The table used to store the tokens.
*/ */
const TOKEN_TABLE = 'i18n_sso_tokens'; public const TOKEN_TABLE = 'i18n_sso_tokens';
/** /**
* The token lifetime. * The token lifetime.
*/ */
const TOKEN_LIFETIME = 60 * 10; public const TOKEN_LIFETIME = 60 * 10;
/** /**
* The database connection. * The database connection.
...@@ -64,13 +64,13 @@ class Token { ...@@ -64,13 +64,13 @@ class Token {
$token = $this->connection->select(self::TOKEN_TABLE) $token = $this->connection->select(self::TOKEN_TABLE)
->fields(self::TOKEN_TABLE, ['token']) ->fields(self::TOKEN_TABLE, ['token'])
->condition('user_ip', $user_ip, 'LIKE') ->condition('user_ip', $user_ip, 'LIKE')
->condition('uid', strval($uid), '=') ->condition('uid', (string) $uid, '=')
->condition('expire', strval($this->datetime->getRequestTime()), '>'); ->condition('expire', (string) ($this->datetime->getRequestTime()), '>');
/** @var \Drupal\Core\Database\StatementInterface $result */ /** @var \Drupal\Core\Database\StatementInterface $result */
$result = $token->range(0, 1)->execute(); $result = $token->range(0, 1)
/** @var object $fetchedObject */ ->execute();
$fetchedObject = $result->fetchObject(); // @phpstan-ignore-next-line
return $fetchedObject; return $result->fetchObject();
} }
/** /**
...@@ -91,7 +91,7 @@ class Token { ...@@ -91,7 +91,7 @@ class Token {
$token['uid'] = $uid; $token['uid'] = $uid;
$token['created'] = $this->datetime->getRequestTime(); $token['created'] = $this->datetime->getRequestTime();
$sha1source = $token['created'] . $uid . $user_ip; $sha1source = $token['created'] . $uid . $user_ip;
$token['token'] = sha1($sha1source); $token['token'] = \sha1($sha1source);
$token['user_ip'] = $user_ip; $token['user_ip'] = $user_ip;
$token['expire'] = $this->datetime->getRequestTime() + self::TOKEN_LIFETIME; $token['expire'] = $this->datetime->getRequestTime() + self::TOKEN_LIFETIME;
$this->connection $this->connection
...@@ -117,14 +117,13 @@ class Token { ...@@ -117,14 +117,13 @@ class Token {
->fields(self::TOKEN_TABLE, ['uid']) ->fields(self::TOKEN_TABLE, ['uid'])
->condition('user_ip', $user_ip, 'LIKE') ->condition('user_ip', $user_ip, 'LIKE')
->condition('token', $token, 'LIKE') ->condition('token', $token, 'LIKE')
->condition('expire', strval($this->datetime->getRequestTime()), '>'); ->condition('expire', (string) ($this->datetime->getRequestTime()), '>');
$result = $query->range(0, 1)->execute(); $result = $query->range(0, 1)->execute();
if ($result) { if ($result) {
return $result->fetchField(); return $result->fetchField();
} }
else {
return ''; return '';
}
} }
/** /**
...@@ -156,7 +155,7 @@ class Token { ...@@ -156,7 +155,7 @@ class Token {
*/ */
public function deleteUserTokens($uid) { public function deleteUserTokens($uid) {
return $this->connection->delete(self::TOKEN_TABLE) return $this->connection->delete(self::TOKEN_TABLE)
->condition('uid', strval($uid), '=') ->condition('uid', (string) $uid, '=')
->execute(); ->execute();
} }
...@@ -168,7 +167,7 @@ class Token { ...@@ -168,7 +167,7 @@ class Token {
*/ */
public function deleteExpiredTokens() { public function deleteExpiredTokens() {
return $this->connection->delete(self::TOKEN_TABLE) return $this->connection->delete(self::TOKEN_TABLE)
->condition('expire', strval($this->datetime->getRequestTime()), '<') ->condition('expire', (string) ($this->datetime->getRequestTime()), '<')
->execute(); ->execute();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment