Skip to content

Commit cf39f5a

Browse files
authored
Merge pull request #1 from Nejcc/dev
Dev
2 parents a99aff0 + 2b94c9c commit cf39f5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+797
-268
lines changed

.idea/php-datatypes.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+68-8
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ This approach has a few key benefits:
5151
### Laravel example
5252

5353
here's how it can be used in practice across different types, focusing on strict handling for both integers and floats:
54+
5455
```php
5556
namespace App\Http\Controllers;
5657

57-
use Illuminate\Http\Request;
58-
use Nejcc\PhpDatatypes\Integers\Unsigned\UInt8;
59-
use Nejcc\PhpDatatypes\Floats\Float32;
58+
use Illuminate\Http\Request;use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32;use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt8;
6059

6160
class TestController
6261
{
@@ -86,9 +85,9 @@ Here, we're not only safeguarding user IDs but also handling potentially complex
8685
PHP examples
8786

8887
### Integers
88+
8989
```php
90-
use Nejcc\PhpDatatypes\Integers\Signed\Int8;
91-
use Nejcc\PhpDatatypes\Integers\Unsigned\UInt8;
90+
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8;use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt8;
9291

9392
$int8 = new Int8(-128); // Minimum value for Int8
9493
echo $int8->getValue(); // -128
@@ -98,9 +97,9 @@ echo $uint8->getValue(); // 255
9897
```
9998

10099
### Floats
100+
101101
```php
102-
use Nejcc\PhpDatatypes\Floats\Float32;
103-
use Nejcc\PhpDatatypes\Floats\Float64;
102+
use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32;use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float64;
104103

105104
$float32 = new Float32(3.14);
106105
echo $float32->getValue(); // 3.14
@@ -110,8 +109,9 @@ echo $float64->getValue(); // 1.7976931348623157e308
110109
```
111110

112111
### Arithmetic Operations
112+
113113
```php
114-
use Nejcc\PhpDatatypes\Integers\Signed\Int8;
114+
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8;
115115

116116
$int1 = new Int8(50);
117117
$int2 = new Int8(30);
@@ -121,6 +121,66 @@ echo $result->getValue(); // 80
121121

122122
```
123123

124+
# ROAD MAP
125+
126+
```md
127+
Data Types
128+
129+
├── Scalar Types
130+
│ ├── Integer Types
131+
│ │ ├── Signed Integers
132+
│ │ │ ├── ✓ Int8
133+
│ │ │ ├── ✓ Int16
134+
│ │ │ ├── ✓ Int32
135+
│ │ │ ├── Int64
136+
│ │ │ └── Int128
137+
│ │ └── Unsigned Integers
138+
│ │ ├── ✓ UInt8
139+
│ │ ├── ✓ UInt16
140+
│ │ ├── ✓ UInt32
141+
│ │ ├── UInt64
142+
│ │ └── UInt128
143+
│ ├── Floating Point Types
144+
│ │ ├── ✓ Float32
145+
│ │ ├── ✓ Float64
146+
│ │ ├── Double
147+
│ │ └── Double Floating Point
148+
│ ├── Boolean
149+
│ │ └── Boolean (true/false)
150+
│ ├── Char
151+
│ └── Byte
152+
153+
├── Composite Types
154+
│ ├── Arrays
155+
│ │ ├── StringArray
156+
│ │ ├── IntArray
157+
│ │ ├── FloatArray
158+
│ │ └── Byte Slice
159+
│ ├── Struct
160+
│ │ └── struct { fields of different types }
161+
│ ├── Union
162+
│ │ └── union { shared memory for different types }
163+
│ ├── List
164+
│ └── Dictionary
165+
166+
├── Reference Types
167+
│ ├── Reference Pointer
168+
│ ├── Void (Nullable)
169+
│ └── Channel (Concurrency)
170+
171+
├── Map Types
172+
│ ├── Hashmap
173+
│ └── Map
174+
175+
└── Specialized Types
176+
├── String
177+
├── Double
178+
├── Slice
179+
├── Map
180+
└── Channel
181+
```
182+
183+
124184
### Testing
125185

126186
```bash

tests/Floats/Float32Test.php renamed to Tests/Floats/Float32Test.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22

33
declare(strict_types=1);
44

5-
namespace Nejcc\PhpDatatypes\Tests;
5+
namespace Nejcc\PhpDatatypes\Tests\Floats;
66

7-
use Nejcc\PhpDatatypes\Floats\Float32;
7+
use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float32;
88
use PHPUnit\Framework\TestCase;
99

1010
final class Float32Test extends TestCase
1111
{
1212
public function testSetAndGetValue(): void
1313
{
14-
$float = new Float32(1.234567e10);
14+
$float = float32(1.234567e10);
1515
$this->assertEquals(1.234567e10, $float->getValue());
1616
}
1717

1818
public function testOutOfRangeException(): void
1919
{
20+
// Expect the exception to be thrown before the code that triggers it.
2021
$this->expectException(\OutOfRangeException::class);
21-
new Float32(4.0e38); // Value out of Float32 range
22+
23+
// Now trigger the exception with an out-of-range value.
24+
\float32(4.0e38); // This value is beyond Float32's range.
2225
}
26+
2327
}

tests/Floats/Float64Test.php renamed to Tests/Floats/Float64Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Nejcc\PhpDatatypes\Tests;
66

