@param \google\protobuf\FieldDescriptorProto $field

@return string
775294
protected function getDocBlockType(FieldDescriptorProto $field)
    {
        $type     = $this->getDoctype($field);
        $typeName = $field->getTypeName();
        $label    = $field->getLabel();

        if ($label === Label::LABEL_REPEATED()) {
            $type = '\Protobuf\Collection';
        }

        if ($label === Label::LABEL_REPEATED() && $typeName !== null) {
            $typeName  = $field->getTypeName();
            $refEntity = $this->getEntity($typeName);
            $reference = $refEntity->getNamespacedName();
            $type      = $type . sprintf('<%s>', $reference);
        }

        return $type;
    }
1142848
protected function getMethodOutputDocblock(MethodDescriptorProto $method)
    {
        $refType   = $method->getOutputType();
        $refEntity = $this->getEntity($refType);
        $refClass  = $this->getMethodOutputTypeHint($method);

        if ($method->getServerStreaming()) {
            return sprintf('\Iterator<%s>', $refEntity->getNamespacedName());
        }

        return $refClass;
    }
1252629
public function punctuation($field)
    {
        return (preg_match("/[^\w\s\p{P}]/", '' . $this->get($field)) > 0) ? $this->error($field, __FUNCTION__) : true;
    }
599500
protected function generateSetValue(Entity $entity, FieldDescriptorProto $field)
    {
        $lines      = [];
        $fieldName  = $field->getName();
        $methodName = $this->getAccessorName('set', $field);

        $lines[] = '$message->' . $methodName . '($values[\'' . $fieldName . '\']);';

        return $lines;
    }
1107315
public function get_label($field) {
		return isset($this->labels[$field]) ? $this->labels[$field] : $this->humanize_field_name($field);
	}
602596
public function localizeField($field) {
        $re = "/(?:[-])(".$this->multilingual_parameters['default_language'].")(?:[-])/";
        $language = "-".$this->languageDetection()."-";
        $field = preg_replace($re, $language,$field);
        return $field;
    }
