cpapdotcom/asendia

View on GitHub
src/Cpapdotcom/Asendia/Manifest/Manifest.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Cpapdotcom\Asendia\Manifest;

use DateTime;

/**
 * @method static withHeader(Header $header)
 */
class Manifest implements Properties
{
    use WithProperties;

    private function __construct() { }

    public static function create($accountNumber, $companyName, DateTime $timeStamp = null)
    {
        return (new static())
            ->withHeader(Header::create($accountNumber, $companyName, $timeStamp))
            ->withProperty('Package', [])
        ;
    }

    public function withTimestamp(DateTime $timeStamp)
    {
        $instance = clone($this);

        $header = $instance->getProperty('Header');

        return $instance->withHeader($header->withTimestamp($timeStamp));
    }

    public function withPackage(Package $package)
    {
        $instance = clone($this);

        $packages = $instance->getProperty('Package');
        $packages[] = $package;

        return $instance->withProperty('Package', $packages);
    }

    public function getPropertyNames()
    {
        return [
            'Header',
            'Package',
        ];
    }
}