lukebeer / broadworks-ocip

PHP Framework for interacting with the Broadworks OCI Provisioning API
GNU General Public License v2.0
26 stars 15 forks source link

PHP Fatal error: Call to a member function getName() on null in #13

Open TwinMist opened 7 years ago

TwinMist commented 7 years ago

Hi When you try and do a XXXXGetListRequest for any service with a department it fails with the following

PHP Fatal error: Call to a member function getName() on null in /var/www/html/vendor/lukebeer/broadworks-ocip/src/BroadworksOCIP/Serializer/XMLSerializer.php on line 60

any ideas? cheers

lukebeer commented 4 years ago

I've had a look at the code, I suspect either there is no valid response or nothing to reflect into - I'm sure tableType responses did work.

Can you provide a test login and host for me to replicate?

src/BroadworksOCIP/Serializer/XMLSerializer.php


    /**
     * Builds the object recursively generating and setting ComplexTypes/SimpleTypes/TableTypes along the way.
     *
     * @param $destinationObject
     * @param $simpleXMLElement
     * @return object
     */
    public function buildComplex($destinationObject, $simpleXMLElement)
    {
        $reflectionClass = new \ReflectionClass($destinationObject);
        $object = $reflectionClass->newInstance();
        $methods = get_class_methods($destinationObject);
        foreach ($simpleXMLElement->children() as $key => $value) {
            $methodName = 'set' . ucfirst($key);
            if (in_array($methodName, $methods, null)) {
                if (count($value->children()) === 0) {
                    $object->$methodName((string)$value);
                } else {
                    if (preg_match('/Table/i', (string)$key)) {
                        $obj = new TableType($key, $value);
                    } else {
                        $method = $reflectionClass->getMethod($methodName)->getParameters();

                        //  PHP Fatal thrown here
                        $type = $method[0]->getClass()->getName();

                        $obj = $this->buildComplex($type, $value);
                    }
                    $object->$methodName($obj);
                }
            }
        }
        return $object;
    }