commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CounterModel.php
1<?php
2
3declare(strict_types=1);
10
15use DateTimeImmutable;
16use stdClass;
17
21final class CounterModel extends JsonObjectModel implements Counter
22{
23 public const DISCRIMINATOR_VALUE = 'Counter';
28 protected $type;
29
34 protected $totalToSkip;
35
40 protected $skipped;
41
46 protected $lastSkippedAt;
47
48
52 public function __construct(
53 ?int $totalToSkip = null,
54 ?int $skipped = null,
55 ?DateTimeImmutable $lastSkippedAt = null,
56 ?string $type = null
57 ) {
58 $this->totalToSkip = $totalToSkip;
59 $this->skipped = $skipped;
60 $this->lastSkippedAt = $lastSkippedAt;
61 $this->type = $type ?? self::DISCRIMINATOR_VALUE;
62 }
63
68 public function getType()
69 {
70 if (is_null($this->type)) {
72 $data = $this->raw(self::FIELD_TYPE);
73 if (is_null($data)) {
74 return null;
75 }
76 $this->type = (string) $data;
77 }
78
79 return $this->type;
80 }
81
88 public function getTotalToSkip()
89 {
90 if (is_null($this->totalToSkip)) {
92 $data = $this->raw(self::FIELD_TOTAL_TO_SKIP);
93 if (is_null($data)) {
94 return null;
95 }
96 $this->totalToSkip = (int) $data;
97 }
98
99 return $this->totalToSkip;
100 }
101
108 public function getSkipped()
109 {
110 if (is_null($this->skipped)) {
112 $data = $this->raw(self::FIELD_SKIPPED);
113 if (is_null($data)) {
114 return null;
115 }
116 $this->skipped = (int) $data;
117 }
118
119 return $this->skipped;
120 }
121
128 public function getLastSkippedAt()
129 {
130 if (is_null($this->lastSkippedAt)) {
132 $data = $this->raw(self::FIELD_LAST_SKIPPED_AT);
133 if (is_null($data)) {
134 return null;
135 }
136 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
137 if (false === $data) {
138 return null;
139 }
140 $this->lastSkippedAt = $data;
141 }
142
144 }
145
146
150 public function setTotalToSkip(?int $totalToSkip): void
151 {
152 $this->totalToSkip = $totalToSkip;
153 }
154
158 public function setSkipped(?int $skipped): void
159 {
160 $this->skipped = $skipped;
161 }
162
166 public function setLastSkippedAt(?DateTimeImmutable $lastSkippedAt): void
167 {
168 $this->lastSkippedAt = $lastSkippedAt;
169 }
170
171
172 #[\ReturnTypeWillChange]
173 public function jsonSerialize()
174 {
175 $data = $this->toArray();
176 if (isset($data[Counter::FIELD_LAST_SKIPPED_AT]) && $data[Counter::FIELD_LAST_SKIPPED_AT] instanceof \DateTimeImmutable) {
177 $data[Counter::FIELD_LAST_SKIPPED_AT] = $data[Counter::FIELD_LAST_SKIPPED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
178 }
179 return (object) $data;
180 }
181}
setLastSkippedAt(?DateTimeImmutable $lastSkippedAt)
__construct(?int $totalToSkip=null, ?int $skipped=null, ?DateTimeImmutable $lastSkippedAt=null, ?string $type=null)