Skip to content

Commit

Permalink
force global namespace on php built-in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
johanrosenson committed Feb 10, 2021
1 parent 4a74e78 commit eb55fb4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Handlers/LaravelCookieJarHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
);
Expand Down
4 changes: 2 additions & 2 deletions src/Handlers/LaravelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions src/Handlers/Psr7Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -136,22 +136,22 @@ private function getSetCookieHeaderValue(string $name, ?string $value, ?DateTime
? true
: false;

$nameValueAttribute = sprintf(
$nameValueAttribute = \sprintf(
'%1$s=%2$s',
$name,
! $shouldRemove
? urlencode($value)
: '',
);

$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()
Expand All @@ -160,7 +160,7 @@ private function getSetCookieHeaderValue(string $name, ?string $value, ?DateTime

$pathAttribute = 'path=/';

return implode('; ', [
return \implode('; ', [
$nameValueAttribute,
$expiresAttribute,
$maxAgeAttribute,
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/SymfonyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 12 additions & 1 deletion src/InteractsWithDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/UtmParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit eb55fb4

Please sign in to comment.