massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / flatted / php / flatted.php
index 31c0d41d4535e9b4a927c921ea72a5b16cb773b1..30585bf9455db178be084ac6659b40d3efe023b0 100644 (file)
@@ -3,7 +3,7 @@
 /*!
  * ISC License
  * 
- * Copyright (c) 2018-2020, Andrea Giammarchi, @WebReflection
+ * Copyright (c) 2018-2021, Andrea Giammarchi, @WebReflection
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -60,7 +60,7 @@ class Flatted {
   }
 
   // private helpers
-  private static function asString(&$value) {
+  private static function asString($value) {
     return $value instanceof FlattedString ? $value->value : $value;
   }
 
@@ -76,42 +76,25 @@ class Flatted {
     $obj = new ReflectionObject($value);
     $props = $obj->getProperties();
     $keys = array();
-    foreach ($props as $prop) {
+    foreach ($props as $prop)
       $keys[] = $prop->getName();
-    }
     return $keys;
   }
 
   private static function loop($obj, $keys, &$input, &$set, &$output) {
     foreach ($keys as $key) {
       $value = $obj ? $output->$key : $output[$key];
-      if ($value instanceof FlattedString) {
+      if ($value instanceof FlattedString)
         Flatted::ref($obj, $key, $input[$value->value], $input, $set, $output);
-      }
     }
     return $output;
   }
 
   private static function relate(&$known, &$input, &$value) {
-    if (is_string($value)) {
-      $key = array_search($value, $known->key, true);
-      if ($key !== false) {
-        return $known->value[$key];
-      }
-      return Flatted::index($known, $input, $value);
-    }
-    if (is_array($value)) {
+    if (is_string($value) || is_array($value) || is_object($value)) {
       $key = array_search($value, $known->key, true);
-      if ($key !== false) {
+      if ($key !== false)
         return $known->value[$key];
-      }
-      return Flatted::index($known, $input, $value);
-    }
-    if (is_object($value)) {
-      $key = array_search($value, $known->key, true);
-      if ($key !== false) {
-        return $known->value[$key];
-      }
       return Flatted::index($known, $input, $value);
     }
     return $value;
@@ -137,7 +120,7 @@ class Flatted {
   private static function transform(&$known, &$input, &$value) {
     if (is_array($value)) {
       return array_map(
-        function (&$value) use(&$known, &$input) {
+        function ($value) use(&$known, &$input) {
           return Flatted::relate($known, $input, $value);
         },
         $value
@@ -146,15 +129,14 @@ class Flatted {
     if (is_object($value)) {
       $object = new stdClass;
       $keys = Flatted::keys($value);
-      foreach ($keys as $key) {
+      foreach ($keys as $key)
         $object->$key = Flatted::relate($known, $input, $value->$key);
-      }
       return $object;
     }
     return $value;
   }
 
-  private static function wrap(&$value) {
+  private static function wrap($value) {
     if (is_string($value)) {
       return new FlattedString($value);
     }