Skip to content

Commit ef9f917

Browse files
authored
Merge pull request #149 from aldinokemal/feat/compatible-php-8
feat: add compatible with php 8
2 parents 9469117 + 7504a16 commit ef9f917

File tree

5 files changed

+31
-36
lines changed

5 files changed

+31
-36
lines changed

.github/workflows/php.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
include:
16-
- php: 7.3
17-
- php: 7.4
18-
coverage: '--coverage --coverage-xml'
1916
- php: 8.0
17+
- php: 8.1
18+
- php: 8.2
19+
coverage: '--coverage --coverage-xml'
2020
name: PHP ${{ matrix.php }}
2121

2222
steps:
2323
- uses: actions/checkout@v2
24-
24+
with:
25+
fetch-depth: 10
26+
2527
- name: Setup PHP
2628
uses: shivammathur/setup-php@v2
2729
with:
@@ -39,7 +41,7 @@ jobs:
3941

4042
- name: Upload coverage to Scrutinizer
4143
if: ${{ matrix.coverage }}
42-
run: >
43-
wget https://scrutinizer-ci.com/ocular.phar -O "/tmp/ocular.phar" &&
44-
php "/tmp/ocular.phar" code-coverage:upload --format=php-clover tests/_output/coverage.xml
44+
uses: sudo-bot/action-scrutinizer@latest
45+
with:
46+
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"
4547

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ tests/_output/*
99
!.elasticbeanstalk/*.cfg.yml
1010
!.elasticbeanstalk/*.global.yml
1111
/tests/_support/_generated/
12+
.idea

.scrutinizer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build:
88
nodes:
99
analysis:
1010
environment:
11-
php: 7.4
11+
php: 8.2
1212
postgresql: false
1313
redis: false
1414
mongodb: false

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"source": "https://github.com/jasny/sso"
1717
},
1818
"require": {
19-
"php": ">=7.3.0",
19+
"php": "^8.0",
2020
"ext-json": "*",
2121
"jasny/immutable": "^2.1",
2222
"psr/simple-cache": "^1.0",

src/Broker/Cookies.php

+19-27
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,17 @@
1313
class Cookies implements \ArrayAccess
1414
{
1515
/** @var int */
16-
protected $ttl;
16+
protected int $ttl;
1717

1818
/** @var string */
19-
protected $path;
19+
protected string $path;
2020

2121
/** @var string */
22-
protected $domain;
22+
protected string $domain;
2323

2424
/** @var bool */
25-
protected $secure;
25+
protected bool $secure;
2626

27-
/**
28-
* Cookies constructor.
29-
*
30-
* @param int $ttl Cookie TTL in seconds
31-
* @param string $path
32-
* @param string $domain
33-
* @param bool $secure
34-
*/
3527
public function __construct(int $ttl = 3600, string $path = '', string $domain = '', bool $secure = false)
3628
{
3729
$this->ttl = $ttl;
@@ -43,39 +35,39 @@ public function __construct(int $ttl = 3600, string $path = '', string $domain =
4335
/**
4436
* @inheritDoc
4537
*/
46-
public function offsetSet($name, $value)
38+
public function offsetExists(mixed $offset): bool
4739
{
48-
$success = setcookie($name, $value, time() + $this->ttl, $this->path, $this->domain, $this->secure, true);
49-
50-
if (!$success) {
51-
throw new \RuntimeException("Failed to set cookie '$name'");
52-
}
53-
54-
$_COOKIE[$name] = $value;
40+
return isset($_COOKIE[$offset]);
5541
}
5642

5743
/**
5844
* @inheritDoc
5945
*/
60-
public function offsetUnset($name): void
46+
public function offsetGet(mixed $offset): mixed
6147
{
62-
setcookie($name, '', 1, $this->path, $this->domain, $this->secure, true);
63-
unset($_COOKIE[$name]);
48+
return $_COOKIE[$offset] ?? null;
6449
}
6550

6651
/**
6752
* @inheritDoc
6853
*/
69-
public function offsetGet($name)
54+
public function offsetSet(mixed $offset, mixed $value): void
7055
{
71-
return $_COOKIE[$name] ?? null;
56+
$success = setcookie($offset, $value, time() + $this->ttl, $this->path, $this->domain, $this->secure, true);
57+
58+
if (!$success) {
59+
throw new \RuntimeException("Failed to set cookie '$offset'");
60+
}
61+
62+
$_COOKIE[$offset] = $value;
7263
}
7364

7465
/**
7566
* @inheritDoc
7667
*/
77-
public function offsetExists($name)
68+
public function offsetUnset(mixed $offset): void
7869
{
79-
return isset($_COOKIE[$name]);
70+
setcookie($offset, '', 1, $this->path, $this->domain, $this->secure, true);
71+
unset($_COOKIE[$offset]);
8072
}
8173
}

0 commit comments

Comments
 (0)