src/Facades/FacadeHelper.php
public static function reflectArrayToObject($classNameOrKeyName, $data, $throwException = TRUE) {
     if(!isset($classNameOrKeyName)){ throw new \Exception("The Class Name or Key Name cannot be NULL when generating Objects.");}
     if(!isset($data) || empty($data)){ throw new \Exception("The passed data cannot be NULL.");}
     if(is_object($data)){
       if(!FacadeHelper::checkIfTheObjectIsAnInstanceOfTheClass($classNameOrKeyName,$data)){
         throw new \Exception("The assigned object is not an instance of required object:{" . $classNameOrKeyName . "}.");
       }else{
         return $data;
       }
     }
     //Get reflection class of FacadeHelper
     $trimedData = FacadeHelper::trimSpacesForArrayKeys($data);
     //Any key in the Ignored List will not be processed
     $IgnoredList = FacadeClassMapper::IgnoredComplexTypeNameEntity();
     //Intuit does not name every Key with its corresponding class as IPP . $key; for some classes, the IPP . $key was not a class name. Those
     //type will located at the Mapper as an array
     $ObjectMap = FacadeClassMapper::classMethodToList();

     //If the key is in complexList
     if(FacadeHelper::isKeyInComplexList($classNameOrKeyName)){
         $methodFound = FacadeHelper::isKeyInComplexList($classNameOrKeyName);
         $createdObj = FacadeHelper::getComplexListObject($methodFound, $classNameOrKeyName, $trimedData);
         return $createdObj;
     } else if(FacadeHelper::isKeyEnumType($classNameOrKeyName)){
         $enumTypeClassName = FacadeHelper::isKeyEnumType($classNameOrKeyName);
         $createdObj = FacadeHelper::getEnumType($enumTypeClassName, $trimedData);
         return $createdObj;
     }
     else{
         //The key can be constructed with an IPPObject
         $clazz = FacadeHelper::decorateKeyWithNameSpaceAndPrefix($classNameOrKeyName);
         if(class_exists($clazz)){
            $currentObj = new $clazz();
            foreach($trimedData as $key => $val){
                if(is_array($val)){
                    if (FacadeHelper::isAssociateArray($val)){
                       //Key value pair. The value can be another array
                       //For example, SalesItemLineDetail as $key and
                       //          {
                       //  "ItemRef": {
                       //      "value": "14",
                       //      "name": "Sod"
                       //  },
                       //  "Qty": 0,
                       //  "TaxCodeRef": {
                       //      "value": "TAX"
                       //  }
                       // }as $val
                       $obj = FacadeHelper::reflectArrayToObject($key, $val, $throwException);
                       FacadeHelper::assignValue($currentObj, $key, $obj);
                    } else if(FacadeHelper::isArrayOfObj($val)){
                         // Array of LineItem object, for example
                         foreach($val as $valobj){
                            if(!FacadeHelper::checkIfTheObjectIsAnInstanceOfTheClass($key,$valobj)){
                              throw new \Exception("The assigned object is not an instance of required object:{" . $key . "}.");
                            }
                         }
                         FacadeHelper::assignValue($currentObj, $key, $val);
                    } else{
                        //The array is a recursive array. It can be an Line or LinkedTxn
                        //Example:
                        // Line": [{ ....}, {...}]
                        //For each element in the array, it is a line
                        //or It can be an mix of lines and Objects
                        //Line": [{ ....}, $obj1, {...}]
                        $list = array();
                        foreach ($val as $index => $element) {
                            if(is_object($element)){
                              if(!FacadeHelper::checkIfTheObjectIsAnInstanceOfTheClass($key,$element)){
                                throw new \Exception("The assigned object is not an instance of required object:{" . $key . "}.");
                              }
                              array_push($list, $element);
                            }else if(is_array($element)){
                              $obj = FacadeHelper::reflectArrayToObject($key, $element, $throwException);
                              array_push($list, $obj);
                            }else{
                              throw new \Exception("Format Error. Expect an element of an array or an object.");
                            }
                          }
                        FacadeHelper::assignValue($currentObj, $key, $list);
                     }
                }else{
                    //Even the value is a key, the key can be an Enum type or a wrapper
                    if(FacadeHelper::isKeyInComplexList($key)){
                        $methodFound = FacadeHelper::isKeyInComplexList($key);
                        $createdObj = FacadeHelper::getComplexListObject($methodFound, $key, $val);
                        FacadeHelper::assignValue($currentObj, $key, $createdObj);
                    }
                    //If it is enum type
                    else if(FacadeHelper::isKeyEnumType($key)){
                        $enumTypeClassName = FacadeHelper::isKeyEnumType($key);
                        $createdObj = FacadeHelper::getEnumType($enumTypeClassName, $val);
                        FacadeHelper::assignValue($currentObj, $key, $createdObj);
                    }
                    else
                    {
                      //If it is an object
                      if(is_object($val)){
                        if(!FacadeHelper::checkIfTheObjectIsAnInstanceOfTheClass($key,$val)){
                          throw new \Exception("The assigned object is not an instance of required object:{" . $key . "}.");
                        }
                      }
                      FacadeHelper::assignValue($currentObj, $key, $val);
                    }
                }
            }
            return $currentObj;
         }else{
            //The key can't be construct with An App Object
            if($throwException)
            {
              throw new \Exception("The name value:{" . $classNameOrKeyName . "} can't be used to construct an Intuit Entity Object. Please check the name and try again.");
            }else{
              return NULL;
            }
         }
     }
   }
