Skip to content

Commit 45aa554

Browse files
committed
Added PHP 8.4 compatibility.
BC: Changed DataType from AbstractEnumeration -> native enum.
1 parent dafee01 commit 45aa554

File tree

7 files changed

+13
-25
lines changed

7 files changed

+13
-25
lines changed

.github/workflows/Tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- 8.1
1919
- 8.2
2020
- 8.3
21+
- 8.4
2122
dependencies:
2223
- hi
2324
- lo

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ Type(DataType $type, Strategy $strategy)
897897
#### Example
898898

899899
```php
900-
(new Mapper)->map(['foo' => 123], new Type(DataType::STRING(), new Copy('foo')));
900+
(new Mapper)->map(['foo' => 123], new Type(DataType::String, new Copy('foo')));
901901
```
902902

903903
> '123'

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"license": "LGPL-3.0",
1111
"require": {
1212
"php": "^8.1",
13-
"scriptfusion/array-walker": "^1",
14-
"eloquent/enumeration": "^5|^6"
13+
"scriptfusion/array-walker": "^1"
1514
},
1615
"require-dev": {
1716
"scriptfusion/static-class": "^1",

src/DataType.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
<?php
22
namespace ScriptFUSION\Mapper;
33

4-
use Eloquent\Enumeration\AbstractEnumeration;
5-
6-
/**
7-
* Specifies a PHP data type.
8-
*
9-
* @method static self BOOLEAN
10-
* @method static self INTEGER
11-
* @method static self FLOAT
12-
* @method static self STRING
13-
* @method static self MAP
14-
* @method static self OBJECT
15-
*/
16-
final class DataType extends AbstractEnumeration
4+
enum DataType
175
{
18-
const BOOLEAN = 'boolean';
19-
const INTEGER = 'integer';
20-
const FLOAT = 'float';
21-
const STRING = 'string';
22-
const MAP = 'array';
23-
const OBJECT = 'object';
6+
case Boolean;
7+
case Integer;
8+
case Float;
9+
case String;
10+
case Array;
11+
case Object;
2412
}

src/Strategy/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __invoke($data, $context = null)
3030
* "resource". Since the enumeration guarantees valid type specifiers
3131
* this function call never returns false, so we do not check it.
3232
*/
33-
settype($data, "$this->type");
33+
settype($data, $this->type->name);
3434

3535
return $data;
3636
}

test/Functional/DocumentationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public function testType()
390390
{
391391
self::assertSame(
392392
'123',
393-
(new Mapper)->map(['foo' => 123], new Type(DataType::STRING(), new Copy('foo')))
393+
(new Mapper)->map(['foo' => 123], new Type(DataType::String, new Copy('foo')))
394394
);
395395
}
396396

test/Unit/Mapper/Strategy/TypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class TypeTest extends TestCase
1414

1515
public function test()
1616
{
17-
$type = new Type(DataType::INTEGER(), \Mockery::mock(Strategy::class));
17+
$type = new Type(DataType::Integer, \Mockery::mock(Strategy::class));
1818
$type->setMapper(MockFactory::mockMapper('123'));
1919

2020
self::assertSame(123, $type([]));

0 commit comments

Comments
 (0)