7-
use Nejcc\PhpDatatypes\Floats\Float64;
7+
use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float64;
88
use PHPUnit\Framework\TestCase;
99

1010
final class Float64Test extends TestCase

tests/Integers/Signed/Int16Test.php renamed to Tests/Integers/Signed/Int16Test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Nejcc\PhpDatatypes\Tests\Integers\Signed;
66

7-
use Nejcc\PhpDatatypes\Integers\Signed\Int16;
8-
use Nejcc\PhpDatatypes\Interfaces\IntegerInterface;
7+
8+
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16;
99
use PHPUnit\Framework\TestCase;
1010

1111
class Int16Test extends TestCase

tests/Integers/Signed/Int32Test.php renamed to Tests/Integers/Signed/Int32Test.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Nejcc\PhpDatatypes\Tests\Integers\Signed;
66

7-
use Nejcc\PhpDatatypes\Integers\Signed\Int32;
8-
use Nejcc\PhpDatatypes\Interfaces\IntegerInterface;
7+
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int32;
98
use PHPUnit\Framework\TestCase;
109

1110
class Int32Test extends TestCase

tests/Integers/Signed/Int8Test.php renamed to Tests/Integers/Signed/Int8Test.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Nejcc\PhpDatatypes\Tests\Integers\Signed;
66

7-
use Nejcc\PhpDatatypes\Integers\Signed\Int8;
8-
use Nejcc\PhpDatatypes\Interfaces\IntegerInterface;
7+
8+
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8;
99
use PHPUnit\Framework\TestCase;
1010

1111
class Int8Test extends TestCase
@@ -24,7 +24,7 @@ public function testInvalidInitialization()
2424

2525
public function testAdditionWithinBounds()
2626
{
27-
$int8a = new Int8(50);
27+
$int8a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(50);
2828
$int8b = new Int8(77);
2929
$int8c = $int8a->add($int8b);
3030
$this->assertSame(127, $int8c->getValue());
@@ -34,14 +34,14 @@ public function testAdditionOverflow()
3434
{
3535
$this->expectException(\OverflowException::class);
3636
$int8a = new Int8(100);
37-
$int8b = new Int8(50);
37+
$int8b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(50);
3838
$int8a->add($int8b);
3939
}
4040

4141
public function testSubtractionWithinBounds()
4242
{
43-
$int8a = new Int8(-50);
44-
$int8b = new Int8(-77);
43+
$int8a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(-50);
44+
$int8b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(-77);
4545
$int8c = $int8a->subtract($int8b);
4646
$this->assertSame(27, $int8c->getValue());
4747
}
@@ -56,17 +56,17 @@ public function testSubtractionUnderflow()
5656

5757
public function testMultiplicationWithinBounds()
5858
{
59-
$int8a = new Int8(10);
60-
$int8b = new Int8(12);
59+
$int8a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(10);
60+
$int8b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(12);
6161
$int8c = $int8a->multiply($int8b);
6262
$this->assertSame(120, $int8c->getValue());
6363
}
6464

6565
public function testMultiplicationOverflow()
6666
{
6767
$this->expectException(\OverflowException::class);
68-
$int8a = new Int8(16);
69-
$int8b = new Int8(8);
68+
$int8a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(16);
69+
$int8b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(8);
7070
$int8a->multiply($int8b);
7171
}
7272

@@ -81,22 +81,22 @@ public function testDivisionWithinBounds()
8181
public function testDivisionByZero()
8282
{
8383
$this->expectException(\DivisionByZeroError::class);
84-
$int8a = new Int8(100);
85-
$int8b = new Int8(0);
84+
$int8a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(100);
85+
$int8b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(0);
8686
$int8a->divide($int8b);
8787
}
8888

8989
public function testDivisionResultNotInteger()
9090
{
9191
$this->expectException(\UnexpectedValueException::class);
92-
$int8a = new Int8(5);
93-
$int8b = new Int8(2);
92+
$int8a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(5);
93+
$int8b = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(2);
9494
$int8a->divide($int8b);
9595
}
9696

9797
public function testModulusWithinBounds()
9898
{
99-
$int8a = new Int8(100);
99+
$int8a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(100);
100100
$int8b = new Int8(30);
101101
$int8c = $int8a->mod($int8b);
102102
$this->assertSame(10, $int8c->getValue());
@@ -111,7 +111,7 @@ public function testEquality()
111111

112112
public function testInequality()
113113
{
114-
$int8a = new Int8(50);
114+
$int8a = new \Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8(50);
115115
$int8b = new Int8(60);
116116
$this->assertFalse($int8a->equals($int8b));
117117
}

tests/Integers/Unsigned/UInt16Test.php renamed to Tests/Integers/Unsigned/UInt16Test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Nejcc\PhpDatatypes\Tests\Integers\Unsigned;
66

7-
use Nejcc\PhpDatatypes\Integers\Unsigned\UInt16;
7+
use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt16;
88
use PHPUnit\Framework\TestCase;
99

1010
class UInt16Test extends TestCase
@@ -55,7 +55,7 @@ public function testSubtractionUnderflow()
5555

5656
public function testMultiplicationWithinBounds()
5757
{
58-
$uint16a = new UInt16(3000);
58+
$uint16a = new \Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt16(3000);
5959
$uint16b = new UInt16(20);
6060
$uint16c = $uint16a->multiply($uint16b);
6161
$this->assertSame(60000, $uint16c->getValue());

0 commit comments

Comments
 (0)