Skip to content

Commit c6b0d14

Browse files
authored
Merge pull request #3 from pavog/fix-return-type
Change return types of many functions to static and adjust some phpdocs
2 parents 7a4fcd6 + 24bfd61 commit c6b0d14

12 files changed

+27
-23
lines changed

src/IO/Reader/AbstractReader.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function getFormat(): int
3131

3232
/**
3333
* @param int $format
34-
* @return AbstractReader
34+
* @return $this
3535
*/
36-
public function setFormat(int $format): AbstractReader
36+
public function setFormat(int $format): static
3737
{
3838
$this->format = $format;
3939
$this->deserializer = null;

src/IO/Writer/AbstractWriter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function getFormat(): int
3131

3232
/**
3333
* @param int $format
34-
* @return AbstractWriter
34+
* @return $this
3535
*/
36-
public function setFormat(int $format): AbstractWriter
36+
public function setFormat(int $format): static
3737
{
3838
$this->format = $format;
3939
$this->serializer = null;

src/Tag/CompoundTag.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function jsonSerialize()
239239
* @return $this
240240
* @throws Exception
241241
*/
242-
public function set(?string $name, Tag $tag): CompoundTag
242+
public function set(?string $name, Tag $tag): static
243243
{
244244
$this->offsetSet($name, $tag);
245245
return $this;
@@ -250,7 +250,7 @@ public function set(?string $name, Tag $tag): CompoundTag
250250
* @return $this
251251
* @throws Exception
252252
*/
253-
public function delete(string $name): CompoundTag
253+
public function delete(string $name): static
254254
{
255255
$this->offsetUnset($name);
256256
return $this;

src/Tag/DoubleTag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected static function readContentRaw(Reader $reader, TagOptions $options): s
4646
/**
4747
* @inheritDoc
4848
*/
49-
public function setValue(float $value): FloatValueTag
49+
public function setValue(float $value): static
5050
{
5151
$this->resetRawValue();
5252
return parent::setValue($value);

src/Tag/FloatTag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected static function readContentRaw(Reader $reader, TagOptions $options): s
4646
/**
4747
* @inheritDoc
4848
*/
49-
public function setValue(float $value): FloatValueTag
49+
public function setValue(float $value): static
5050
{
5151
$this->resetRawValue();
5252
return parent::setValue($value);

src/Tag/FloatValueTag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function getValue(): float
1818
* @param float $value
1919
* @return $this
2020
*/
21-
public function setValue(float $value): FloatValueTag
21+
public function setValue(float $value): static
2222
{
2323
$this->value = $value;
2424
return $this;

src/Tag/IntValueTag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function getValue(): int
1818
* @param int $value
1919
* @return $this
2020
*/
21-
public function setValue(int $value): IntValueTag
21+
public function setValue(int $value): static
2222
{
2323
$this->value = $value;
2424
return $this;

src/Tag/ListTag.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public function getContentTag(): int
5757

5858
/**
5959
* @param int $contentTagType
60-
* @return ListTag
60+
* @return $this
6161
* @throws Exception
6262
*/
63-
public function setContentTag(int $contentTagType): ListTag
63+
public function setContentTag(int $contentTagType): static
6464
{
6565
if ($this->isRaw()) {
6666
throw new Exception("Raw list tags cannot be modified");
@@ -83,7 +83,7 @@ public function setContentTag(int $contentTagType): ListTag
8383
protected function readValues(Reader $reader, int $length): array
8484
{
8585
$values = [];
86-
/** @var Tag $tagClass */
86+
/** @var class-string<Tag>|null $tagClass */
8787
$tagClass = Tag::getTagClass($this->contentTagType);
8888
if (is_null($tagClass)) {
8989
throw new Exception("Unknown ListTag content type " . $this->contentTagType);
@@ -153,7 +153,7 @@ protected static function readValueTagsRaw(Reader $reader, TagOptions $options,
153153
{
154154
$valueData = "";
155155

156-
/** @var Tag $tagClass */
156+
/** @var class-string<Tag>|null $tagClass */
157157
$tagClass = Tag::getTagClass($contentType);
158158
if (is_null($tagClass)) {
159159
throw new Exception("Unknown ListTag content type " . $contentType);
@@ -198,7 +198,7 @@ public function offsetSet($offset, $value)
198198
throw new Exception("Raw list tags cannot be modified");
199199
}
200200

201-
/** @var Tag $previousValue */
201+
/** @var Tag|null $previousValue */
202202
$previousValue = $this->valueArray[$offset] ?? null;
203203
parent::offsetSet($offset, $value);
204204
$value->setParentTag($this);
@@ -207,14 +207,15 @@ public function offsetSet($offset, $value)
207207

208208
/**
209209
* @inheritDoc
210+
* @throws Exception
210211
*/
211212
public function offsetUnset($offset)
212213
{
213214
if ($this->isRaw()) {
214215
throw new Exception("Raw list tags cannot be modified");
215216
}
216217

217-
/** @var Tag $previousValue */
218+
/** @var Tag|null $previousValue */
218219
$previousValue = $this->valueArray[$offset] ?? null;
219220
$previousValue?->setParentTag(null);
220221
parent::offsetUnset($offset);

src/Tag/LongTag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected static function readContentRaw(Reader $reader, TagOptions $options): s
4848
/**
4949
* @inheritDoc
5050
*/
51-
public function setValue(int $value): IntValueTag
51+
public function setValue(int $value): static
5252
{
5353
$this->resetRawValue();
5454
return parent::setValue($value);

src/Tag/StringTag.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function getValue(): string
2222

2323
/**
2424
* @param string $value
25-
* @return StringTag
25+
* @return $this
2626
*/
27-
public function setValue(string $value): StringTag
27+
public function setValue(string $value): static
2828
{
2929
$this->value = $value;
3030
return $this;

src/Tag/Tag.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ abstract class Tag implements JsonSerializable
1313
{
1414
public const TYPE = -1;
1515

16+
/**
17+
* @var class-string<Tag>[]
18+
*/
1619
public const TAGS = [
1720
TagType::TAG_End => EndTag::class,
1821
TagType::TAG_Byte => ByteTag::class,
@@ -46,7 +49,7 @@ public function __construct(?TagOptions $options = null)
4649
* @param string|null $name
4750
* @return $this
4851
*/
49-
public function setName(?string $name): Tag
52+
public function setName(?string $name): static
5053
{
5154
$this->name = $name;
5255
return $this;
@@ -266,7 +269,7 @@ abstract protected function getValueString(): string;
266269

267270
/**
268271
* @param int $type
269-
* @return string|null
272+
* @return class-string<Tag>|null
270273
*/
271274
public static function getTagClass(int $type): ?string
272275
{

src/Tag/TagOptions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function getRawCompoundPaths(): array
3939

4040
/**
4141
* @param string[]|null $parsedCompoundPaths
42-
* @return TagOptions
42+
* @return $this
4343
*/
44-
public function setParsedCompoundPaths(?array $parsedCompoundPaths): TagOptions
44+
public function setParsedCompoundPaths(?array $parsedCompoundPaths): static
4545
{
4646
$this->parsedCompoundPaths = $parsedCompoundPaths;
4747
return $this;

0 commit comments

Comments
 (0)