Skip to content

Commit 7f228c6

Browse files
Consts replaced to the enums
1 parent 8cbe2ce commit 7f228c6

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/Formatters/Plain.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace Differ\Formatters\Plain;
44

5-
const ADD_MARKER = 'added';
6-
const REMOVE_MARKER = 'removed';
7-
const UPDATED_MARKER = 'updated';
5+
enum Marker: string
6+
{
7+
case ADD = 'added';
8+
case REMOVE = 'removed';
9+
case UPDATE = 'updated';
10+
}
811

912
function plain(array $tree, string $path = '', int $depth = 1): string
1013
{
@@ -16,9 +19,9 @@ function ($acc, $key) use ($tree, $path, $depth) {
1619
$newPath = $depth === 1 ? $key : "{$path}.{$key}";
1720
$resultString = $acc;
1821

19-
$addMarker = ADD_MARKER;
20-
$removeMarker = REMOVE_MARKER;
21-
$updatedMarker = UPDATED_MARKER;
22+
$addMarker = Marker::ADD->value;
23+
$removeMarker = Marker::REMOVE->value;
24+
$updatedMarker = Marker::UPDATE->value;
2225

2326
if ($status === 'unchanged') {
2427
return $resultString;

src/Formatters/Stylish.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace Differ\Formatters\Stylish;
44

5-
const ADD_MARKER = '+';
6-
const REMOVE_MARKER = '-';
7-
const UNCHANGED_MARKER = ' ';
5+
enum Marker: string
6+
{
7+
case ADD = '+';
8+
case REMOVE = '-';
9+
case UNCHANGED = ' ';
10+
}
811

912
function stylish(array $tree, string $replacer = ' ', int $spacesCount = 4): string
1013
{
@@ -22,9 +25,9 @@ function ($acc, $key) use ($tree, $replacer, $spacesCount, $depth) {
2225
$resultString = $acc;
2326

2427
$status = match ($statusName) {
25-
'add' => ADD_MARKER,
26-
'remove' => REMOVE_MARKER,
27-
default => UNCHANGED_MARKER
28+
'add' => Marker::ADD->value,
29+
'remove' => Marker::REMOVE->value,
30+
default => Marker::UNCHANGED->value
2831
};
2932

3033
$indentationCount = $spacesCount * $depth - 2;
@@ -33,7 +36,7 @@ function ($acc, $key) use ($tree, $replacer, $spacesCount, $depth) {
3336
if (array_key_exists('children', $keyData)) {
3437
$value = $keyData['children'];
3538

36-
if ($status === ADD_MARKER) {
39+
if ($status === Marker::ADD->value) {
3740
$innerContent = getArrayContent($value, $replacer, $spacesCount, $depth + 1);
3841
$string = getStylishInnerContent($status, $key, $innerContent, $indentation);
3942
return "{$resultString}{$string}";
@@ -58,14 +61,14 @@ function ($acc, $key) use ($tree, $replacer, $spacesCount, $depth) {
5861
];
5962

6063
$stringBefore = getChangedString(
61-
REMOVE_MARKER,
64+
Marker::REMOVE->value,
6265
$keyData['beforeValue'],
6366
$key,
6467
$data
6568
);
6669

6770
$stringAfter = getChangedString(
68-
ADD_MARKER,
71+
Marker::ADD->value,
6972
$keyData['afterValue'],
7073
$key,
7174
$data
@@ -86,13 +89,13 @@ function getArrayContent(array $tree, string $replacer, int $spacesCount, int $d
8689

8790
if (array_key_exists('value', $tree[$key])) {
8891
$value = $tree[$key]['value'];
89-
$string = getStylishString(UNCHANGED_MARKER, $key, $value, $indentation);
92+
$string = getStylishString(Marker::UNCHANGED->value, $key, $value, $indentation);
9093
return "{$resultString}{$string}";
9194
}
9295

9396
$value = $tree[$key]['children'];
9497
$innerContent = getArrayContent($value, $replacer, $spacesCount, $depth + 1);
95-
return getStylishInnerContent(UNCHANGED_MARKER, $key, $innerContent, $indentation);
98+
return getStylishInnerContent(Marker::UNCHANGED->value, $key, $innerContent, $indentation);
9699
}, '');
97100
}
98101

0 commit comments

Comments
 (0)