Skip to content

Commit c3a90e5

Browse files
committed
feat: Get rid of myclabs/php-enum, switch to native enums
1 parent a842e7b commit c3a90e5

5 files changed

Lines changed: 14 additions & 34 deletions

File tree

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"php": "^8.2",
2929
"ext-json": "*",
3030
"guzzlehttp/guzzle": "^6.3|^7.2",
31-
"myclabs/php-enum": "^1.8",
3231
"psr/log": "^2|^3",
3332
"symfony/validator": "^6.4|^7.0"
3433
},

src/Requests/PostSubscription/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function jsonSerialize(): array
2727
];
2828

2929
if ($this->operator !== null) {
30-
$data['operator'] = $this->operator->getValue();
30+
$data['operator'] = $this->operator->value;
3131
}
3232

3333
return $data;

src/Requests/PostSubscription/FilterOperator.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,11 @@
44

55
namespace Keboola\NotificationClient\Requests\PostSubscription;
66

7-
use DomainException;
8-
use MyCLabs\Enum\Enum;
9-
10-
/**
11-
* @method static self EQUAL()
12-
* @method static self LESS_THAN()
13-
* @method static self GREATER_THAN()
14-
* @method static self LESS_THAN_OR_EQUAL()
15-
* @method static self GREATER_THAN_OR_EQUAL()
16-
*
17-
* @phpstan-extends Enum<string>
18-
*/
19-
class FilterOperator extends Enum
7+
enum FilterOperator: string
208
{
21-
// phpcs:disable SlevomatCodingStandard.Classes.UnusedPrivateElements
22-
// @phpstan-ignore-next-line
23-
private const EQUAL = '=='; // can't be called EQUALS because there is a method called `equals` on base Enum class
24-
// @phpstan-ignore-next-line
25-
private const LESS_THAN = '<';
26-
// @phpstan-ignore-next-line
27-
private const GREATER_THAN = '>';
28-
// @phpstan-ignore-next-line
29-
private const LESS_THAN_OR_EQUAL = '<=';
30-
// @phpstan-ignore-next-line
31-
private const GREATER_THAN_OR_EQUAL = '>=';
32-
// phpcs:enable SlevomatCodingStandard.Classes.UnusedPrivateElements
9+
case Equal = '==';
10+
case LessThan = '<';
11+
case GreaterThan = '>';
12+
case LessThanOrEqual = '<=';
13+
case GreaterThanOrEqual = '>=';
3314
}

tests/Requests/PostSubscription/FilterOperatorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class FilterOperatorTest extends TestCase
1414
*/
1515
public function testOperatorValues(FilterOperator $operator, string $expectedValue): void
1616
{
17-
self::assertSame($expectedValue, $operator->getValue());
17+
self::assertSame($expectedValue, $operator->value);
1818
}
1919

2020
public function provideOperatorValues(): iterable
2121
{
22-
yield 'equals' => [FilterOperator::EQUAL(), '=='];
23-
yield 'less than' => [FilterOperator::LESS_THAN(), '<'];
24-
yield 'greater than' => [FilterOperator::GREATER_THAN(), '>'];
25-
yield 'less than or equals' => [FilterOperator::LESS_THAN_OR_EQUAL(), '<='];
26-
yield 'greater than or equals' => [FilterOperator::GREATER_THAN_OR_EQUAL(), '>='];
22+
yield 'equals' => [FilterOperator::Equal, '=='];
23+
yield 'less than' => [FilterOperator::LessThan, '<'];
24+
yield 'greater than' => [FilterOperator::GreaterThan, '>'];
25+
yield 'less than or equals' => [FilterOperator::LessThanOrEqual, '<='];
26+
yield 'greater than or equals' => [FilterOperator::GreaterThanOrEqual, '>='];
2727
}
2828
}

tests/Requests/PostSubscription/FilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testJsonSerialize(): void
2424

2525
public function testJsonSerializeWithOperator(): void
2626
{
27-
$filter = new Filter('someName', 'someValue', FilterOperator::GREATER_THAN_OR_EQUAL());
27+
$filter = new Filter('someName', 'someValue', FilterOperator::GreaterThanOrEqual);
2828
self::assertSame(
2929
[
3030
'field' => 'someName',

0 commit comments

Comments
 (0)