Oihana PHP System

hydrateAdjustment.php

Table of Contents

Functions

hydrateAdjustment()  : mixed
Hydrate an array definition with the Adjustment class.

Functions

hydrateAdjustment()

Hydrate an array definition with the Adjustment class.

hydrateAdjustment([mixed $init = null ]) : mixed

Handles both a single adjustment array and an array of them — the second is the usual shape, since a document commonly carries a carriage charge beside an environmental fee.

The adjustment is built through Reflection::hydrate() rather than the Adjustment constructor : only that path honors the #[HydrateAs] / #[HydrateWith] attributes declared on the class, so amount and taxes come out typed. The resolution goes one level deeper on its own — each TaxDetail declares its own basisAmount and taxAmount, and reflection recurses — so the whole « what it costs / what it owes » pair is typed by this single call.

🔑 An empty list is kept as an empty list, where the rest of the family answers null. « This document has no adjustment » is an answer, and it is not the answer « nothing here was readable » : a consumer mapping over the value deserves the empty list it can map over. A non-empty list that hydrates to nothing keeps the family's null — there, nothing usable was found, which is a different statement.

🔑 A bare reference survives inside a list, exactly as it does on its own : a list of unresolved handles comes back as it stands, and only an entry that was an array and resolved to nothing is dropped. The keys stay gap-free — a filtered list left with holes serializes as a JSON object, and a consumer walking the value gets something it cannot walk.

Parameters
$init : mixed = null

Single adjustment data or array of adjustment data.

Tags
throws
HydrationException
ReflectionException
example
$adjustments = hydrateAdjustment
([
    [
        'type'   => PriceComponentType::SHIPPING_FEE ,
        'amount' => [ 'value' => 52 , 'currency' => 'EUR' ] ,
        'taxes'  => [ [ 'rate' => 20 , 'taxAmount' => [ 'value' => 10.4 , 'currency' => 'EUR' ] ] ] ,
    ] ,
]) ;

$adjustments[ 0 ]->amount instanceof MonetaryAmount            ; // true
$adjustments[ 0 ]->taxes[ 0 ]->taxAmount instanceof MonetaryAmount ; // true
On this page

Search results