368348
public function generateFieldReadStatement(Entity $entity, FieldDescriptorProto $field)
    {
        $body      = [];
        $reference = null;
        $type      = $field->getType();
        $name      = $field->getName();
        $rule      = $field->getLabel();
        $tag       = $field->getNumber();
        $options   = $field->getOptions();
        $isPack    = $options ? $options->getPacked() : false;
        $variable  = $this->targetVar ?: '$this->' . $name;
        $breakSttm = $this->getBreakStatement($variable);

        if ($field->hasTypeName()) {
            $typeName   = $field->getTypeName();
            $typeEntity = $this->getEntity($typeName);
            $reference  = $typeEntity->getNamespacedName();
        }

        if ( ! $isPack) {
            $body[] = sprintf('\Protobuf\WireFormat::assertWireType($wire, %s);', $type->value());
            $body[] = null;
        }

        if ($rule === Label::LABEL_REPEATED() && $isPack) {
            $readSttm = ($type === Type::TYPE_ENUM())
                ? $reference . '::valueOf(' . $this->generateReadScalarStatement($type->value()) .')'
                : $this->generateReadScalarStatement($type->value());

            $body[] = '$innerSize  = $reader->readVarint($stream);';
            $body[] = '$innerLimit = $stream->tell() + $innerSize;';
            $body[] = null;
            $body[] = 'if (' . $variable . ' === null) {';
            $body[] = '    ' . $variable . ' = new ' . $this->getCollectionClassName($field) . '();';
            $body[] = '}';
            $body[] = null;
            $body[] = 'while ($stream->tell() < $innerLimit) {';
            $body[] = '    ' . $variable . '->add(' . $readSttm . ');';
            $body[] = '}';
            $body[] = null;
            $body[] = $breakSttm;

            return $body;
        }

        if ($type === Type::TYPE_MESSAGE() && $rule === Label::LABEL_REPEATED()) {
            $body[] = '$innerSize    = $reader->readVarint($stream);';
            $body[] = '$innerMessage = new ' . $reference . '();';
            $body[] = null;
            $body[] = 'if (' . $variable . ' === null) {';
            $body[] = '    ' . $variable . ' = new \Protobuf\MessageCollection();';
            $body[] = '}';
            $body[] = null;
            $body[] = $variable . '->add($innerMessage);';
            $body[] = null;
            $body[] = '$context->setLength($innerSize);';
            $body[] = '$innerMessage->readFrom($context);';
            $body[] = '$context->setLength($length);';
            $body[] = null;
            $body[] = $breakSttm;

            return $body;
        }

        if ($type === Type::TYPE_ENUM() && $rule === LABEL::LABEL_REPEATED()) {
            $body[] = 'if (' . $variable . ' === null) {';
            $body[] = '    ' . $variable . ' = new ' . $this->getCollectionClassName($field) . '();';
            $body[] = '}';
            $body[] = null;
            $body[] = $variable . '->add(' . $reference . '::valueOf(' . $this->generateReadScalarStatement($type->value()) . '));';
            $body[] = null;
            $body[] = $breakSttm;

            return $body;
        }

        if ($type === Type::TYPE_MESSAGE()) {
            $body[] = '$innerSize    = $reader->readVarint($stream);';
            $body[] = '$innerMessage = new ' . $reference . '();';
            $body[] = null;
            $body[] = $variable . ' = $innerMessage;';
            $body[] = null;
            $body[] = '$context->setLength($innerSize);';
            $body[] = '$innerMessage->readFrom($context);';
            $body[] = '$context->setLength($length);';
            $body[] = null;
            $body[] = $breakSttm;

            return $body;
        }

        if ($type === Type::TYPE_ENUM()) {
            $body[] = $variable . ' = ' . $reference . '::valueOf(' . $this->generateReadScalarStatement($type->value()) . ');';
            $body[] = null;
            $body[] = $breakSttm;

            return $body;
        }

        if ($rule !== LABEL::LABEL_REPEATED()) {
            $body[] = $variable . ' = ' . $this->generateReadScalarStatement($type->value()) . ';';
            $body[] = null;
            $body[] = $breakSttm;

            return $body;
        }

        $body[] = 'if (' . $variable . ' === null) {';
        $body[] = '    ' . $variable . ' = new ' . $this->getCollectionClassName($field) . '();';
        $body[] = '}';
        $body[] = null;
        $body[] = $variable . '->add(' . $this->generateReadScalarStatement($type->value()) . ');';
        $body[] = null;
        $body[] = $breakSttm;

        return $body;
    }
497084
public function handleField(Field $field)
    {
        $prefix = $this->prefix . strtoupper($field->name);

        if (!isset($field->label)) {
            $field->label = $prefix . '_LABEL';
        }

        if (preg_match('~^([A-Z_]+)$~', $field->label, $match)) {
            $prefix = $match[1];
        }

        if (preg_match('~^([A-Z_]+?)_LABEL$~', $field->label, $match)) {
            $prefix = $match[1];
        }

        if (!isset($field->description)) {
            $field->description = $prefix . '_DESC';
        }

        if (preg_match('~^([A-Z_]+?)_DESC$~', $field->description, $match)) {
            $prefix = $match[1];
        }

        if (!isset($field->hint)) {
            $field->hint = $prefix . '_HINT';
        }

        if (!isset($field->role)) {
            if (isset($this->special[$field->name])) {
                $field->role = $this->special[$field->name];
            }
        }

        if (isset($field->role)) {
            $this->fieldAliases[$field->role] = $field->name;
        }

        $this->reflector->addField($field);
    }
152222
public function addField(\google\protobuf\FieldDescriptorProto $value)
    {
        if ($this->field === null) {
            $this->field = new \Protobuf\MessageCollection();
        }

        $this->field->add($value);
    }
