]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/Cache/PConfigCache.php
wrapping up 2019.12
[friendica.git] / src / Core / Config / Cache / PConfigCache.php
index 98adfa2ce1ce5171e2fb1f0e0fbfb2824e0b67ca..b0dd209cbf9d07bb2af14a884b1829526fe83636 100644 (file)
@@ -20,9 +20,9 @@ class PConfigCache
        private $hidePasswordOutput;
 
        /**
-        * @param bool  $hidePasswordOutput True, if cache variables should take extra care of password values
+        * @param bool $hidePasswordOutput True, if cache variables should take extra care of password values
         */
-       public function __construct($hidePasswordOutput = true)
+       public function __construct(bool $hidePasswordOutput = true)
        {
                $this->hidePasswordOutput = $hidePasswordOutput;
        }
@@ -36,6 +36,10 @@ class PConfigCache
         */
        public function load($uid, array $config)
        {
+               if (!is_int($uid)) {
+                       return;
+               }
+
                $categories = array_keys($config);
 
                foreach ($categories as $category) {
@@ -56,14 +60,18 @@ class PConfigCache
        /**
         * Retrieves a value from the user config cache
         *
-        * @param int    $uid     User Id
-        * @param string $cat     Config category
-        * @param string $key     Config key
+        * @param int    $uid User Id
+        * @param string $cat Config category
+        * @param string $key Config key
         *
         * @return null|string The value of the config entry or null if not set
         */
-       public function get($uid, $cat, $key = null)
+       public function get($uid, string $cat, string $key = null)
        {
+               if (!is_int($uid)) {
+                       return null;
+               }
+
                if (isset($this->config[$uid][$cat][$key])) {
                        return $this->config[$uid][$cat][$key];
                } elseif (!isset($key) && isset($this->config[$uid][$cat])) {
@@ -85,8 +93,12 @@ class PConfigCache
         *
         * @return bool Set successful
         */
-       public function set($uid, $cat, $key, $value)
+       public function set($uid, string $cat, string $key, $value)
        {
+               if (!is_int($uid)) {
+                       return false;
+               }
+
                if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
                        $this->config[$uid] = [];
                }
@@ -98,7 +110,7 @@ class PConfigCache
                if ($this->hidePasswordOutput &&
                    $key == 'password' &&
                    !empty($value) && is_string($value)) {
-                       $this->config[$uid][$cat][$key] = new HiddenString((string) $value);
+                       $this->config[$uid][$cat][$key] = new HiddenString((string)$value);
                } else {
                        $this->config[$uid][$cat][$key] = $value;
                }
@@ -116,8 +128,12 @@ class PConfigCache
         *
         * @return bool true, if deleted
         */
-       public function delete($uid, $cat, $key)
+       public function delete($uid, string $cat, string $key)
        {
+               if (!is_int($uid)) {
+                       return false;
+               }
+
                if (isset($this->config[$uid][$cat][$key])) {
                        unset($this->config[$uid][$cat][$key]);
                        if (count($this->config[$uid][$cat]) == 0) {