public function renderClass()

in util/Endpoint.php [139:203]


    public function renderClass(): string
    {
        if (isset($this->content['body']['serialize']) &&
            $this->content['body']['serialize'] === 'bulk') {
            $class = file_get_contents(self::ENDPOINT_BULK_CLASS_TEMPLATE);
        } else {
            $class = file_get_contents(self::ENDPOINT_CLASS_TEMPLATE);
        }
        $class = str_replace(
            ':uri',
            $this->extractUrl($this->content['url']['paths']),
            $class
        );
        $class = str_replace(
            ':params',
            $this->extractParameters(),
            $class
        );
        $class = str_replace(
            ':namespace',
            $this->namespace === ''
                ? $this->normalizeName($this->namespace)
                : '\\' . $this->normalizeName($this->namespace),
            $class
        );

        // Set the HTTP method
        $action = $this->getMethod();
        if (!empty($this->content['body']) &&
            ($action === ['GET', 'POST'] || $action === ['POST', 'GET'])) {
            $method = 'isset($this->body) ? \'POST\' : \'GET\'';
        } else {
            $method = sprintf("'%s'", reset($action));
        }
        $class = str_replace(':method', $method, $class);

        $parts = '';
        // Set parts
        if (!empty($this->content['body'])) {
            if (isset($this->content['body']['serialize']) &&
                $this->content['body']['serialize'] === 'bulk') {
                $parts .= $this->getSetBulkBody();
            } else {
                $parts .= $this->getSetPart('body');
            }
        }
        foreach ($this->parts as $part => $value) {
            if (in_array($part, ['type', 'index', 'id'])) {
                continue;
            }
            if (isset($value['type']) && $value['type'] === 'list') {
                $parts .= $this->getSetPartList($part);
            } else {
                $parts .= $this->getSetPart($part);
            }
        }
        $class = str_replace(':set-parts', $parts, $class);
        $class = str_replace(':endpoint', $this->getClassName(), $class);
        $class = str_replace(':version', $this->version, $class);
        $class = str_replace(':buildhash', $this->buildhash, $class);
        $class = str_replace(':use-namespace', $this->getNamespaces(), $class);
        $class = str_replace(':properties', $this->getProperties(), $class);

        return str_replace(':apiname', $this->apiName, $class);
    }