public static function reflectArrayToObject($classNameOrKeyName, $data, $throwException = TRUE) {
     if(!isset($classNameOrKeyName)){ throw new \Exception("The Class Name or Key Name cannot be NULL when generating Objects.");}
     if(!isset($data) || empty($data)){ throw new \Exception("The passed data cannot be NULL.");}
     if(is_object($data)){
       if(!FacadeHelper::checkIfTheObjectIsAnInstanceOfTheClass($classNameOrKeyName,$data)){
         throw new \Exception("The assigned object is not an instance of required object:{" . $classNameOrKeyName . "}.");
       }else{
         return $data;
       }
     }
     //Get reflection class of FacadeHelper
     $trimedData = FacadeHelper::trimSpacesForArrayKeys($data);
     //Any key in the Ignored List will not be processed
     $IgnoredList = FacadeClassMapper::IgnoredComplexTypeNameEntity();
     //Intuit does not name every Key with its corresponding class as IPP . $key; for some classes, the IPP . $key was not a class name. Those
     //type will located at the Mapper as an array
     $ObjectMap = FacadeClassMapper::classMethodToList();

     //If the key is in complexList
     if(FacadeHelper::isKeyInComplexList($classNameOrKeyName)){
         $methodFound = FacadeHelper::isKeyInComplexList($classNameOrKeyName);
         $createdObj = FacadeHelper::getComplexListObject($methodFound, $classNameOrKeyName, $trimedData);
         return $createdObj;
     } else if(FacadeHelper::isKeyEnumType($classNameOrKeyName)){
         $enumTypeClassName = FacadeHelper::isKeyEnumType($classNameOrKeyName);
         $createdObj = FacadeHelper::getEnumType($enumTypeClassName, $trimedData);
         return $createdObj;
     }
     else{
         //The key can be constructed with an IPPObject
         $clazz = FacadeHelper::decorateKeyWithNameSpaceAndPrefix($classNameOrKeyName);
         if(class_exists($clazz)){
            $currentObj = new $clazz();
            foreach($trimedData as $key => $val){
                if(is_array($val)){
                    if (FacadeHelper::isAssociateArray($val)){
                       //Key value pair. The value can be another array
                       //For example, SalesItemLineDetail as $key and
                       //          {
                       //  "ItemRef": {
                       //      "value": "14",
                       //      "name": "Sod"
                       //  },
                       //  "Qty": 0,
                       //  "TaxCodeRef": {
                       //      "value": "TAX"
                       //  }
                       // }as $val
                       $obj = FacadeHelper::reflectArrayToObject($key, $val, $throwException);
                       FacadeHelper::assignValue($currentObj, $key, $obj);
                    } else if(FacadeHelper::isArrayOfObj($val)){
                         // Array of LineItem object, for example
                         foreach($val as $valobj){
                            if(!FacadeHelper::checkIfTheObjectIsAnInstanceOfTheClass($key,$valobj)){
                              throw new \Exception("The assigned object is not an instance of required object:{" . $key . "}.");
                            }
                         }
                         FacadeHelper::assignValue($currentObj, $key, $val);
                    } else{
                        //The array is a recursive array. It can be an Line or LinkedTxn
                        //Example:
                        // Line": [{ ....}, {...}]
                        //For each element in the array, it is a line
                        //or It can be an mix of lines and Objects
                        //Line": [{ ....}, $obj1, {...}]
                        $list = array();
                        foreach ($val as $index => $element) {
                            if(is_object($element)){
                              if(!FacadeHelper::checkIfTheObjectIsAnInstanceOfTheClass($key,$element)){
                                throw new \Exception("The assigned object is not an instance of required object:{" . $key . "}.");
                              }
                              array_push($list, $element);
                            }else if(is_array($element)){
                              $obj = FacadeHelper::reflectArrayToObject($key, $element, $throwException);
                              array_push($list, $obj);
                            }else{
                              throw new \Exception("Format Error. Expect an element of an array or an object.");
                            }
                          }
                        FacadeHelper::assignValue($currentObj, $key, $list);
                     }
                }else{
                    //Even the value is a key, the key can be an Enum type or a wrapper
                    if(FacadeHelper::isKeyInComplexList($key)){
                        $methodFound = FacadeHelper::isKeyInComplexList($key);
                        $createdObj = FacadeHelper::getComplexListObject($methodFound, $key, $val);
                        FacadeHelper::assignValue($currentObj, $key, $createdObj);
                    }
                    //If it is enum type
                    else if(FacadeHelper::isKeyEnumType($key)){
                        $enumTypeClassName = FacadeHelper::isKeyEnumType($key);
                        $createdObj = FacadeHelper::getEnumType($enumTypeClassName, $val);
                        FacadeHelper::assignValue($currentObj, $key, $createdObj);
                    }
                    else
                    {
                      //If it is an object
                      if(is_object($val)){
                        if(!FacadeHelper::checkIfTheObjectIsAnInstanceOfTheClass($key,$val)){
                          throw new \Exception("The assigned object is not an instance of required object:{" . $key . "}.");
                        }
                      }
                      FacadeHelper::assignValue($currentObj, $key, $val);
                    }
                }
            }
            return $currentObj;
         }else{
            //The key can't be construct with An App Object
            if($throwException)
            {
              throw new \Exception("The name value:{" . $classNameOrKeyName . "} can't be used to construct an Intuit Entity Object. Please check the name and try again.");
            }else{
              return NULL;
            }
         }
     }
   }
A helper reflection class to assign object to Target Object