Skip to content

Commit 4b8f7ee

Browse files
committed
Updated readme.
1 parent 0e2d391 commit 4b8f7ee

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Mapper
66
[![Test coverage][Coverage image]][Coverage]
77
[![Code style][Style image]][Style]
88

9-
Mapper transforms arrays from one format to another using an object composition DSL. An application often receives data from a foreign source structured differently than it wants. We can use Mapper to transform data into a more suitable format by using a `Mapping` as shown in the following example.
9+
Mapper transforms arrays from one format to another using an object composition DSL. An application often receives data from a foreign source structured differently than it wants. We can use Mapper to transform foreign data into a more suitable format for our application using a `Mapping` as shown in the following example.
1010

1111
```php
1212
$mappedData = (new Mapper)->map($data, new MyMapping);
@@ -39,7 +39,7 @@ $barData = (new Mapper)->map($fooData, new FooToBarMapping);
3939

4040
> ['bar' => 123]
4141
42-
In this example we declare a mapping, `FooToBarMapping`, and pass it to the `Mapper::map` method to transform `$fooData` into `$barData`.
42+
In this example we declare a mapping, `FooToBarMapping`, and pass it to the `Mapper::map` method to transform `$fooData` into `$barData`. As mentioned, this is just a contrived example to demonstrate how Mapper works; one may like to see a more [practical example](#practical-example).
4343

4444
This mapping introduces the `Copy` strategy that copies a value from the input data to the output. Strategies are just one type of *expression* we can specify as mapping values.
4545

@@ -105,7 +105,7 @@ It is recommended to name custom strategies with a *Strategy* suffix to help dis
105105

106106
## Practical example
107107

108-
Suppose we receive two different address formats from two different third-party providers. The first provider, FooBook, provides a single UK addresses. The second provider, BarBucket, provides a collection of US addresses. We are tasked with converting both types to the same uniform address format for our application using mappings. Sample data from each provider is shown below.
108+
Suppose we receive two different postal address formats from two different third-party providers. The first provider, FooBook, provides a single UK addresses. The second provider, BarBucket, provides a collection of US addresses. We are tasked with converting both types to the same uniform address format for our application using mappings.
109109

110110
The address format for our application must be a flat array with the following fields.
111111

@@ -115,7 +115,7 @@ The address format for our application must be a flat array with the following f
115115
* postcode
116116
* country
117117

118-
### FooBook
118+
### FooBook address mapping
119119

120120
A sample of the data we receive from FooBook is shown below.
121121

@@ -167,7 +167,7 @@ $address = (new Mapper)->map($fooBookAddress, new FooBookAddressToAddresesMappin
167167
]
168168
```
169169

170-
### BarBucket
170+
### BarBucket address mapping
171171

172172
A sample of the data we receive from BarBucket is show below.
173173

@@ -702,19 +702,19 @@ Requirements
702702
- [PHP 5.5](http://php.net/)
703703
- [Composer](https://getcomposer.org/)
704704

705-
Testing
706-
-------
707-
708-
Mapper is fully unit tested. Run the tests with `bin/test` from a shell. All examples
709-
in this document can be found in `DocumentationTest`.
710-
711705
Limitations
712706
-----------
713707

714708
- Strategies do not know the name of the key they are assigned to because `Mapper` does not forward the key name.
715709
- Strategies do not know where they sit in a `Mapping` and therefore cannot traverse a mapping relative to their position.
716710
- The `Collection` strategy overwrites context making any previous context inaccessible to descendants.
717711

712+
Testing
713+
-------
714+
715+
Mapper is fully unit tested. Run the tests with `bin/test` from a shell. All examples
716+
in this document can be found in `DocumentationTest`.
717+
718718

719719
[Releases]: https://github.com/ScriptFUSION/Mapper/releases
720720
[Version image]: https://poser.pugx.org/scriptfusion/mapper/version "Latest version"

0 commit comments

Comments
 (0)