From 8cb6bb3987cef8bd536f35854ae4da15d390d7a0 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 26 Feb 2018 22:20:21 +0100 Subject: [PATCH] Make ISession strict * Make all implementations strict * Add scalar types Signed-off-by: Roeland Jago Douma --- lib/private/Session/CryptoSessionData.php | 17 +++++++++-------- lib/private/Session/Internal.php | 21 +++++++++++---------- lib/private/Session/Memory.php | 19 ++++++++++--------- lib/private/Session/Session.php | 5 +++-- lib/public/ISession.php | 15 +++++++++------ 5 files changed, 42 insertions(+), 35 deletions(-) diff --git a/lib/private/Session/CryptoSessionData.php b/lib/private/Session/CryptoSessionData.php index 530bd9063c..b63b568875 100644 --- a/lib/private/Session/CryptoSessionData.php +++ b/lib/private/Session/CryptoSessionData.php @@ -1,4 +1,5 @@ crypto = $crypto; $this->session = $session; $this->passphrase = $passphrase; @@ -92,7 +93,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param string $key * @param mixed $value */ - public function set($key, $value) { + public function set(string $key, $value) { $this->sessionValues[$key] = $value; $this->isModified = true; } @@ -103,7 +104,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param string $key * @return string|null Either the value or null */ - public function get($key) { + public function get(string $key) { if(isset($this->sessionValues[$key])) { return $this->sessionValues[$key]; } @@ -117,7 +118,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param string $key * @return bool */ - public function exists($key) { + public function exists(string $key): bool { return isset($this->sessionValues[$key]); } @@ -126,7 +127,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { * * @param string $key */ - public function remove($key) { + public function remove(string $key) { $this->isModified = true; unset($this->sessionValues[$key]); $this->session->remove(self::encryptedSessionName); @@ -151,7 +152,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param bool $deleteOldSession Whether to delete the old associated session file or not. * @return void */ - public function regenerateId($deleteOldSession = true) { + public function regenerateId(bool $deleteOldSession = true) { $this->session->regenerateId($deleteOldSession); } @@ -162,7 +163,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @throws SessionNotAvailableException * @since 9.1.0 */ - public function getId() { + public function getId(): string { return $this->session->getId(); } @@ -182,7 +183,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param mixed $offset * @return bool */ - public function offsetExists($offset) { + public function offsetExists($offset): bool { return $this->exists($offset); } diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php index d137d72a04..1d0466ec34 100644 --- a/lib/private/Session/Internal.php +++ b/lib/private/Session/Internal.php @@ -1,4 +1,5 @@ invoke('session_name', [$name]); try { $this->invoke('session_start'); @@ -61,7 +62,7 @@ class Internal extends Session { * @param string $key * @param integer $value */ - public function set($key, $value) { + public function set(string $key, $value) { $this->validateSession(); $_SESSION[$key] = $value; } @@ -70,7 +71,7 @@ class Internal extends Session { * @param string $key * @return mixed */ - public function get($key) { + public function get(string $key) { if (!$this->exists($key)) { return null; } @@ -81,14 +82,14 @@ class Internal extends Session { * @param string $key * @return bool */ - public function exists($key) { + public function exists(string $key): bool { return isset($_SESSION[$key]); } /** * @param string $key */ - public function remove($key) { + public function remove(string $key) { if (isset($_SESSION[$key])) { unset($_SESSION[$key]); } @@ -112,7 +113,7 @@ class Internal extends Session { * @param bool $deleteOldSession Whether to delete the old associated session file or not. * @return void */ - public function regenerateId($deleteOldSession = true) { + public function regenerateId(bool $deleteOldSession = true) { try { @session_regenerate_id($deleteOldSession); } catch (\Error $e) { @@ -127,7 +128,7 @@ class Internal extends Session { * @throws SessionNotAvailableException * @since 9.1.0 */ - public function getId() { + public function getId(): string { $id = $this->invoke('session_id', [], true); if ($id === '') { throw new SessionNotAvailableException(); @@ -147,7 +148,7 @@ class Internal extends Session { * @param string $errorString * @throws \ErrorException */ - public function trapError($errorNumber, $errorString) { + public function trapError(int $errorNumber, string $errorString) { throw new \ErrorException($errorString); } @@ -167,7 +168,7 @@ class Internal extends Session { * @throws \ErrorException via trapError * @return mixed */ - private function invoke($functionName, array $parameters = [], $silence = false) { + private function invoke(string $functionName, array $parameters = [], bool $silence = false) { try { if($silence) { return @call_user_func_array($functionName, $parameters); diff --git a/lib/private/Session/Memory.php b/lib/private/Session/Memory.php index 22d6ffa011..79900bc806 100644 --- a/lib/private/Session/Memory.php +++ b/lib/private/Session/Memory.php @@ -1,4 +1,5 @@ data = array(); + $this->data = []; } /** * @param string $key * @param integer $value */ - public function set($key, $value) { + public function set(string $key, $value) { $this->validateSession(); $this->data[$key] = $value; } @@ -58,7 +59,7 @@ class Memory extends Session { * @param string $key * @return mixed */ - public function get($key) { + public function get(string $key) { if (!$this->exists($key)) { return null; } @@ -69,20 +70,20 @@ class Memory extends Session { * @param string $key * @return bool */ - public function exists($key) { + public function exists(string $key): bool { return isset($this->data[$key]); } /** * @param string $key */ - public function remove($key) { + public function remove(string $key) { $this->validateSession(); unset($this->data[$key]); } public function clear() { - $this->data = array(); + $this->data = []; } /** @@ -90,7 +91,7 @@ class Memory extends Session { * * @param bool $deleteOldSession */ - public function regenerateId($deleteOldSession = true) {} + public function regenerateId(bool $deleteOldSession = true) {} /** * Wrapper around session_id @@ -99,7 +100,7 @@ class Memory extends Session { * @throws SessionNotAvailableException * @since 9.1.0 */ - public function getId() { + public function getId(): string { throw new SessionNotAvailableException('Memory session does not have an ID'); } diff --git a/lib/private/Session/Session.php b/lib/private/Session/Session.php index 49afc56430..cadbb7e7ad 100644 --- a/lib/private/Session/Session.php +++ b/lib/private/Session/Session.php @@ -1,4 +1,5 @@ exists($offset); } diff --git a/lib/public/ISession.php b/lib/public/ISession.php index 2d23497686..411356b8dc 100644 --- a/lib/public/ISession.php +++ b/lib/public/ISession.php @@ -1,4 +1,5 @@