src/Field.php
private function applyDefault($default = null)
    {
        $this->default = $default;

        if ($this->type->isScalar()) {
            if ($this->type->getTypeName() !== TypeName::TIMESTAMP()) {
                $this->useTypeDefault = true;
            }
        } else {
            $decodeDefault = null !== $this->default && !$this->default instanceof \Closure;
            switch ($this->type->getTypeValue()) {
                case TypeName::IDENTIFIER:
                    Assertion::notNull($this->className, sprintf('Field [%s] requires a className.', $this->name));
                    if ($decodeDefault && !$this->default instanceof Identifier) {
                        $this->default = $this->type->decode($this->default, $this);
                    }
                    break;

                case TypeName::INT_ENUM:
                case TypeName::STRING_ENUM:
                    Assertion::notNull($this->className, sprintf('Field [%s] requires a className.', $this->name));
                    if ($decodeDefault && !$this->default instanceof Enum) {
                        $this->default = $this->type->decode($this->default, $this);
                    }
                    break;

                default:
                    break;
            }
        }

        if (null !== $this->default && !$this->default instanceof \Closure) {
            $this->guardDefault($this->default);
        }
    }
private function applyDefault($default = null)
    {
        $this->default = $default;

        if ($this->type->isScalar()) {
            if ($this->type->getTypeName() !== TypeName::TIMESTAMP()) {
                $this->useTypeDefault = true;
            }
        } else {
            $decodeDefault = null !== $this->default && !$this->default instanceof \Closure;
            switch ($this->type->getTypeValue()) {
                case TypeName::IDENTIFIER:
                    Assertion::notNull($this->className, sprintf('Field [%s] requires a className.', $this->name));
                    if ($decodeDefault && !$this->default instanceof Identifier) {
                        $this->default = $this->type->decode($this->default, $this);
                    }
                    break;

                case TypeName::INT_ENUM:
                case TypeName::STRING_ENUM:
                    Assertion::notNull($this->className, sprintf('Field [%s] requires a className.', $this->name));
                    if ($decodeDefault && !$this->default instanceof Enum) {
                        $this->default = $this->type->decode($this->default, $this);
                    }
                    break;

                default:
                    break;
            }
        }

        if (null !== $this->default && !$this->default instanceof \Closure) {
            $this->guardDefault($this->default);
        }
    }
private function applyDefault ( $ default = null ) { $ this -> default = $ default ; if ( $ this -> type -> isScalar ( ) ) { if ( $ this -> type -> getTypeName ( ) !== TypeName :: TIMESTAMP ( ) ) { $ this -> useTypeDefault = true ; } } else { $ decodeDefault = null !== $ this -> default && ! $ this -> default instanceof \ Closure ; switch ( $ this -> type -> getTypeValue ( ) ) { case TypeName :: IDENTIFIER : Assertion :: notNull ( $ this -> className , sprintf ( 'Field [%s] requires a className.' , $ this -> name ) ) ; if ( $ decodeDefault && ! $ this -> default instanceof Identifier ) { $ this -> default = $ this -> type -> decode ( $ this -> default , $ this ) ; } break ; case TypeName :: INT_ENUM : case TypeName :: STRING_ENUM : Assertion :: notNull ( $ this -> className , sprintf ( 'Field [%s] requires a className.' , $ this -> name ) ) ; if ( $ decodeDefault && ! $ this -> default instanceof Enum ) { $ this -> default = $ this -> type -> decode ( $ this -> default , $ this ) ; } break ; default : break ; } } if ( null !== $ this -> default && ! $ this -> default instanceof \ Closure ) { $ this -> guardDefault ( $ this -> default ) ; } }
@param mixed $default

@throws AssertionFailed
@throws \Exception
@param mixed $default