public static function createFromArray($properties, string $priceType = self::GROSS, $validate = true)
    {
        if (!is_array($properties) && !$properties instanceof Traversable) {
            throw new InvalidArgumentException("prices must be iterable");
        }

        $price = new static(null, $priceType);

        // Make sure default type is set first in order to be able to sanitize sign of other properties
        if (isset($properties[$priceType])) {
            $properties = [$priceType => $properties[$priceType]] + $properties;
        }

        foreach ($properties as $property => $value) {
            $value = Text::trim($value);
            if (mb_strlen($value)) {
                $value = ConvertPrice::getInstance()->sanitize($value);
                $price->set($property, $value, false, true);
            }
        }

        if (count($properties) > 1) {
            $price->calculate();
        }

        if ($validate) {
            $price->validate();
        }

        return $price;
    }
public static function createFromArray($properties, string $priceType = self::GROSS, $validate = true)
    {
        if (!is_array($properties) && !$properties instanceof Traversable) {
            throw new InvalidArgumentException("prices must be iterable");
        }

        $price = new static(null, $priceType);

        // Make sure default type is set first in order to be able to sanitize sign of other properties
        if (isset($properties[$priceType])) {
            $properties = [$priceType => $properties[$priceType]] + $properties;
        }

        foreach ($properties as $property => $value) {
            $value = Text::trim($value);
            if (mb_strlen($value)) {
                $value = ConvertPrice::getInstance()->sanitize($value);
                $price->set($property, $value, false, true);
            }
        }

        if (count($properties) > 1) {
            $price->calculate();
        }

        if ($validate) {
            $price->validate();
        }

        return $price;
    }
public static function createFromArray ( $ properties , string $ priceType = self :: GROSS , $ validate = true ) { if ( ! is_array ( $ properties ) && ! $ properties instanceof Traversable ) { throw new InvalidArgumentException ( "prices must be iterable" ) ; } $ price = new static ( null , $ priceType ) ; // Make sure default type is set first in order to be able to sanitize sign of other properties if ( isset ( $ properties [ $ priceType ] ) ) { $ properties = [ $ priceType => $ properties [ $ priceType ] ] + $ properties ; } foreach ( $ properties as $ property => $ value ) { $ value = Text :: trim ( $ value ) ; if ( mb_strlen ( $ value ) ) { $ value = ConvertPrice :: getInstance ( ) -> sanitize ( $ value ) ; $ price -> set ( $ property , $ value , false , true ) ; } } if ( count ( $ properties ) > 1 ) { $ price -> calculate ( ) ; } if ( $ validate ) { $ price -> validate ( ) ; } return $ price ; }
Create new instance via static method.

@param array  $properties
@param string $priceType [optional]
@param bool   $validate  [optional]

@return static
@throws InvalidArgumentException
Create new instance via static method .