From eb55fb449cf08751ba0302b883b7b1736ea65d75 Mon Sep 17 00:00:00 2001 From: Johan Date: Wed, 10 Feb 2021 11:35:05 +0700 Subject: [PATCH] force global namespace on php built-in functions --- src/Handlers/LaravelCookieJarHandler.php | 4 ++-- src/Handlers/LaravelHandler.php | 4 ++-- src/Handlers/Psr7Handler.php | 14 +++++++------- src/Handlers/SymfonyHandler.php | 2 +- src/InteractsWithDateTime.php | 13 ++++++++++++- src/UtmParameters.php | 2 +- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/Handlers/LaravelCookieJarHandler.php b/src/Handlers/LaravelCookieJarHandler.php index 05f5c77..76e5f1a 100644 --- a/src/Handlers/LaravelCookieJarHandler.php +++ b/src/Handlers/LaravelCookieJarHandler.php @@ -29,7 +29,7 @@ public function remember(UtmParameters $utmParameters, $cookieJar, DateTimeInter { Assert::isInstanceOf($cookieJar, QueueingFactory::class); - $minutes = (int) floor($this->secondsUntil($expires) / 60); + $minutes = $this->minutesUntil($expires); foreach ($utmParameters->toArray() as $parameter => $value) { $cookieJar->queue($value !== null @@ -52,7 +52,7 @@ public function forget(UtmParameters $utmParameters, $cookieJar) { Assert::isInstanceOf($cookieJar, QueueingFactory::class); - foreach (array_keys($utmParameters->toArray()) as $parameter) { + foreach (\array_keys($utmParameters->toArray()) as $parameter) { $cookieJar->queue( $cookieJar->forget($parameter), ); diff --git a/src/Handlers/LaravelHandler.php b/src/Handlers/LaravelHandler.php index cd2ab5c..4925e6a 100644 --- a/src/Handlers/LaravelHandler.php +++ b/src/Handlers/LaravelHandler.php @@ -80,7 +80,7 @@ public function remember(UtmParameters $utmParameters, $response, DateTimeInterf { Assert::isInstanceOf($response, Response::class); - $minutes = (int) floor($this->secondsUntil($expires) / 60); + $minutes = $this->minutesUntil($expires); foreach ($utmParameters->toArray() as $parameter => $value) { if ($value !== null) { @@ -104,7 +104,7 @@ public function forget(UtmParameters $utmParameters, $response) { Assert::isInstanceOf($response, Response::class); - foreach (array_keys($utmParameters->toArray()) as $parameter) { + foreach (\array_keys($utmParameters->toArray()) as $parameter) { $response->withoutCookie($parameter); } diff --git a/src/Handlers/Psr7Handler.php b/src/Handlers/Psr7Handler.php index 9be6c4e..bb90105 100644 --- a/src/Handlers/Psr7Handler.php +++ b/src/Handlers/Psr7Handler.php @@ -104,7 +104,7 @@ public function forget(UtmParameters $utmParameters, $response) { Assert::isInstanceOf($response, MessageInterface::class); - foreach (array_keys($utmParameters->toArray()) as $parameter) { + foreach (\array_keys($utmParameters->toArray()) as $parameter) { $response = $response->withAddedHeader('Set-Cookie', $this->getRemoveCookieHeaderValue($parameter)); } @@ -136,7 +136,7 @@ private function getSetCookieHeaderValue(string $name, ?string $value, ?DateTime ? true : false; - $nameValueAttribute = sprintf( + $nameValueAttribute = \sprintf( '%1$s=%2$s', $name, ! $shouldRemove @@ -144,14 +144,14 @@ private function getSetCookieHeaderValue(string $name, ?string $value, ?DateTime : '', ); - $expiresAttribute = sprintf( + $expiresAttribute = \sprintf( 'expires=%1$s', ! $shouldRemove - ? gmdate('D, d M Y H:i:s T', $expires->getTimestamp()) - : gmdate('D, d M Y H:i:s T', (new DateTimeImmutable)->getTimestamp() - 31536002), + ? \gmdate('D, d M Y H:i:s T', $expires->getTimestamp()) + : \gmdate('D, d M Y H:i:s T', (new DateTimeImmutable)->getTimestamp() - 31536002), ); - $maxAgeAttribute = sprintf( + $maxAgeAttribute = \sprintf( 'max-age=%1$s', ! $shouldRemove ? $expires->getTimestamp() - (new DateTimeImmutable)->getTimestamp() @@ -160,7 +160,7 @@ private function getSetCookieHeaderValue(string $name, ?string $value, ?DateTime $pathAttribute = 'path=/'; - return implode('; ', [ + return \implode('; ', [ $nameValueAttribute, $expiresAttribute, $maxAgeAttribute, diff --git a/src/Handlers/SymfonyHandler.php b/src/Handlers/SymfonyHandler.php index 648ec70..313e4eb 100644 --- a/src/Handlers/SymfonyHandler.php +++ b/src/Handlers/SymfonyHandler.php @@ -108,7 +108,7 @@ public function forget(UtmParameters $utmParameters, $response) { Assert::isInstanceOf($response, Response::class); - foreach (array_keys($utmParameters->toArray()) as $parameter) { + foreach (\array_keys($utmParameters->toArray()) as $parameter) { $response->headers->clearCookie($parameter); } diff --git a/src/InteractsWithDateTime.php b/src/InteractsWithDateTime.php index a29080a..245816b 100644 --- a/src/InteractsWithDateTime.php +++ b/src/InteractsWithDateTime.php @@ -7,10 +7,21 @@ use DateTimeImmutable; use DateTimeInterface; +/** + * @internal + */ trait InteractsWithDateTime { /** - * Calculate the difference between now and a future DateTime in seconds + * Calculate the difference between now and a future DateTime in minutes. + */ + private function minutesUntil(DateTimeInterface $dateTime) : int + { + return (int) \floor($this->secondsUntil($expires) / 60); + } + + /** + * Calculate the difference between now and a future DateTime in seconds. */ private function secondsUntil(DateTimeInterface $dateTime) : int { diff --git a/src/UtmParameters.php b/src/UtmParameters.php index 30499ba..07f1a9a 100644 --- a/src/UtmParameters.php +++ b/src/UtmParameters.php @@ -183,7 +183,7 @@ public static function retrieve($request) : ?UtmParametersInterface */ public function remember($response, $expires) { - if (is_integer($expires)) { + if (\is_integer($expires)) { Assert::greaterThan($expires, 0); } elseif (! ($expires instanceof DateTimeInterface)) { throw new InvalidArgumentException('$expires argument must be an integer or an instanceof of DateTimeInterface');