Skip to content

Commit 5956eb1

Browse files
committed
update docs
1 parent d7dd201 commit 5956eb1

File tree

9 files changed

+199
-14
lines changed

9 files changed

+199
-14
lines changed

src/Abstract/AbstractBigInteger.php

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,31 @@
1414
*
1515
* @package Nejcc\PhpDatatypes\Integers
1616
*/
17-
abstract class AbstractBigInteger implements BigIntegerInterface, NativeIntegerInterface
17+
abstract class AbstractBigInteger implements BigIntegerInterface
1818
{
1919
use ArithmeticOperationsTrait;
2020
use IntegerComparisonTrait;
2121

22+
/**
23+
* @var string
24+
*/
2225
protected readonly string $value;
2326

2427
public const MIN_VALUE = null;
2528
public const MAX_VALUE = null;
2629

30+
/**
31+
* @param int|string $value
32+
*/
2733
public function __construct(int|string $value)
2834
{
2935
$this->setValue($value);
3036
}
3137

38+
/**
39+
* @param int|string $value
40+
* @return void
41+
*/
3242
protected function setValue(int|string $value): void
3343
{
3444
$valueStr = (string)$value;
@@ -44,18 +54,30 @@ protected function setValue(int|string $value): void
4454
$this->value = $valueStr;
4555
}
4656

57+
/**
58+
* @return string
59+
*/
4760
public function getValue(): string
4861
{
4962
return $this->value;
5063
}
5164

52-
// Implement comparison method
65+
/**
66+
* @param NativeIntegerInterface|BigIntegerInterface $other
67+
* @return int
68+
*/
5369
public function compare(NativeIntegerInterface|BigIntegerInterface $other): int
5470
{
5571
return bccomp($this->value, (string)$other->getValue());
5672
}
5773

58-
// Implement operation methods required by the trait
74+
75+
/**
76+
* @param BigIntegerInterface|NativeIntegerInterface $other
77+
* @param callable $operation
78+
* @param string $operationName
79+
* @return $this
80+
*/
5981
protected function performOperation(
6082
BigIntegerInterface|NativeIntegerInterface $other,
6183
callable $operation,
@@ -71,21 +93,41 @@ protected function performOperation(
7193
return new static($result);
7294
}
7395

96+
/**
97+
* @param string $a
98+
* @param string $b
99+
* @return string
100+
*/
74101
protected function addValues(string $a, string $b): string
75102
{
76103
return bcadd($a, $b, 0);
77104
}
78105

106+
/**
107+
* @param string $a
108+
* @param string $b
109+
* @return string
110+
*/
79111
protected function subtractValues(string $a, string $b): string
80112
{
81113
return bcsub($a, $b, 0);
82114
}
83115

116+
/**
117+
* @param string $a
118+
* @param string $b
119+
* @return string
120+
*/
84121
protected function multiplyValues(string $a, string $b): string
85122
{
86123
return bcmul($a, $b, 0);
87124
}
88125

126+
/**
127+
* @param string $a
128+
* @param string $b
129+
* @return string
130+
*/
89131
protected function divideValues(string $a, string $b): string
90132
{
91133
if ($b === '0') {
@@ -101,6 +143,11 @@ protected function divideValues(string $a, string $b): string
101143
return $result;
102144
}
103145

146+
/**
147+
* @param string $a
148+
* @param string $b
149+
* @return string
150+
*/
104151
protected function modValues(string $a, string $b): string
105152
{
106153
if ($b === '0') {

src/Abstract/AbstractFloat.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@
88

99
abstract class AbstractFloat
1010
{
11+
/**
12+
* @var float
13+
*/
1114
protected readonly float $value;
1215

1316
public const MIN_VALUE = null;
1417
public const MAX_VALUE = null;
1518

19+
/**
20+
* @param float $value
21+
*/
1622
public function __construct(float $value)
1723
{
1824
$this->setValue($value);
1925
}
2026

27+
/**
28+
* @param float $value
29+
* @return void
30+
*/
2131
protected function setValue(float $value): void
2232
{
2333
// Check if value is out of range
@@ -33,6 +43,9 @@ protected function setValue(float $value): void
3343
$this->value = $value;
3444
}
3545

46+
/**
47+
* @return float
48+
*/
3649
public function getValue(): float
3750
{
3851
return $this->value;

src/Abstract/AbstractNativeInteger.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ abstract class AbstractNativeInteger implements NativeIntegerInterface
2323
public const MIN_VALUE = null;
2424
public const MAX_VALUE = null;
2525

26+
/**
27+
* @param int $value
28+
*/
2629
public function __construct(int $value)
2730
{
2831
$this->setValue($value);
2932
}
3033

34+
/**
35+
* @param int $value
36+
* @return void
37+
*/
3138
protected function setValue(int $value): void
3239
{
3340
if ($value < static::MIN_VALUE || $value > static::MAX_VALUE) {
@@ -41,16 +48,29 @@ protected function setValue(int $value): void
4148
$this->value = $value;
4249
}
4350

51+
/**
52+
* @return int
53+
*/
4454
public function getValue(): int
4555
{
4656
return $this->value;
4757
}
4858

59+
/**
60+
* @param NativeIntegerInterface $other
61+
* @return int
62+
*/
4963
public function compare(NativeIntegerInterface $other): int
5064
{
5165
return $this->value <=> $other->getValue();
5266
}
5367

68+
/**
69+
* @param NativeIntegerInterface $other
70+
* @param callable $operation
71+
* @param string $operationName
72+
* @return $this
73+
*/
5474
protected function performOperation(
5575
NativeIntegerInterface $other,
5676
callable $operation,
@@ -66,21 +86,41 @@ protected function performOperation(
6686
return new static($result);
6787
}
6888

89+
/**
90+
* @param int $a
91+
* @param int $b
92+
* @return int
93+
*/
6994
protected function addValues(int $a, int $b): int
7095
{
7196
return $a + $b;
7297
}
7398

99+
/**
100+
* @param int $a
101+
* @param int $b
102+
* @return int
103+
*/
74104
protected function subtractValues(int $a, int $b): int
75105
{
76106
return $a - $b;
77107
}
78108

109+
/**
110+
* @param int $a
111+
* @param int $b
112+
* @return int
113+
*/
79114
protected function multiplyValues(int $a, int $b): int
80115
{
81116
return $a * $b;
82117
}
83118

119+
/**
120+
* @param int $a
121+
* @param int $b
122+
* @return int
123+
*/
84124
protected function divideValues(int $a, int $b): int
85125
{
86126
if ($b === 0) {
@@ -94,6 +134,11 @@ protected function divideValues(int $a, int $b): int
94134
return intdiv($a, $b);
95135
}
96136

137+
/**
138+
* @param int $a
139+
* @param int $b
140+
* @return int
141+
*/
97142
protected function modValues(int $a, int $b): int
98143
{
99144
if ($b === 0) {

src/Integers/Signed/Int32.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@ final class Int32 extends AbstractNativeInteger
2626
* @var int
2727
*/
2828
public const MAX_VALUE = 2147483647;
29-
30-
// Inherit methods from AbstractInteger.
3129
}

src/Interfaces/BigIntegerInterface.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,50 @@
1111
*/
1212
interface BigIntegerInterface
1313
{
14+
/**
15+
* @return string
16+
*/
1417
public function getValue(): string;
1518

19+
/**
20+
* @param BigIntegerInterface $other
21+
* @return $this
22+
*/
1623
public function add(BigIntegerInterface $other): static;
1724

25+
/**
26+
* @param BigIntegerInterface $other
27+
* @return $this
28+
*/
1829
public function subtract(BigIntegerInterface $other): static;
1930

31+
/**
32+
* @param BigIntegerInterface $other
33+
* @return $this
34+
*/
2035
public function multiply(BigIntegerInterface $other): static;
2136

37+
/**
38+
* @param BigIntegerInterface $other
39+
* @return $this
40+
*/
2241
public function divide(BigIntegerInterface $other): static;
2342

43+
/**
44+
* @param BigIntegerInterface $other
45+
* @return $this
46+
*/
2447
public function mod(BigIntegerInterface $other): static;
2548

49+
/**
50+
* @param BigIntegerInterface $other
51+
* @return bool
52+
*/
2653
public function equals(BigIntegerInterface $other): bool;
2754

55+
/**
56+
* @param BigIntegerInterface $other
57+
* @return int
58+
*/
2859
public function compare(BigIntegerInterface $other): int;
2960
}

src/Interfaces/FloatInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
interface FloatInterface
66
{
7+
/**
8+
* @return float
9+
*/
710
public function getValue(): float;
8-
911
}

src/Interfaces/NativeIntegerInterface.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,50 @@
1111
*/
1212
interface NativeIntegerInterface
1313
{
14+
/**
15+
* @return int
16+
*/
1417
public function getValue(): int;
1518

19+
/**
20+
* @param NativeIntegerInterface $other
21+
* @return $this
22+
*/
1623
public function add(NativeIntegerInterface $other): static;
1724

25+
/**
26+
* @param NativeIntegerInterface $other
27+
* @return $this
28+
*/
1829
public function subtract(NativeIntegerInterface $other): static;
1930

31+
/**
32+
* @param NativeIntegerInterface $other
33+
* @return $this
34+
*/
2035
public function multiply(NativeIntegerInterface $other): static;
2136

37+
/**
38+
* @param NativeIntegerInterface $other
39+
* @return $this
40+
*/
2241
public function divide(NativeIntegerInterface $other): static;
2342

43+
/**
44+
* @param NativeIntegerInterface $other
45+
* @return $this
46+
*/
2447
public function mod(NativeIntegerInterface $other): static;
2548

49+
/**
50+
* @param NativeIntegerInterface $other
51+
* @return bool
52+
*/
2653
public function equals(NativeIntegerInterface $other): bool;
2754

55+
/**
56+
* @param NativeIntegerInterface $other
57+
* @return int
58+
*/
2859
public function compare(NativeIntegerInterface $other): int;
2960
}

src/PhpDatatypes.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)