gabrielbull/php-ups-api

View on GitHub
src/Entity/ShipFrom.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Ups\Entity;

use DOMDocument;
use DOMElement;
use Ups\NodeInterface;

class ShipFrom extends Shipper implements NodeInterface
{
    /**
     * @param null|DOMDocument $document
     *
     * @return DOMElement
     */
    public function toNode(DOMDocument $document = null)
    {
        if (null === $document) {
            $document = new DOMDocument();
        }

        $node = $document->createElement('ShipFrom');

        if ($this->getCompanyName()) {
            $node->appendChild($document->createElement('CompanyName', $this->getCompanyName()));
        }

        if ($this->getAttentionName()) {
            $node->appendChild($document->createElement('AttentionName', $this->getAttentionName()));
        }

        $address = $this->getAddress();
        if (isset($address)) {
            $node->appendChild($address->toNode($document));
        }

        $vendorInfo = $this->getVendorInfo();
        if (isset($vendorInfo)) {
            $node->appendChild($vendorInfo->toNode($document));
        }

        return $node;
    }
}