975119
private function render(Field $field)
    {
        $field->set('lang', $this->language);
        $field->set('prefix', $this->buildPrefix($field));

        foreach ($this->fill($field->getAttributes()) as $key => $value) {
            $field->set($key, $value);
        }

        return $field->render();
    }
714998
public static function quoteField($field) {
        $trimmedField = trim($field);
        if ($trimmedField == '*') {
            return $trimmedField;
        }

        if (strpos($trimmedField, ' ') !== false) {
            return $trimmedField;
        }

        return strpos($trimmedField, '.') !== false ?
                $trimmedField : "`{$trimmedField}`";
    }
992083
protected function generateRequiredFieldException(Entity $entity, FieldDescriptorProto $field)
    {
        $name       = $field->getName();
        $label      = $field->getLabel();
        $tag        = $field->getNumber();
        $isRequired = $label === Label::LABEL_REQUIRED();

        if ( ! $isRequired) {
            return [];
        }

        $class   = $entity->getNamespacedName();
        $format  = 'Field "%s#%s" (tag %s) is required but has no value.';
        $message = var_export(sprintf($format, $class, $name, $tag), true);

        $body[] = 'if ($this->' . $name . ' === null) {';
        $body[] = '    throw new \UnexpectedValueException(' . $message . ');';
        $body[] = '}';
        $body[] = null;

        return $body;
    }
1309929
protected function getUniqueFieldName(DescriptorProto $descriptor, $default)
    {
        $extensions = $descriptor->getExtensionList() ?: [];
        $fields     = $descriptor->getFieldList() ?: [];
        $name       = $default;
        $names      = [];
        $count      = 0;

        foreach ($fields as $field) {
            $names[$field->getName()] = true;
        }

        foreach ($extensions as $field) {
            $names[$field->getName()] = true;
        }

        while (isset($names[$name])) {
            $name = $default . ($count ++);
        }

        return $name;
    }
1089761
protected function generateFieldReadStatement(Entity $entity, FieldDescriptorProto $field)
    {
        $generator = new ReadFieldStatementGenerator($this->context);
        $statement = $generator->generateFieldReadStatement($entity, $field);

        return $statement;
    }
964382
public static function camelCaseToSnakeCase(string $field): string
    {
        return strtolower(preg_replace(self::REGEX_CAPITAL, self::REPLACEMENT_UNDERSCORE, $field));
    }
111292
public function build_field($field)
	{
		! $field instanceof Fieldset_Field && $field = $this->field($field);

		return $field->build();
	}
942668
protected function generateAddMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $fieldName  = $field->getName();
        $fieldType  = $field->getType();
        $collClass  = $this->getCollectionClassName($field);
        $methodName = 'add' . $this->getClassifiedName($field);
        $typeHint   = ($fieldType !== Type::TYPE_BYTES())
            ? $this->getDoctype($field)
            : null;

        $lines[] = 'if ($this->' . $fieldName . ' === null) {';
        $lines[] = '    $this->' . $fieldName . ' = new ' . $collClass . '();';
        $lines[] = '}';
        $lines[] = null;
        $lines[] = ($fieldType !== Type::TYPE_BYTES())
            ? '$this->' . $fieldName . '->add($value);'
            : '$this->' . $fieldName . '->add(\Protobuf\Stream::wrap($value));';

        return MethodGenerator::fromArray([
            'name'       => $methodName,
            'body'       => implode(PHP_EOL, $lines),
            'parameters' => [
                [
                    'name'   => 'value',
                    'type'   => $typeHint
                ]
            ],
            'docblock'   => [
                'shortDescription' => "Add a new element to '$fieldName'",
                'tags'             => [
                    [
                        'name'        => 'param',
                        'description' => $this->getDoctype($field) . ' $value'
                    ]
                ]
            ]
        ]);
    }