@param \Protobuf\Compiler\Entity $entity

@return string
177457
public function generateValueOfMethod(Entity $entity)
    {
        $body        = [];
        $descriptor  = $entity->getDescriptor();
        $class       = $entity->getNamespacedName();
        $values      = $descriptor->getValueList() ?: [];

        $body[] = 'switch ($value) {';

        foreach ($values as $value) {
            $name   = $value->getName();
            $number = $value->getNumber();

            $body[] = '    case ' . $number . ': return self::' . $name . '();';
        }

        $body[] = '    default: return null;';
        $body[] = '}';

        $method = MethodGenerator::fromArray([
            'static'     => true,
            'name'       => 'valueOf',
            'body'       => implode(PHP_EOL, $body),
            'parameters' => [
                [
                    'name' => 'value',
                    'type' => 'int',
                ]
            ],
            'docblock'   => [
                'tags'     => [
                    [
                        'name'        => 'param',
                        'description' => 'int $value',
                    ],
                    [
                        'name'        => 'return',
                        'description' => $class,
                    ]
                ]
            ]
        ]);

        $method->getDocblock()->setWordWrap(false);

        return $method;
    }
1372583
protected function generateBody(Entity $entity)
    {
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];
        $extLines   = $this->generateExtensionsSerializedSize($entity);

        $body[] = '$calculator = $context->getSizeCalculator();';
        $body[] = '$size       = 0;';
        $body[] = null;

        foreach ($fields as $field) {
            $lines = $this->generateFieldCondition($entity, $field);
            $body  = array_merge($body, $lines, [null]);
        }

        $body   = array_merge($body, $extLines);
        $body[] = null;
        $body[] = 'return $size;';

        return $body;
    }
58414
protected function generateToStreamMethod(Entity $entity)
    {
        $lines   = $this->generateBody($entity);
        $body    = implode(PHP_EOL, $lines);
        $method  = MethodGenerator::fromArray([
            'name'       => 'toStream',
            'body'       => $body,
            'parameters' => [
                [
                    'name'          => 'configuration',
                    'type'          => '\Protobuf\Configuration',
                    'defaultValue'  => null
                ]
            ],
            'docblock'   => [
                'shortDescription' => "{@inheritdoc}"
            ]
        ]);

        return $method;
    }
253109
public function generateBody(Entity $entity)
    {
        $innerLoop = $this->addIndentation($this->generateInnerLoop($entity), 1);

        $body[] = '$reader = $context->getReader();';
        $body[] = '$length = $context->getLength();';
        $body[] = '$stream = $context->getStream();';
        $body[] = null;
        $body[] = '$limit = ($length !== null)';
        $body[] = '    ? ($stream->tell() + $length)';
        $body[] = '    : null;';
        $body[] = null;
        $body[] = 'while ($limit === null || $stream->tell() < $limit) {';

        $body = array_merge($body, $innerLoop);

        $body[] = null;
        $body[] = '}';

        return $body;
    }
1360273
private function formatEntities(array $entities) : string
    {
        $formattedEntities = array_map(function (DistanceMatrixLocation $entry) {
            return $entry->getFormattedLocation();
        }, $entities);
        $formattedEntities = implode('|', $formattedEntities);

        return $formattedEntities;
    }
92069
private static function makeObject($entity)
    {
        $methodsGet = get_class_methods($entity);
        $methodsGet = array_filter($methodsGet, function($value) {
            return (bool) preg_match('/^get.*$/', $value);
        });
        $std = new \stdClass();
        foreach ($methodsGet as $attribute) {
            $name = str_replace('get', '', $attribute);
            $name = lcfirst($name);
            $std->$name = $entity->$attribute();
        }
        return $std;
    }
642349
protected function getEntityTable($entity)
    {
        if (!$entity instanceof EntityInterface) {
            $entity = $this->getEntityClass($entity);
        }
        return $this->tablePrefix . $entity::getTable() . $this->tableSuffix;
    }
