| Total Complexity | 9 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class ObjectMapper extends AbstractPropertyMapper |
||
| 17 | { |
||
| 18 | /** @var AsObject */ |
||
| 19 | private $options; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * C'tor. |
||
| 23 | * |
||
| 24 | * @param AsObject $options |
||
| 25 | */ |
||
| 26 | 24 | public function __construct(AsObject $options) |
|
| 27 | { |
||
| 28 | 24 | $this->options = $options; |
|
| 29 | 24 | } |
|
| 30 | |||
| 31 | /** |
||
| 32 | * @return AsObject |
||
| 33 | */ |
||
| 34 | 4 | public function getOptions() |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param Slumberer $slumberer |
||
| 41 | * @param mixed $value |
||
| 42 | * |
||
| 43 | * @return mixed |
||
| 44 | */ |
||
| 45 | 15 | public function slumber(Slumberer $slumberer, $value) |
|
| 46 | { |
||
| 47 | /** |
||
| 48 | * unwrap any wrappers like LazyDbReference |
||
| 49 | * @see LazyDbReference |
||
| 50 | */ |
||
| 51 | 15 | if ($value instanceof ValueHolder) { |
|
| 52 | |||
| 53 | // TODO: Rethink this! Is this really a good idea or should it only happen in the Mongo ObjectMapper and only for LazyDbReference ? |
||
| 54 | // This might trigger in cases where it is not really wanted. |
||
| 55 | |||
| 56 | 1 | $value = $value->getValue(); |
|
| 57 | } |
||
| 58 | |||
| 59 | 15 | if ($value instanceof $this->options->value) { |
|
| 60 | 3 | return $slumberer->slumber($value); |
|
| 61 | } |
||
| 62 | |||
| 63 | 12 | return null; |
|
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param Awaker $awaker |
||
| 68 | * @param mixed $value |
||
| 69 | * |
||
| 70 | * @return mixed |
||
| 71 | */ |
||
| 72 | 5 | public function awake(Awaker $awaker, $value) |
|
| 81 | } |
||
| 82 | } |
||
| 83 |