diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5544366..75c5844 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,15 +13,17 @@ jobs: fail-fast: false matrix: include: - - php: 7.3 - - php: 7.4 - coverage: '--coverage --coverage-xml' - php: 8.0 + - php: 8.1 + - php: 8.2 + coverage: '--coverage --coverage-xml' name: PHP ${{ matrix.php }} steps: - uses: actions/checkout@v2 - + with: + fetch-depth: 10 + - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -39,7 +41,7 @@ jobs: - name: Upload coverage to Scrutinizer if: ${{ matrix.coverage }} - run: > - wget https://scrutinizer-ci.com/ocular.phar -O "/tmp/ocular.phar" && - php "/tmp/ocular.phar" code-coverage:upload --format=php-clover tests/_output/coverage.xml + uses: sudo-bot/action-scrutinizer@latest + with: + cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}" diff --git a/.gitignore b/.gitignore index 622097a..9a51957 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ tests/_output/* !.elasticbeanstalk/*.cfg.yml !.elasticbeanstalk/*.global.yml /tests/_support/_generated/ +.idea diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 985ff19..f891c68 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -8,7 +8,7 @@ build: nodes: analysis: environment: - php: 7.4 + php: 8.2 postgresql: false redis: false mongodb: false diff --git a/composer.json b/composer.json index c35c5dc..e16c02a 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "source": "https://github.com/jasny/sso" }, "require": { - "php": ">=7.3.0", + "php": "^8.0", "ext-json": "*", "jasny/immutable": "^2.1", "psr/simple-cache": "^1.0", diff --git a/src/Broker/Cookies.php b/src/Broker/Cookies.php index ff290bc..62c4721 100644 --- a/src/Broker/Cookies.php +++ b/src/Broker/Cookies.php @@ -13,25 +13,17 @@ class Cookies implements \ArrayAccess { /** @var int */ - protected $ttl; + protected int $ttl; /** @var string */ - protected $path; + protected string $path; /** @var string */ - protected $domain; + protected string $domain; /** @var bool */ - protected $secure; + protected bool $secure; - /** - * Cookies constructor. - * - * @param int $ttl Cookie TTL in seconds - * @param string $path - * @param string $domain - * @param bool $secure - */ public function __construct(int $ttl = 3600, string $path = '', string $domain = '', bool $secure = false) { $this->ttl = $ttl; @@ -43,39 +35,39 @@ public function __construct(int $ttl = 3600, string $path = '', string $domain = /** * @inheritDoc */ - public function offsetSet($name, $value) + public function offsetExists(mixed $offset): bool { - $success = setcookie($name, $value, time() + $this->ttl, $this->path, $this->domain, $this->secure, true); - - if (!$success) { - throw new \RuntimeException("Failed to set cookie '$name'"); - } - - $_COOKIE[$name] = $value; + return isset($_COOKIE[$offset]); } /** * @inheritDoc */ - public function offsetUnset($name): void + public function offsetGet(mixed $offset): mixed { - setcookie($name, '', 1, $this->path, $this->domain, $this->secure, true); - unset($_COOKIE[$name]); + return $_COOKIE[$offset] ?? null; } /** * @inheritDoc */ - public function offsetGet($name) + public function offsetSet(mixed $offset, mixed $value): void { - return $_COOKIE[$name] ?? null; + $success = setcookie($offset, $value, time() + $this->ttl, $this->path, $this->domain, $this->secure, true); + + if (!$success) { + throw new \RuntimeException("Failed to set cookie '$offset'"); + } + + $_COOKIE[$offset] = $value; } /** * @inheritDoc */ - public function offsetExists($name) + public function offsetUnset(mixed $offset): void { - return isset($_COOKIE[$name]); + setcookie($offset, '', 1, $this->path, $this->domain, $this->secure, true); + unset($_COOKIE[$offset]); } }