Stevebauman\Inventory\Traits\InventoryTransactionTrait::validatePreviousState PHP Method

validatePreviousState() protected method

Returns true if the current state equals at least one of the allowed states in the array. Throws an exception otherwise.
protected validatePreviousState ( array $allowedStates = [], string $toState ) : boolean
$allowedStates array
$toState string
return boolean
    protected function validatePreviousState($allowedStates = [], $toState)
    {
        $state = $this->getAttribute('state');
        if (!in_array($state, $allowedStates)) {
            $fromState = !$state ? 'NULL' : $state;
            $message = "Transaction state: {$fromState} cannot be changed to a: {$toState} state.";
            throw new InvalidTransactionStateException($message);
        }
        return true;
    }