471958
public function unmapEntity(Entity $entity)
    {
        $output = [];
        foreach ($entity->getData() as $name => $value) {

            $property = $entity::getReflection()->getProperty($name);

            // Skip associations & readonly & disabled mapping
            if ($property->hasOption(Reflection\Property\Option\Assoc::KEY)
                || !$property->isWritable()
                || ($property->hasOption(Reflection\Property\Option\Map::KEY)
                    && !$property->getOption(Reflection\Property\Option\Map::KEY))
            ) {
                continue;
            }

            $output[$property->getUnmapped()] = $this->unmapValue($property, $value);
        }
        return $output;
    }
142471
protected function buildEntityCreatePayload(EntityInterface $entity, array $context = []): string
    {
        return $this->getEntitySerializer()->serialize($entity, 'json', $context);
    }
1039695
public static function getEntity(\Twizo\Api\AbstractEntity $entity)
    {
        $result = '';
        $values = self::getEntityValues($entity);

        $result .= str_repeat('-', strlen(get_class($entity)) + 4) . PHP_EOL;
        $result .= '| ' . get_class($entity) . ' |' . PHP_EOL;
        $result .= str_repeat('-', strlen(get_class($entity)) + 4) . PHP_EOL;

        foreach ($values as $method => $value) {
            $result .= substr($method, 3) . ' : ' . var_export($value, true) . PHP_EOL;
        }

        return $result;
    }
147312
public function getEntityId($entity)
    {
        $entityId = $this->idAccessorRegistry->getEntityId($entity);

        if (is_array($entityId)) {
            ksort($entityId);
            $entityId = json_encode($entityId);
        }

        return $entityId;
    }
360936
protected function generateGetUnknownFieldSetMethod(Entity $entity)
    {
        $methodName = 'unknownFieldSet';
        $descriptor = $entity->getDescriptor();
        $fieldName  = $this->getUniqueFieldName($descriptor, $methodName);
        $method     = MethodGenerator::fromArray([
            'name'       => $methodName,
            'body'       => 'return $this->' . $fieldName . ';',
            'docblock'   => [
                'shortDescription' => "{@inheritdoc}"
            ]
        ]);

        return $method;
    }
70221
protected function generateDefaultValues(Entity $entity)
    {
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];
        $size       = count($fields);
        $lines      = [];

        foreach ($fields as $i => $field) {
            $name  = $field->getName();
            $comma = ($i +1 < $size) ? ',' : '';
            $value = $this->getDefaultFieldValue($field);

            // required field throw InvalidArgumentException
            if ($field->getLabel() === Label::LABEL_REQUIRED()) {
                continue;
            }

            if ($field->getLabel() === Label::LABEL_REPEATED()) {
                $value = '[]';
            }

            $lines[] = "'$name' => $value" . $comma;
        }

        return $lines;
    }
924539
public function getRepository($entity)
    {
        $annotation = $this->getClassAnnotation($entity, self::DOCUMENT_CLASS);

        if ($annotation instanceof Document) {
            return $annotation->repository;
        }

        return '';
    }
650005
private function getDoctrineMapperType($entity)
    {
        if ($this->isDoctrineEntity($entity) == false) {
            return '';
        }

        if ($this->annotationReader->isOdm($entity)) {
            return MetaInformationInterface::DOCTRINE_MAPPER_TYPE_DOCUMENT;
        }

        if ($this->annotationReader->isOrm($entity)) {
            return MetaInformationInterface::DOCTRINE_MAPPER_TYPE_RELATIONAL;
        }
    }
405601
public function defaultRender($entity)
    {
        $joinEntity = $this->getJoinEntity($entity);

        if ($joinEntity === null) {
            return null;
        }

        if ($joinEntity instanceof \Traversable) {
            $html = '';
            foreach ($joinEntity as $e) {
                $html .= '<span class="label label-primary">' . $this->getJoinEntityValue($e) . '</span>&nbsp;';
            }
            return $html;
        }

        return $this->getJoinEntityValue($joinEntity);
    }
584651
public function getSynchronizationCallback($entity)
    {
        $annotation = $this->getClassAnnotation($entity, self::SYNCHRONIZATION_FILTER_CLASS);

        if (!$annotation) {
            return '';
        }

        return $annotation->callback;
    }