Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
35.00% covered (danger)
35.00%
7 / 20
CRAP
20.51% covered (danger)
20.51%
16 / 78
PostDataMutable
0.00% covered (danger)
0.00%
0 / 1
35.00% covered (danger)
35.00%
7 / 20
1688.70
20.51% covered (danger)
20.51%
16 / 78
 __construct
0.00% covered (danger)
0.00%
0 / 1
15.46
10.53% covered (danger)
10.53%
2 / 19
 fromArray
0.00% covered (danger)
0.00%
0 / 1
132
0.00% covered (danger)
0.00%
0 / 12
 fromIterable
0.00% covered (danger)
0.00%
0 / 1
182
0.00% covered (danger)
0.00%
0 / 13
 getId
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 getTitle
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getSlug
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getSummary
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getContent
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getPublishedAt
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getAuthorId
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getCommentCount
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 get
0.00% covered (danger)
0.00%
0 / 1
90
0.00% covered (danger)
0.00%
0 / 10
 setId
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
2 / 2
 setTitle
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 setSlug
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 setSummary
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 setContent
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 setPublishedAt
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 setAuthorId
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 setCommentCount
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 2
<?php declare(strict_types = 1);
//
// Generated by Smalldb\CodeCooker\Generator\DtoGenerator.
// Do NOT edit! All changes will be lost!
// 
// 
namespace Smalldb\StateMachine\Test\Example\Post\PostData;
use DateTimeImmutable;
use InvalidArgumentException;
use Smalldb\CodeCooker\Annotation\GeneratedClass;
use Smalldb\StateMachine\Test\Example\Post\PostProperties as Source_PostProperties;
/**
 * @GeneratedClass
 * @see \Smalldb\StateMachine\Test\Example\Post\PostProperties
 */
class PostDataMutable extends Source_PostProperties implements PostData
{
    public function __construct(?PostData $source = null)
    {
        if ($source !== null) {
            if ($source instanceof Source_PostProperties) {
                $this->id = $source->id;
                $this->title = $source->title;
                $this->slug = $source->slug;
                $this->summary = $source->summary;
                $this->content = $source->content;
                $this->publishedAt = $source->publishedAt;
                $this->authorId = $source->authorId;
                $this->commentCount = $source->commentCount;
            } else {
                $this->id = $source->getId();
                $this->title = $source->getTitle();
                $this->slug = $source->getSlug();
                $this->summary = $source->getSummary();
                $this->content = $source->getContent();
                $this->publishedAt = $source->getPublishedAt();
                $this->authorId = $source->getAuthorId();
                $this->commentCount = $source->getCommentCount();
            }
        }
    }
    public static function fromArray(?array $source, ?PostData $sourceObj = null): ?self
    {
        if ($source === null) {
            return null;
        }
        $t = $sourceObj instanceof self ? clone $sourceObj : new self($sourceObj);
        $t->id = isset($source['id']) ? (int) $source['id'] : null;
        $t->title = (string) $source['title'];
        $t->slug = (string) $source['slug'];
        $t->summary = (string) $source['summary'];
        $t->content = (string) $source['content'];
        $t->publishedAt = ($v = $source['publishedAt'] ?? null) instanceof \DateTimeImmutable || $v === null ? $v : ($v instanceof \DateTime ? \DateTimeImmutable::createFromMutable($v) : new \DateTimeImmutable($v));
        $t->authorId = (int) $source['authorId'];
        $t->commentCount = isset($source['commentCount']) ? (int) $source['commentCount'] : null;
        return $t;
    }
    public static function fromIterable(?PostData $sourceObj, iterable $source): self
    {
        $t = $sourceObj instanceof self ? clone $sourceObj : new self($sourceObj);
        foreach ($source as $prop => $value) {
            switch ($prop) {
                case 'id': $t->id = $value; break;
                case 'title': $t->title = $value; break;
                case 'slug': $t->slug = $value; break;
                case 'summary': $t->summary = $value; break;
                case 'content': $t->content = $value; break;
                case 'publishedAt': $t->publishedAt = $value instanceof \DateTime ? \DateTimeImmutable::createFromMutable($value) : $value; break;
                case 'authorId': $t->authorId = $value; break;
                case 'commentCount': $t->commentCount = $value; break;
                default: throw new InvalidArgumentException('Unknown property: "' . $prop . '" not in ' . __CLASS__);
            }
        }
        return $t;
    }
    public function getId(): ?int
    {
        return $this->id;
    }
    public function getTitle(): string
    {
        return $this->title;
    }
    public function getSlug(): string
    {
        return $this->slug;
    }
    public function getSummary(): string
    {
        return $this->summary;
    }
    public function getContent(): string
    {
        return $this->content;
    }
    public function getPublishedAt(): DateTimeImmutable
    {
        return $this->publishedAt;
    }
    public function getAuthorId(): int
    {
        return $this->authorId;
    }
    public function getCommentCount(): ?int
    {
        return $this->commentCount;
    }
    public static function get(PostData $source, string $propertyName)
    {
        switch ($propertyName) {
            case 'id': return $source->getId();
            case 'title': return $source->getTitle();
            case 'slug': return $source->getSlug();
            case 'summary': return $source->getSummary();
            case 'content': return $source->getContent();
            case 'publishedAt': return $source->getPublishedAt();
            case 'authorId': return $source->getAuthorId();
            case 'commentCount': return $source->getCommentCount();
            default: throw new \InvalidArgumentException("Unknown property: " . $propertyName);
        }
    }
    public function setId(?int $id): void
    {
        $this->id = $id;
    }
    public function setTitle(string $title): void
    {
        $this->title = $title;
    }
    public function setSlug(string $slug): void
    {
        $this->slug = $slug;
    }
    public function setSummary(string $summary): void
    {
        $this->summary = $summary;
    }
    public function setContent(string $content): void
    {
        $this->content = $content;
    }
    public function setPublishedAt(DateTimeImmutable $publishedAt): void
    {
        $this->publishedAt = $publishedAt;
    }
    public function setAuthorId(int $authorId): void
    {
        $this->authorId = $authorId;
    }
    public function setCommentCount(?int $commentCount): void
    {
        $this->commentCount = $commentCount;
    }
}