Skip to content

Commit

Permalink
Added PHP 8.4 compatibility.
Browse files Browse the repository at this point in the history
BC: Changed DataType from AbstractEnumeration -> native enum.
  • Loading branch information
Bilge committed Nov 25, 2024
1 parent dafee01 commit 45aa554
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4
dependencies:
- hi
- lo
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ Type(DataType $type, Strategy $strategy)
#### Example

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

> '123'
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"license": "LGPL-3.0",
"require": {
"php": "^8.1",
"scriptfusion/array-walker": "^1",
"eloquent/enumeration": "^5|^6"
"scriptfusion/array-walker": "^1"
},
"require-dev": {
"scriptfusion/static-class": "^1",
Expand Down
26 changes: 7 additions & 19 deletions src/DataType.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
<?php
namespace ScriptFUSION\Mapper;

use Eloquent\Enumeration\AbstractEnumeration;

/**
* Specifies a PHP data type.
*
* @method static self BOOLEAN
* @method static self INTEGER
* @method static self FLOAT
* @method static self STRING
* @method static self MAP
* @method static self OBJECT
*/
final class DataType extends AbstractEnumeration
enum DataType
{
const BOOLEAN = 'boolean';
const INTEGER = 'integer';
const FLOAT = 'float';
const STRING = 'string';
const MAP = 'array';
const OBJECT = 'object';
case Boolean;
case Integer;
case Float;
case String;
case Array;
case Object;
}
2 changes: 1 addition & 1 deletion src/Strategy/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __invoke($data, $context = null)
* "resource". Since the enumeration guarantees valid type specifiers
* this function call never returns false, so we do not check it.
*/
settype($data, "$this->type");
settype($data, $this->type->name);

return $data;
}
Expand Down
2 changes: 1 addition & 1 deletion test/Functional/DocumentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function testType()
{
self::assertSame(
'123',
(new Mapper)->map(['foo' => 123], new Type(DataType::STRING(), new Copy('foo')))
(new Mapper)->map(['foo' => 123], new Type(DataType::String, new Copy('foo')))
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Mapper/Strategy/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class TypeTest extends TestCase

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

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

0 comments on commit 45aa554

Please sign in to comment.