From d14e7a27e800f8e10f7616229c24ef235b5d7158 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Mon, 21 Feb 2022 12:55:28 +0000 Subject: [PATCH 1/9] feature: type safe getters closes #81 --- composer.json | 7 +- composer.lock | 216 +++++++++++------- src/FileHandler.php | 12 +- src/Handler.php | 16 +- src/Session.php | 40 ++-- src/SessionStore.php | 15 +- .../Helper/FunctionOverride/session_start.php | 4 +- test/phpunit/SessionStoreTest.php | 55 ++++- test/phpunit/SessionTest.php | 65 +++++- 9 files changed, 305 insertions(+), 125 deletions(-) diff --git a/composer.json b/composer.json index 889a99e..d157df0 100644 --- a/composer.json +++ b/composer.json @@ -4,11 +4,12 @@ "license": "MIT", "require": { - "php": ">=7.2" + "php": ">=8.0", + "phpgt/typesafegetter": "^v1.2" }, "require-dev": { - "phpunit/phpunit": "9.*", - "phpstan/phpstan": "1.0.2" + "phpunit/phpunit": "^9.5", + "phpstan/phpstan": "^v1.4" }, "autoload": { diff --git a/composer.lock b/composer.lock index c8bac1b..1b8982d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,58 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2e4b232fb6d83b62e1c30a262a97fa21", - "packages": [], + "content-hash": "f32a6d1ec518670b8c827c0fcd60c47f", + "packages": [ + { + "name": "phpgt/typesafegetter", + "version": "v1.2.2", + "source": { + "type": "git", + "url": "https://github.com/PhpGt/TypeSafeGetter.git", + "reference": "ffeb5d847b3a4b36081a5cd180587fc4d83c6e31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PhpGt/TypeSafeGetter/zipball/ffeb5d847b3a4b36081a5cd180587fc4d83c6e31", + "reference": "ffeb5d847b3a4b36081a5cd180587fc4d83c6e31", + "shasum": "" + }, + "require": { + "php": ">=8.0" + }, + "require-dev": { + "phpstan/phpstan": ">=0.12.42" + }, + "type": "library", + "autoload": { + "psr-4": { + "Gt\\TypeSafeGetter\\": "./src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Greg Bowler", + "email": "greg.bowler@g105b.com" + } + ], + "description": "An interface for objects that expose type-safe getter methods.", + "support": { + "issues": "https://github.com/PhpGt/TypeSafeGetter/issues", + "source": "https://github.com/PhpGt/TypeSafeGetter/tree/v1.2.2" + }, + "funding": [ + { + "url": "https://github.com/sponsors/PhpGt", + "type": "github" + } + ], + "time": "2021-01-30T12:18:23+00:00" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", @@ -93,9 +143,6 @@ "require": { "php": "^7.1 || ^8.0" }, - "replace": { - "myclabs/deep-copy": "self.version" - }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", @@ -103,12 +150,12 @@ }, "type": "library", "autoload": { - "psr-4": { - "DeepCopy\\": "src/DeepCopy/" - }, "files": [ "src/DeepCopy/deep_copy.php" - ] + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -136,16 +183,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.13.1", + "version": "v4.13.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "63a79e8daa781cac14e5195e63ed8ae231dd10fd" + "reference": "210577fe3cf7badcc5814d99455df46564f3c077" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/63a79e8daa781cac14e5195e63ed8ae231dd10fd", - "reference": "63a79e8daa781cac14e5195e63ed8ae231dd10fd", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077", + "reference": "210577fe3cf7badcc5814d99455df46564f3c077", "shasum": "" }, "require": { @@ -186,9 +233,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2" }, - "time": "2021-11-03T20:52:16+00:00" + "time": "2021-11-30T19:35:32+00:00" }, { "name": "phar-io/manifest", @@ -252,16 +299,16 @@ }, { "name": "phar-io/version", - "version": "3.1.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "bae7c545bef187884426f042434e561ab1ddb182" + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182", - "reference": "bae7c545bef187884426f042434e561ab1ddb182", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", "shasum": "" }, "require": { @@ -297,9 +344,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/3.1.0" + "source": "https://github.com/phar-io/version/tree/3.2.1" }, - "time": "2021-02-23T14:00:09+00:00" + "time": "2022-02-21T01:04:05+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -413,16 +460,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.5.1", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae" + "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/a12f7e301eb7258bb68acd89d4aefa05c2906cae", - "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706", + "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706", "shasum": "" }, "require": { @@ -457,22 +504,22 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.1" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0" }, - "time": "2021-10-02T14:08:47+00:00" + "time": "2022-01-04T19:58:01+00:00" }, { "name": "phpspec/prophecy", - "version": "1.14.0", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e" + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e", - "reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", "shasum": "" }, "require": { @@ -524,22 +571,22 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.14.0" + "source": "https://github.com/phpspec/prophecy/tree/v1.15.0" }, - "time": "2021-09-10T09:02:12+00:00" + "time": "2021-12-08T12:19:24+00:00" }, { "name": "phpstan/phpstan", - "version": "1.0.2", + "version": "1.4.6", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e9e2a501102ba0b126b2f63a7f0a3b151056fe91" + "reference": "8a7761f1c520e0dad6e04d862fdc697445457cfe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e9e2a501102ba0b126b2f63a7f0a3b151056fe91", - "reference": "e9e2a501102ba0b126b2f63a7f0a3b151056fe91", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8a7761f1c520e0dad6e04d862fdc697445457cfe", + "reference": "8a7761f1c520e0dad6e04d862fdc697445457cfe", "shasum": "" }, "require": { @@ -555,7 +602,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -570,7 +617,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.0.2" + "source": "https://github.com/phpstan/phpstan/tree/1.4.6" }, "funding": [ { @@ -590,20 +637,20 @@ "type": "tidelift" } ], - "time": "2021-11-03T16:09:51+00:00" + "time": "2022-02-06T12:56:13+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.8", + "version": "9.2.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "cf04e88a2e3c56fc1a65488afd493325b4c1bc3e" + "reference": "665a1ac0a763c51afc30d6d130dac0813092b17f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/cf04e88a2e3c56fc1a65488afd493325b4c1bc3e", - "reference": "cf04e88a2e3c56fc1a65488afd493325b4c1bc3e", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/665a1ac0a763c51afc30d6d130dac0813092b17f", + "reference": "665a1ac0a763c51afc30d6d130dac0813092b17f", "shasum": "" }, "require": { @@ -659,7 +706,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.8" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.11" }, "funding": [ { @@ -667,20 +714,20 @@ "type": "github" } ], - "time": "2021-10-30T08:01:38+00:00" + "time": "2022-02-18T12:46:09+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "3.0.5", + "version": "3.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8" + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8", - "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", "shasum": "" }, "require": { @@ -719,7 +766,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" }, "funding": [ { @@ -727,7 +774,7 @@ "type": "github" } ], - "time": "2020-09-28T05:57:25+00:00" + "time": "2021-12-02T12:48:52+00:00" }, { "name": "phpunit/php-invoker", @@ -912,16 +959,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.10", + "version": "9.5.14", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a" + "reference": "1883687169c017d6ae37c58883ca3994cfc34189" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c814a05837f2edb0d1471d6e3f4ab3501ca3899a", - "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1883687169c017d6ae37c58883ca3994cfc34189", + "reference": "1883687169c017d6ae37c58883ca3994cfc34189", "shasum": "" }, "require": { @@ -972,11 +1019,11 @@ } }, "autoload": { - "classmap": [ - "src/" - ], "files": [ "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -999,11 +1046,11 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.10" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.14" }, "funding": [ { - "url": "https://phpunit.de/donate.html", + "url": "https://phpunit.de/sponsors.html", "type": "custom" }, { @@ -1011,7 +1058,7 @@ "type": "github" } ], - "time": "2021-09-25T07:38:51+00:00" + "time": "2022-02-18T12:54:07+00:00" }, { "name": "sebastian/cli-parser", @@ -1442,16 +1489,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.3", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65" + "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d89cc98761b8cb5a1a235a6b703ae50d34080e65", - "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/65e8b7db476c5dd267e65eea9cab77584d3cfff9", + "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9", "shasum": "" }, "require": { @@ -1500,14 +1547,14 @@ } ], "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", + "homepage": "https://www.github.com/sebastianbergmann/exporter", "keywords": [ "export", "exporter" ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.4" }, "funding": [ { @@ -1515,20 +1562,20 @@ "type": "github" } ], - "time": "2020-09-28T05:24:23+00:00" + "time": "2021-11-11T14:18:36+00:00" }, { "name": "sebastian/global-state", - "version": "5.0.3", + "version": "5.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49" + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23bd5951f7ff26f12d4e3242864df3e08dec4e49", - "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", "shasum": "" }, "require": { @@ -1571,7 +1618,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.3" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" }, "funding": [ { @@ -1579,7 +1626,7 @@ "type": "github" } ], - "time": "2021-06-11T13:31:12+00:00" + "time": "2022-02-14T08:28:10+00:00" }, { "name": "sebastian/lines-of-code", @@ -1979,21 +2026,24 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" + "reference": "30885182c981ab175d4d034db0f6f469898070ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab", + "reference": "30885182c981ab175d4d034db0f6f469898070ab", "shasum": "" }, "require": { "php": ">=7.1" }, + "provide": { + "ext-ctype": "*" + }, "suggest": { "ext-ctype": "For best performance" }, @@ -2038,7 +2088,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0" }, "funding": [ { @@ -2054,7 +2104,7 @@ "type": "tidelift" } ], - "time": "2021-02-19T12:13:01+00:00" + "time": "2021-10-20T20:35:02+00:00" }, { "name": "theseer/tokenizer", @@ -2171,8 +2221,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.2" + "php": ">=8.0" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.2.0" } diff --git a/src/FileHandler.php b/src/FileHandler.php index 838a404..4c3a087 100644 --- a/src/FileHandler.php +++ b/src/FileHandler.php @@ -13,7 +13,7 @@ class FileHandler extends Handler { * @param string $save_path The path where to store/retrieve the session. * @param string $name The session name. */ - public function open($save_path, $name):bool { + public function open(string $save_path, string $name):bool { $success = true; $save_path = str_replace( @@ -45,7 +45,7 @@ public function close():bool { * @link http://php.net/manual/en/sessionhandlerinterface.read.php * @param string $session_id */ - public function read($session_id):string { + public function read(string $session_id):string { if(isset($this->cache[$session_id])) { return $this->cache[$session_id]; } @@ -65,7 +65,7 @@ public function read($session_id):string { * @param string $session_id * @param string $session_data */ - public function write($session_id, $session_data):bool { + public function write(string $session_id, string $session_data):bool { if($session_data === self::EMPTY_PHP_ARRAY) { return true; } @@ -76,10 +76,10 @@ public function write($session_id, $session_data):bool { /** * @link http://php.net/manual/en/sessionhandlerinterface.destroy.php - * @param string $session_id + * @param string $id */ - public function destroy($session_id):bool { - $filePath = $this->getFilePath($session_id); + public function destroy($id):bool { + $filePath = $this->getFilePath($id); if(file_exists($filePath)) { return unlink($filePath); diff --git a/src/Handler.php b/src/Handler.php index ffbe95a..a3f7a11 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -12,33 +12,33 @@ abstract public function close():bool; /** * @link http://php.net/manual/en/sessionhandlerinterface.destroy.php - * @param string $session_id + * @param string $id */ - abstract public function destroy($session_id); + abstract public function destroy(string $id = ""):bool; /** * @link http://php.net/manual/en/sessionhandlerinterface.gc.php - * @param int $maxlifetime + * @param int $max_lifetime */ - abstract public function gc($maxlifetime):bool; + abstract public function gc(int $max_lifetime):int|false; /** * @link http://php.net/manual/en/sessionhandlerinterface.open.php * @param string $save_path The path where to store/retrieve the session. * @param string $name The session name. */ - abstract public function open($save_path, $name):bool; + abstract public function open(string $save_path, string $name):bool; /** * @link http://php.net/manual/en/sessionhandlerinterface.read.php * @param string $session_id */ - abstract public function read($session_id):string; + abstract public function read(string $session_id):string; /** * @link http://php.net/manual/en/sessionhandlerinterface.write.php * @param string $session_id * @param string $session_data */ - abstract public function write($session_id, $session_data):bool; -} \ No newline at end of file + abstract public function write(string $session_id, string $session_data):bool; +} diff --git a/src/Session.php b/src/Session.php index 1f9b3eb..8b850a6 100644 --- a/src/Session.php +++ b/src/Session.php @@ -1,9 +1,14 @@ $sessionPath, - "name" => $sessionName, - "serialize_handler" => "php_serialize", - "cookie_lifetime" => $config["cookie_lifetime"] ?? self::DEFAULT_SESSION_LIFETIME, - "cookie_path" => $config["cookie_path"] ?? self::DEFAULT_COOKIE_PATH, - "cookie_domain" => $config["cookie_domain"] ?? self::DEFAULT_SESSION_DOMAIN, - "cookie_secure" => $config["cookie_secure"] ?? self::DEFAULT_SESSION_SECURE, - "cookie_httponly" => $config["cookie_httponly"] ?? self::DEFAULT_SESSION_HTTPONLY, - ]); - - if(!$success) { -// TODO: Throw exception after #131 investigated. - var_dump($sessionPath, $sessionName, $this->id);die("Session starting failed"); + do { + $success = session_start([ + "save_path" => $sessionPath, + "name" => $sessionName, + "serialize_handler" => "php_serialize", + "cookie_lifetime" => $config["cookie_lifetime"] ?? self::DEFAULT_SESSION_LIFETIME, + "cookie_path" => $config["cookie_path"] ?? self::DEFAULT_COOKIE_PATH, + "cookie_domain" => $config["cookie_domain"] ?? self::DEFAULT_SESSION_DOMAIN, + "cookie_secure" => $config["cookie_secure"] ?? self::DEFAULT_SESSION_SECURE, + "cookie_httponly" => $config["cookie_httponly"] ?? self::DEFAULT_SESSION_HTTPONLY, + ]); + + if(!$success) { + session_destroy(); + } } + while(!$success); $this->sessionHandler->open($sessionPath, $sessionName); $this->store = $this->readSessionData() ?: null; @@ -84,10 +91,9 @@ public function getStore( ); } - public function get(string $key) { + public function get(string $key):mixed { return $this->store->get($key); } - public function set(string $key, $value):void { $this->store->set($key, $value); } diff --git a/src/SessionStore.php b/src/SessionStore.php index b40ce8b..a21c4d3 100644 --- a/src/SessionStore.php +++ b/src/SessionStore.php @@ -1,7 +1,14 @@ data = []; } - public function setData(string $key, $value):void { + public function setData(string $key, mixed $value):void { $this->data[$key] = $value; } @@ -117,7 +124,7 @@ public function createStore(string $namespace):SessionStore { return $this->getStore($namespace); } - public function get(string $key) { + public function get(string $key):mixed { $store = $this; $lastDotPosition = strrpos($key, "."); @@ -220,4 +227,4 @@ protected function getNamespaceFromKey(string $key):?string { return substr($key, 0, $lastDotPostition); } -} \ No newline at end of file +} diff --git a/test/phpunit/Helper/FunctionOverride/session_start.php b/test/phpunit/Helper/FunctionOverride/session_start.php index 0765a79..1ac8361 100644 --- a/test/phpunit/Helper/FunctionOverride/session_start.php +++ b/test/phpunit/Helper/FunctionOverride/session_start.php @@ -6,9 +6,9 @@ function session_start() { FunctionMocker::$mockCalls["session_start"] []= func_get_args(); - if(FunctionMocker::$callState["session_start__fail"]) { + if(isset(FunctionMocker::$callState["session_start__fail"])) { return false; } return true; -} \ No newline at end of file +} diff --git a/test/phpunit/SessionStoreTest.php b/test/phpunit/SessionStoreTest.php index 6ee3aa5..cb1d74e 100644 --- a/test/phpunit/SessionStoreTest.php +++ b/test/phpunit/SessionStoreTest.php @@ -1,6 +1,7 @@ createMock(Session::class); + $sut = new SessionStore("test", $session); + + $numericValue = rand(1000, 9999); + $sut->set("test.value", $numericValue); + + self::assertSame((string)$numericValue, $sut->getString("test.value")); + } + + public function testGetInt():void { + $session = $this->createMock(Session::class); + $sut = new SessionStore("test", $session); + + $numericStringValue = (string)rand(1000, 9999); + $sut->set("test.value", $numericStringValue); + + self::assertSame((int)$numericStringValue, $sut->getInt("test.value")); + } + + public function testGetFloat():void { + $session = $this->createMock(Session::class); + $sut = new SessionStore("test", $session); + + $numericStringValue = (string)(rand(1000, 9999) - 0.105); + $sut->set("test.value", $numericStringValue); + + self::assertSame((float)$numericStringValue, $sut->getFloat("test.value")); + } + + public function testGetBool():void { + $session = $this->createMock(Session::class); + $sut = new SessionStore("test", $session); + + $numericValue = rand(0, 1); + $sut->set("test.value", $numericValue); + + self::assertSame((bool)$numericValue, $sut->getBool("test.value")); + } + + public function testGetDateTime():void { + $session = $this->createMock(Session::class); + $sut = new SessionStore("test", $session); + + $numericValue = time(); + $sut->set("test.value", $numericValue); + + $dateTime = new DateTime(); + $dateTime->setTimestamp($numericValue); + self::assertEquals($dateTime, $sut->getDateTime("test.value")); + } +} diff --git a/test/phpunit/SessionTest.php b/test/phpunit/SessionTest.php index f9a19ed..eee23f4 100644 --- a/test/phpunit/SessionTest.php +++ b/test/phpunit/SessionTest.php @@ -1,6 +1,7 @@ getMockBuilder(Handler::class) + ->getMock(); + $sut = new Session($handler); + + $numericValue = rand(1000, 9999); + $sut->set("test.value", $numericValue); + + self::assertSame((string)$numericValue, $sut->getString("test.value")); + } + + public function testGetInt():void { + /** @var Handler|MockObject $handler */ + $handler = $this->getMockBuilder(Handler::class) + ->getMock(); + $sut = new Session($handler); + + $numericStringValue = (string)rand(1000, 9999); + $sut->set("test.value", $numericStringValue); + + self::assertSame((int)$numericStringValue, $sut->getInt("test.value")); + } + + public function testGetFloat():void { + /** @var Handler|MockObject $handler */ + $handler = $this->getMockBuilder(Handler::class) + ->getMock(); + $sut = new Session($handler); + + $numericStringValue = (string)(rand(1000, 9999) - 0.105); + $sut->set("test.value", $numericStringValue); + + self::assertSame((float)$numericStringValue, $sut->getFloat("test.value")); + } + + public function testGetBool():void { + /** @var Handler|MockObject $handler */ + $handler = $this->getMockBuilder(Handler::class) + ->getMock(); + $sut = new Session($handler); + + $numericValue = rand(0, 1); + $sut->set("test.value", $numericValue); + + self::assertSame((bool)$numericValue, $sut->getBool("test.value")); + } + + public function testGetDateTime():void { + /** @var Handler|MockObject $handler */ + $handler = $this->getMockBuilder(Handler::class) + ->getMock(); + $sut = new Session($handler); + + $numericValue = time(); + $sut->set("test.value", $numericValue); + + $dateTime = new DateTime(); + $dateTime->setTimestamp($numericValue); + self::assertEquals($dateTime, $sut->getDateTime("test.value")); + } +} From 9ae14755251f742ee6424691870a218ff235f79d Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Tue, 8 Mar 2022 15:35:59 +0000 Subject: [PATCH 2/9] loosen type (can be array access) --- composer.lock | 95 ++++++++++++++++++++++++++----------------------- src/Session.php | 4 +-- 2 files changed, 52 insertions(+), 47 deletions(-) diff --git a/composer.lock b/composer.lock index 1b8982d..77a3edd 100644 --- a/composer.lock +++ b/composer.lock @@ -59,29 +59,30 @@ "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.4.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b" + "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b", - "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", + "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^8.0", + "doctrine/coding-standard": "^9", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.13 || 1.0.0-alpha2", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpbench/phpbench": "^0.16 || ^1", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.22" }, "type": "library", "autoload": { @@ -108,7 +109,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + "source": "https://github.com/doctrine/instantiator/tree/1.4.1" }, "funding": [ { @@ -124,29 +125,33 @@ "type": "tidelift" } ], - "time": "2020-11-10T18:47:58+00:00" + "time": "2022-03-03T08:28:38+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.10.2", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220" + "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220", - "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", + "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" + }, "require-dev": { - "doctrine/collections": "^1.0", - "doctrine/common": "^2.6", - "phpunit/phpunit": "^7.1" + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, "type": "library", "autoload": { @@ -171,7 +176,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0" }, "funding": [ { @@ -179,7 +184,7 @@ "type": "tidelift" } ], - "time": "2020-11-13T09:40:50+00:00" + "time": "2022-03-03T13:19:32+00:00" }, { "name": "nikic/php-parser", @@ -577,16 +582,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.4.6", + "version": "1.4.8", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "8a7761f1c520e0dad6e04d862fdc697445457cfe" + "reference": "2a6d6704b17c4db6190cc3104056c0aad740cb15" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8a7761f1c520e0dad6e04d862fdc697445457cfe", - "reference": "8a7761f1c520e0dad6e04d862fdc697445457cfe", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2a6d6704b17c4db6190cc3104056c0aad740cb15", + "reference": "2a6d6704b17c4db6190cc3104056c0aad740cb15", "shasum": "" }, "require": { @@ -617,7 +622,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.4.6" + "source": "https://github.com/phpstan/phpstan/tree/1.4.8" }, "funding": [ { @@ -637,20 +642,20 @@ "type": "tidelift" } ], - "time": "2022-02-06T12:56:13+00:00" + "time": "2022-03-04T13:03:56+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.11", + "version": "9.2.15", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "665a1ac0a763c51afc30d6d130dac0813092b17f" + "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/665a1ac0a763c51afc30d6d130dac0813092b17f", - "reference": "665a1ac0a763c51afc30d6d130dac0813092b17f", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2e9da11878c4202f97915c1cb4bb1ca318a63f5f", + "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f", "shasum": "" }, "require": { @@ -706,7 +711,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.11" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.15" }, "funding": [ { @@ -714,7 +719,7 @@ "type": "github" } ], - "time": "2022-02-18T12:46:09+00:00" + "time": "2022-03-07T09:28:20+00:00" }, { "name": "phpunit/php-file-iterator", @@ -959,16 +964,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.14", + "version": "9.5.18", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1883687169c017d6ae37c58883ca3994cfc34189" + "reference": "1b5856028273bfd855e60a887278857d872ec67a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1883687169c017d6ae37c58883ca3994cfc34189", - "reference": "1883687169c017d6ae37c58883ca3994cfc34189", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b5856028273bfd855e60a887278857d872ec67a", + "reference": "1b5856028273bfd855e60a887278857d872ec67a", "shasum": "" }, "require": { @@ -984,7 +989,7 @@ "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2.7", + "phpunit/php-code-coverage": "^9.2.13", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1046,7 +1051,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.14" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.18" }, "funding": [ { @@ -1058,7 +1063,7 @@ "type": "github" } ], - "time": "2022-02-18T12:54:07+00:00" + "time": "2022-03-08T06:52:28+00:00" }, { "name": "sebastian/cli-parser", @@ -2026,7 +2031,7 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.24.0", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -2058,12 +2063,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -2088,7 +2093,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.25.0" }, "funding": [ { diff --git a/src/Session.php b/src/Session.php index 3abd1ea..7c68915 100644 --- a/src/Session.php +++ b/src/Session.php @@ -20,10 +20,10 @@ class Session implements SessionContainer, TypeSafeGetter { protected SessionHandlerInterface $sessionHandler; protected ?SessionStore $store; - /** @param array $config */ + /** @param \ArrayAccess|array $config */ public function __construct( SessionHandlerInterface $sessionHandler, - array $config = [], + array|\ArrayAccess $config = [], string $id = null ) { $this->sessionHandler = $sessionHandler; From 02bec9f80dbac2893578f73f39bc1cc4d18b8888 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Mon, 5 May 2025 14:35:54 +0100 Subject: [PATCH 3/9] Iterable session store (#254) * feature: type safe getters closes #81 * loosen type (can be array access) * feature: implement countable closes #12 * ci: improve ci, fix security vulnerability * build: bump deps * tidy: fix deprecations * tidy: refactor classes from static analysis * feature: Iterable SessionStore closes #11 --------- Co-authored-by: Greg Bowler --- src/SessionStore.php | 26 +++++++++++++------------- test/phpunit/SessionStoreTest.php | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/SessionStore.php b/src/SessionStore.php index e1a32f3..07b9788 100644 --- a/src/SessionStore.php +++ b/src/SessionStore.php @@ -1,20 +1,24 @@ + * @SuppressWarnings(PHPMD.TooManyPublicMethods) + */ +class SessionStore + extends ArrayIterator + implements SessionContainer, TypeSafeGetter, Countable { use NullableTypeSafeGetter; protected string $name; protected Session $session; /** @var array */ protected array $stores; - /** @var array */ - protected array $data; protected ?SessionStore $parentStore; public function __construct( @@ -26,23 +30,19 @@ public function __construct( $this->session = $session; $this->parentStore = $parentStore; $this->stores = []; - $this->data = []; - } - - public function count():int { - return count($this->data); + parent::__construct(); } public function setData(string $key, mixed $value):void { - $this->data[$key] = $value; + $this->offsetSet($key, $value); } public function getData(string $key):mixed { - return $this->data[$key] ?? null; + return $this->offsetGet($key) ?? null; } public function containsData(string $key):bool { - return isset($this->data[$key]); + return $this->offsetExists($key); } public function containsStore(string $key):bool { @@ -50,7 +50,7 @@ public function containsStore(string $key):bool { } public function removeData(string $key):void { - unset($this->data[$key]); + $this->offsetUnset($key); } public function removeStore(string $key):void { diff --git a/test/phpunit/SessionStoreTest.php b/test/phpunit/SessionStoreTest.php index 27417b0..2124cb3 100644 --- a/test/phpunit/SessionStoreTest.php +++ b/test/phpunit/SessionStoreTest.php @@ -151,4 +151,25 @@ public function testCount():void { self::assertCount(3, $sut); } + + + public function testSessionStoreIsIterable():void { + $session = $this->createMock(Session::class); + $sut = new SessionStore("test", $session); + + $rawData = [ + "key1" => "value1", + "key2" => "value2", + "key3" => "value3", + ]; + + foreach($rawData as $key => $value) { + $sut->set($key, $value); + } + + foreach($sut as $key => $value) { + self::assertArrayHasKey($key, $rawData); + self::assertSame($rawData[$key], $value); + } + } } From 5562c3eece80cc2948993b2fd65c5f15f07eb275 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Wed, 7 May 2025 14:29:30 +0100 Subject: [PATCH 4/9] Flash session (#255) * feature: type safe getters closes #81 * loosen type (can be array access) * feature: flash sessions closes #3 * tweak: check offset before getting offset (suppress php warning) --------- Co-authored-by: Greg Bowler --- src/Flash.php | 32 ++++++++++++++++++++ src/FlashMessage.php | 9 ++++++ src/SessionStore.php | 6 +++- test/FlashTest.php | 69 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/Flash.php create mode 100644 src/FlashMessage.php create mode 100644 test/FlashTest.php diff --git a/src/Flash.php b/src/Flash.php new file mode 100644 index 0000000..2ee0bb7 --- /dev/null +++ b/src/Flash.php @@ -0,0 +1,32 @@ +session->get("queue.$name"); + if(!$queue) { + $queue = new SplQueue(); + $this->session->set("queue.$name", $queue); + } + + $queue->enqueue(new FlashMessage($name, $message)); + } + + public function consume(string $name):?FlashMessage { + /** @var null|SplQueue $queue */ + $queue = $this->session->get("queue.$name"); + try { + return $queue->dequeue(); + } + catch(RuntimeException $e) { + $this->session->remove("queue.$name"); + return null; + } + } + +} diff --git a/src/FlashMessage.php b/src/FlashMessage.php new file mode 100644 index 0000000..7475eff --- /dev/null +++ b/src/FlashMessage.php @@ -0,0 +1,9 @@ +offsetGet($key) ?? null; + if(!$this->offsetExists($key)) { + return null; + } + + return $this->offsetGet($key); } public function containsData(string $key):bool { diff --git a/test/FlashTest.php b/test/FlashTest.php new file mode 100644 index 0000000..8056d6d --- /dev/null +++ b/test/FlashTest.php @@ -0,0 +1,69 @@ +expects(self::once()) + ->method("get") + ->with("queue.test") + ->willReturn(null); + $sessionStore->expects(self::once()) + ->method("set") + ->with( + self::equalTo("queue.test"), + self::isInstanceOf(SplQueue::class) + ); + + $sut = new Flash($sessionStore); + $sut->put("test", "Test message"); + } + + public function testConsume_none():void { + $queue = self::createMock(SplQueue::class); + $queue->expects(self::once()) + ->method("dequeue") + ->willThrowException(new RuntimeException("Can't shift from an empty datastructure")); + $sessionStore = self::createMock(SessionStore::class); + $sessionStore->expects(self::once()) + ->method("get") + ->with("queue.test") + ->willReturn($queue); + $sut = new Flash($sessionStore); + $flashMessage = $sut->consume("test"); + self::assertNull($flashMessage); + } + + public function testConsume():void { + $fm1 = new FlashMessage("test", "First"); + $fm2 = new FlashMessage("test", "Second"); + + $queue = self::createMock(SplQueue::class); + $queue->expects(self::exactly(3)) + ->method("dequeue") + ->willReturnOnConsecutiveCalls($fm1, $fm2); + + $sessionStore = self::createMock(SessionStore::class); + $sessionStore->expects(self::exactly(3)) + ->method("get") + ->with("queue.test") + ->willReturn($queue); + $sessionStore->expects(self::once()) + ->method("remove") + ->with("queue.test"); + $sut = new Flash($sessionStore); + + $flashMessage = $sut->consume("test"); + self::assertInstanceOf(FlashMessage::class, $flashMessage); + self::assertSame("First", $flashMessage->message); + $flashMessage = $sut->consume("test"); + self::assertInstanceOf(FlashMessage::class, $flashMessage); + self::assertSame("Second", $flashMessage->message); + $flashMessage = $sut->consume("test"); + self::assertNull($flashMessage); + } +} From 3ad0bb52bbfb2c5b9dd212220aa336c4d2176f22 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Wed, 7 May 2025 15:58:50 +0100 Subject: [PATCH 5/9] Upgrade PHPMD CI (#256) * feature: type safe getters closes #81 * loosen type (can be array access) * feature: flash sessions closes #3 * tweak: check offset before getting offset (suppress php warning) * ci: use phpmd@v2 --------- Co-authored-by: Greg Bowler --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 948ea04..7de7c9d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -132,7 +132,7 @@ jobs: run: tar -xvf /tmp/github-actions/build.tar ./ - name: PHP Mess Detector - uses: php-actions/phpmd@v1 + uses: php-actions/phpmd@v2 with: php_version: ${{ matrix.php }} path: src/ From bb3c8aabd7f07766eb346f20cd3fc4c7dddcfa32 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 May 2025 09:24:02 +0100 Subject: [PATCH 6/9] Bump phpstan/phpstan from 1.12.25 to 2.1.14 (#257) Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.12.25 to 2.1.14. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/2.1.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.12.25...2.1.14) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-version: 2.1.14 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- composer.lock | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index cf6ee88..63dbf65 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "phpgt/typesafegetter": "^1.3" }, "require-dev": { - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^10.1", "phpmd/phpmd": "^2.13", "squizlabs/php_codesniffer": "^3.7" diff --git a/composer.lock b/composer.lock index 0160b61..a6e3f05 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d32bb34f857ad466056beaa4e80cf68a", + "content-hash": "90f742569783bb1b522aa97fe7d3d045", "packages": [ { "name": "phpgt/typesafegetter", @@ -589,20 +589,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.25", + "version": "2.1.14", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e310849a19e02b8bfcbb63147f495d8f872dd96f" + "reference": "8f2e03099cac24ff3b379864d171c5acbfc6b9a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e310849a19e02b8bfcbb63147f495d8f872dd96f", - "reference": "e310849a19e02b8bfcbb63147f495d8f872dd96f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8f2e03099cac24ff3b379864d171c5acbfc6b9a2", + "reference": "8f2e03099cac24ff3b379864d171c5acbfc6b9a2", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -643,7 +643,7 @@ "type": "github" } ], - "time": "2025-04-27T12:20:45+00:00" + "time": "2025-05-02T15:32:28+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2840,12 +2840,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=8.1" }, - "platform-dev": {}, - "plugin-api-version": "2.6.0" + "platform-dev": [], + "plugin-api-version": "2.3.0" } From 2a5fdb91f44246267fd5b30afe6ae3f75616684a Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 12 Jun 2025 11:35:17 +0100 Subject: [PATCH 7/9] tweak: check for old use_trans_sid key --- src/Session.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Session.php b/src/Session.php index 318ad28..de9dcec 100644 --- a/src/Session.php +++ b/src/Session.php @@ -130,7 +130,7 @@ protected function getAbsolutePath(string $path):string { /** @SuppressWarnings(PHPMD.Superglobals) */ protected function createNewId():string { - if($this->config["use_trans_sid"] && !$this->config["use_cookies"]) { + if(($this->config["use_trans_sid"] ?? null) && !$this->config["use_cookies"]) { return $_GET[$this->config["name"]] ?? session_create_id(); } return session_create_id() ?: ""; @@ -196,7 +196,7 @@ private function getSessionOptions( "serialize_handler" => "php_serialize", "use_only_cookies" => $config["use_only_cookies"], "use_cookies" => $config["use_cookies"], - "use_trans_sid" => $config["use_trans_sid"], + "use_trans_sid" => $config["use_trans_sid"] ?? false, "cookie_lifetime" => $config["cookie_lifetime"], "cookie_path" => $config["cookie_path"], "cookie_domain" => $config["cookie_domain"], From 01b718a99cecb7dc40b0ff3a136417292d02ed84 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 12 Jun 2025 11:36:59 +0100 Subject: [PATCH 8/9] tweak: improve static analysis --- src/Flash.php | 2 +- src/Session.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Flash.php b/src/Flash.php index 2ee0bb7..0e1e7c6 100644 --- a/src/Flash.php +++ b/src/Flash.php @@ -18,7 +18,7 @@ public function put(string $name, string $message):void { } public function consume(string $name):?FlashMessage { - /** @var null|SplQueue $queue */ + /** @var null|SplQueue $queue */ $queue = $this->session->get("queue.$name"); try { return $queue->dequeue(); diff --git a/src/Session.php b/src/Session.php index de9dcec..d6e4e40 100644 --- a/src/Session.php +++ b/src/Session.php @@ -130,7 +130,8 @@ protected function getAbsolutePath(string $path):string { /** @SuppressWarnings(PHPMD.Superglobals) */ protected function createNewId():string { - if(($this->config["use_trans_sid"] ?? null) && !$this->config["use_cookies"]) { + if(($this->config["use_trans_sid"] ?? null) + && !$this->config["use_cookies"]) { return $_GET[$this->config["name"]] ?? session_create_id(); } return session_create_id() ?: ""; From ddf4b53920445240410719f1e2b24194b6eb311d Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 12 Jun 2025 11:37:30 +0100 Subject: [PATCH 9/9] tweak: remove obsolete test --- phpcs.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index b771656..ad96b86 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -25,7 +25,6 @@ -