Skip to content

Commit 7a63162

Browse files
authored
Merge pull request #3 from stagerightlabs/rename_xdr_array_length_method
Rename XdrArray length method
2 parents e918b3e + fefea31 commit 7a63162

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to `phpxdr` will be documented in this file
44

5+
## 0.0.10 - 2022-01-03
6+
7+
### Changed
8+
9+
- The `getXdrFixedCount()` method in the `XdrArray` interface has been renamed to `getXdrLength()` which should hopefully be more clear.
10+
511
## 0.0.9 - 2022-01-01
612

713
### Changed

src/Interfaces/XdrArray.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ interface XdrArray
1919
public function getXdrArray(): array;
2020

2121
/**
22-
* If this class is modeling a fixed length array, this method defines
23-
* the number of elements the array is expected to contain. This will
24-
* be null for variable length arrays.
22+
* If this class is modeling a fixed length array use this method
23+
* to define the number of elements the array is expected to
24+
* contain. This will be null for variable length arrays.
2525
*
2626
* @return integer
2727
*/
28-
public static function getXdrFixedCount(): ?int;
28+
public static function getXdrLength(): ?int;
2929

3030
/**
3131
* XDR arrays must be composed entirely of the same type. This method
@@ -36,8 +36,7 @@ public static function getXdrFixedCount(): ?int;
3636
public static function getXdrType(): string;
3737

3838
/**
39-
* If the underlying content type requires a length it can be specified
40-
* with this method.
39+
* Specify the length of the underlying value type, if required.
4140
*
4241
* @return integer|null
4342
*/

src/Read.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public function read(string $type, ?string $vessel = null, ?int $length = null)
3838
}
3939

4040
// Can we infer that this is a fixed length array?
41-
if (class_exists($type) && $this->isInstanceOf($type, XdrArray::class) && $type::getXdrFixedCount()) {
41+
if (class_exists($type) && $this->isInstanceOf($type, XdrArray::class) && $type::getXdrLength()) {
4242
return $this->readArrayFixed($type, $length);
4343
}
4444

4545
// Can we infer that this is a variable length array?
46-
if (class_exists($type) && $this->isInstanceOf($type, XdrArray::class) && !$type::getXdrFixedCount()) {
46+
if (class_exists($type) && $this->isInstanceOf($type, XdrArray::class) && !$type::getXdrLength()) {
4747
return $this->readArrayVariable($type);
4848
}
4949

@@ -359,7 +359,7 @@ protected function readArrayFixed(string|null $vessel, int $length = null): XdrA
359359
}
360360

361361
// Determine the number of elements in our fixed length array
362-
$length = $length ?? $vessel::getXdrFixedCount();
362+
$length = $length ?? $vessel::getXdrLength();
363363
if (!$length) {
364364
throw new InvalidArgumentException('Attempting to decode a fixed length array with no specified length');
365365
}

src/Write.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public function write($value, $type = null, $length = null)
3838
}
3939

4040
// Can we infer that this is a fixed array?
41-
if ($value instanceof XdrArray && $value->getXdrFixedCount()) {
42-
return $this->writeArrayFixed($value, $value->getXdrFixedCount());
41+
if ($value instanceof XdrArray && $value->getXdrLength()) {
42+
return $this->writeArrayFixed($value, $value->getXdrLength());
4343
}
4444

4545
// Can we infer that this is a variable length array?
46-
if ($value instanceof XdrArray && !$value->getXdrFixedCount()) {
46+
if ($value instanceof XdrArray && !$value->getXdrLength()) {
4747
return $this->writeArrayVariable($value);
4848
}
4949

@@ -356,7 +356,7 @@ protected function writeString(string $value): self
356356
*/
357357
protected function writeArrayFixed(XdrArray $value, $length = null): self
358358
{
359-
$count = $length ?? $value->getXdrFixedCount();
359+
$count = $length ?? $value->getXdrLength();
360360
if (!$count) {
361361
throw new InvalidArgumentException('You must specify a length to encode a fixed array.');
362362
}

tests/ArrayFixedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getXdrArray(): array
6464
return $this->arr;
6565
}
6666

67-
public static function getXdrFixedCount(): ?int
67+
public static function getXdrLength(): ?int
6868
{
6969
return 2;
7070
}

tests/ArrayVariableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getXdrArray(): array
6464
return $this->arr;
6565
}
6666

67-
public static function getXdrFixedCount(): ?int
67+
public static function getXdrLength(): ?int
6868
{
6969
return null;
7070
}

0 commit comments

Comments
 (0)