Commit 5d77ca35 authored by Jan Kuchař's avatar Jan Kuchař

grammar

parent 946d70e6
Pipeline #14378 passed with stages
in 1 minute and 9 seconds
...@@ -87,7 +87,7 @@ $monday->process(DayOfWeek::TUESDAY()); ...@@ -87,7 +87,7 @@ $monday->process(DayOfWeek::TUESDAY());
### Migrating from class constants ### Migrating from class constants
This guide show how to migrate from classes with constants to `\Grifart\Enum` with ease. [Continue to example](tests/Example/MigratingLegacyCode/readme.md) This guide show how to migrate from classes with constants to `\Grifart\Enum` in few simple steps. [Continue to example](tests/Example/MigratingLegacyCode/readme.md)
### Adding behaviour to values ### Adding behaviour to values
...@@ -116,11 +116,11 @@ function nextDay(DayOfWeek $dayOfWeek): DayOfWeek ...@@ -116,11 +116,11 @@ function nextDay(DayOfWeek $dayOfWeek): DayOfWeek
case DayOfWeek::MONDAY(): case DayOfWeek::MONDAY():
return DayOfWeek::TUESDAY(); return DayOfWeek::TUESDAY();
case DayOfWeek::TUESDAY(): case DayOfWeek::TUESDAY():
// ... // ...
} }
throw new ShouldNotHappenException(); throw new ShouldNotHappenException();
} }
$tuesday = nextDay($monday); $tuesday = nextDay($monday);
......
...@@ -34,7 +34,7 @@ This is done by ...@@ -34,7 +34,7 @@ This is done by
- by automatically implementing enum values by including `use \Grifart\Enum\AutoInstances;` trait - by automatically implementing enum values by including `use \Grifart\Enum\AutoInstances;` trait
- and by adding magic methods annotations - and by adding magic methods annotations
When you do this there is not backward incompatible change introduced. But... Now you can use new API. There is not backward incompatible change introduced. And now you can use new APIs!
```php ```php
...@@ -49,7 +49,7 @@ class OrderState extends \Grifart\Enum\Enum { ...@@ -49,7 +49,7 @@ class OrderState extends \Grifart\Enum\Enum {
} }
``` ```
## Step 2: Migrating code and discontinuing old API [[source](step2.phpt)] ## Step 2: Migrating existing code to new API [[source](step2.phpt)]
Migrating old code to new API is usually easy, just add parenthesis `()` when you access value. Migrating old code to new API is usually easy, just add parenthesis `()` when you access value.
...@@ -72,6 +72,8 @@ Assert::same('new', $result); ...@@ -72,6 +72,8 @@ Assert::same('new', $result);
Please note, that you will need to handle some cases manually as `OrderState::NEW()` returns object, enum instance, not a string. Please note, that you will need to handle some cases manually as `OrderState::NEW()` returns object, enum instance, not a string.
#### Removing old API
So when you are finally ready to remove old API, just change constant visibility to `private`. So when you are finally ready to remove old API, just change constant visibility to `private`.
```php ```php
...@@ -86,8 +88,8 @@ class OrderState extends \Grifart\Enum\Enum { ...@@ -86,8 +88,8 @@ class OrderState extends \Grifart\Enum\Enum {
} }
``` ```
# Step 3: Enjoy new features [[source](step3.phpt)] ## Step 3: Enjoy new features [[source](step3.phpt)]
Now, when you decide that you what to move your business logic into enum, you are free to do so. Or you can split logic using composition. Now, when you decided that you what to move your business logic inside enum declaration. You are now free to do so. And there are many more options, see other examples.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment