diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-02-26 22:20:21 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-02-26 22:20:21 +0100 |
commit | 8cb6bb3987cef8bd536f35854ae4da15d390d7a0 (patch) | |
tree | 82cbe362d276b775c2e3e4593a864cd5aebeb9f5 /lib/private/Session | |
parent | 695e32d0a66c6c5293291c3f31c5458fd5c248db (diff) | |
download | nextcloud-server-8cb6bb3987cef8bd536f35854ae4da15d390d7a0.tar.gz nextcloud-server-8cb6bb3987cef8bd536f35854ae4da15d390d7a0.zip |
Make ISession strict
* Make all implementations strict
* Add scalar types
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Session')
-rw-r--r-- | lib/private/Session/CryptoSessionData.php | 17 | ||||
-rw-r--r-- | lib/private/Session/Internal.php | 21 | ||||
-rw-r--r-- | lib/private/Session/Memory.php | 19 | ||||
-rw-r--r-- | lib/private/Session/Session.php | 5 |
4 files changed, 33 insertions, 29 deletions
diff --git a/lib/private/Session/CryptoSessionData.php b/lib/private/Session/CryptoSessionData.php index 530bd9063c3..b63b568875e 100644 --- a/lib/private/Session/CryptoSessionData.php +++ b/lib/private/Session/CryptoSessionData.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -55,7 +56,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { */ public function __construct(ISession $session, ICrypto $crypto, - $passphrase) { + string $passphrase) { $this->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 d137d72a048..1d0466ec349 100644 --- a/lib/private/Session/Internal.php +++ b/lib/private/Session/Internal.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -43,8 +44,8 @@ class Internal extends Session { * @param string $name * @throws \Exception */ - public function __construct($name) { - set_error_handler(array($this, 'trapError')); + public function __construct(string $name) { + set_error_handler([$this, 'trapError']); $this->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 22d6ffa0110..79900bc8067 100644 --- a/lib/private/Session/Memory.php +++ b/lib/private/Session/Memory.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -40,16 +41,16 @@ use OCP\Session\Exceptions\SessionNotAvailableException; class Memory extends Session { protected $data; - public function __construct($name) { + public function __construct(string $name) { //no need to use $name since all data is already scoped to this instance - $this->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 49afc564306..cadbb7e7ad4 100644 --- a/lib/private/Session/Session.php +++ b/lib/private/Session/Session.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -38,13 +39,13 @@ abstract class Session implements \ArrayAccess, ISession { * * @param string $name */ - abstract public function __construct($name); + abstract public function __construct(string $name); /** * @param mixed $offset * @return bool */ - public function offsetExists($offset) { + public function offsetExists($offset): bool { return $this->exists($offset); } |