src/AbstractMessage.php
final public function freeze()
    {
        if ($this->isFrozen()) {
            return $this;
        }

        $this->validate();
        $this->isFrozen = true;

        foreach (static::schema()->getFields() as $field) {
            if ($field->getType()->isMessage()) {
                /** @var self $value */
                $value = $this->get($field->getName());
                if (empty($value)) {
                    continue;
                }

                if ($value instanceof Message) {
                    $value->freeze();
                    continue;
                }

                /** @var self $v */
                foreach ($value as $v) {
                    $v->freeze();
                }
            }
        }

        return $this;
    }
final public function freeze()
    {
        if ($this->isFrozen()) {
            return $this;
        }

        $this->validate();
        $this->isFrozen = true;

        foreach (static::schema()->getFields() as $field) {
            if ($field->getType()->isMessage()) {
                /** @var self $value */
                $value = $this->get($field->getName());
                if (empty($value)) {
                    continue;
                }

                if ($value instanceof Message) {
                    $value->freeze();
                    continue;
                }

                /** @var self $v */
                foreach ($value as $v) {
                    $v->freeze();
                }
            }
        }

        return $this;
    }
{@inheritdoc}
@return static