returns the Class as PHP Code (without imports (use), without namespace decl)

indentation is fixed: 2 whitespaces
@return string the code with docblock from class { to }
972614
public function writeGClass(GClass $gClass, $namespace, $eol = "\n") {
    $that = $this;
    $this->namespaceContext = $namespace;
    
    $php = NULL;
    
    /* DocBlock */
    if ($gClass->hasDocBlock())
      $php .= $this->writeDocBlock($gClass->getDocBlock(), 0);
    
    /* Modifiers */
    $php .= $this->writeModifiers($gClass->getModifiers());
    
    /* Class */
    if ($gClass->isInterface()) {
      $php .= 'interface '.$gClass->getName().' ';
    } else {
      $php .= 'class '.$gClass->getName().' ';
    }
    
    /* Extends */
    if (($parent = $gClass->getParent()) != NULL) {
      // its important to use the contextNamespace here, because $namespace can be !== $gClass->getNamespace()
      if ($parent->getNamespace() === $namespace) {
        $php .= 'extends '.$parent->getName(); // don't prefix with namespace
      } else {
        // should it add to use, or use \FQN in extends?
        $php .= 'extends '.'\\'.$parent->getFQN();
      }
      $php .= ' ';
    }
    
    /* Interfaces */
    if (count($gClass->getInterfaces()) > 0) {
      $php .= 'implements ';
      $php .= A::implode($gClass->getInterfaces(), ', ', function (GClass $iClass) use ($namespace) {
        if ($iClass->getNamespace() === $namespace) {
          return $iClass->getName();
        } else {
          return '\\'.$iClass->getFQN();
        }
      });
      $php .= ' ';
    }
    
    $php .= '{'.$eol;
    
    /* those other methods make the margin with line breaks to top and to their left.*/
    
    /* Constants */
    $php .= A::joinc($gClass->getConstants(), '  '.$eol.'%s;'.$eol, function ($constant) use ($that, $eol) {
      return $that->writeConstant($constant, 2, $eol);
    });
    
    /* Properties */
    $php .= A::joinc($gClass->getProperties(), '  '.$eol.'%s;'.$eol, function ($property) use ($that, $eol) {
      return $that->writeProperty($property, 2, $eol);
    });

    /* Methods */
    $php .= A::joinc($gClass->getMethods(), '  '.$eol.'%s'.$eol, function ($method) use ($that, $eol) {
      return $that->writeMethod($method, 2, $eol); 
    });
    
    $php .= '}';
    
    return $php;
  }
295472
protected function _buildClass()
    {
        $defineData = $this->_extractData($this->elements);

        $defineParam = $this->parameters;
        $defineProps = $this->properties;

        $docBlock = '';
        foreach ($defineData as $key => $element) {
            $type = $element['type'];
            if ('scalar' === $type) {
                $type = 'string';
            }

            $docBlock .= "\n * @property ".$type.' $'.$key.' '.(isset($element['options']['label']) ? $element['options']['label'] : '');
        }

        array_walk($defineData, function (&$value, $key) {
                    $value = "->defineData('".$key."', '".$value['type']."', ".var_export($value['options'], true).")";
                });
        array_walk($defineParam, function (&$value, $key) {
                    $value = "->defineParam('".$key."', ".var_export($value, true).")";
                });
        array_walk($defineProps, function (&$value, $key) {
                    $value = "->defineProperty('".$key."', ".var_export($value, true).")";
                });

        $phpCode = str_replace(array('<namespace>',
            '<classname>',
            '<repository>',
            '<extends>',
            '<interface>',
            '<trait>',
            '<defineDatas>',
            '<defineParam>',
            '<defineProps>',
            '<docblock>', ), array($this->namespace,
            $this->classname,
            $this->repository,
            $this->extends,
            $this->interfaces,
            $this->traits,
            (0 < count($defineData)) ? '$this'.implode('', $defineData).';' : '',
            (0 < count($defineParam)) ? '$this'.implode('', $defineParam).';' : '',
            (0 < count($defineProps)) ? '$this'.implode('', $defineProps).';' : '',
            $docBlock, ), $this->template);

        return $phpCode;
    }
730055
protected function getElementType()
    {
        $class   = $this->getElementClass($this);
        $parts   = explode('\\', $class);
        $type    = end($parts);
        $replace = '$1_$2';

        return ctype_lower($type) ? $type : strtolower(preg_replace('/(.)([A-Z])/', $replace, $type));
    }
489256
public function generate()
    {
        $code = array();

        if ($this->namespace !== null) {
            $code[] = $this->getIndentation() . 'namespace ' . $this->namespace;
            $code[] = '{';
            $code[] = null;

            // Temporarily add one more level of indentation.
            $this->addIndentationLevel(1);
        }

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        $code[] = $this->generateSignature();
        $code[] = $this->getIndentation() . $this->generateBody();

        if ($this->namespace !== null) {
            // Set back the indentation.
            $this->addIndentationLevel(-1);

            $code[] = $this->getIndentation() . '}';
        }

        return implode($this->getLineFeed(), $code);
    }
352239
public function getClassName() {
        $fileSource = $this->fileSpecification->getSource();
        return (new fphp\Helper\PhpParser())->parseFile($fileSource)->getExactlyOneClass($fileSource)->name;
    }
1374156
public function toString()
    {
        if (substr($this->name, -2) === '()') {
            return PHP_EOL . substr($this->name, 0, -2) . '(' . implode($this->glue, $this->elements) . ')';
        } else {
            return PHP_EOL . $this->name . ' ' . implode($this->glue, $this->elements);
        }
    }
318535
function getClassName() {
    	preg_match('/\[\s\<\w+?>\s([\w\\\\]+)/s', $this->__toString(), $matches);
    	$class = isset($matches[1]) ? $matches[1] : null;
        if(in_array($class, [ 'array', 'string', 'char', 'bool', 'boolean', 'int', 'integer', 'double', 'float', 'real', 'mixed', 'number', 'null', 'callable', 'callback' ])) {
            return null;
        }
        return $class;
    }
905839
public static function getType()
    {
        $clsInfo = explode('\\', get_called_class());
        $namespaceParts = array_slice($clsInfo, 0, -1);
        // convention: AdminType classes are placed into the "<bundle>\Element\Type" namespace
        $namespaceParts[] = "Type";
        $bareClassName = implode('', array_slice($clsInfo, -1));
        // convention: AdminType class name is the same as the element class name suffixed with AdminType
        return implode('\\', $namespaceParts) . '\\' . $bareClassName . 'AdminType';
    }
809214
public function forTemplate()
    {
        $isEditable = FrontendEditing::editingEnabled() && FrontendEditing::isEditable($this);
        if ($isEditable) {
            $this->processShortcodes = false;
        }
        $value = parent::forTemplate();
        if ($isEditable) {
            $randId = uniqid();
            $value  = '<div id="'.$randId.'" contenteditable=true class="frontend-editable frontend-editable-html" data-feclass="'.FrontendEditing::getClassName($this).'" data-feid="'.FrontendEditing::getID($this).'" data-fefield="'.$this->name.'">'.$value.'</div>';
        }
        return $value;
    }
164403
protected function getPreviewCode()
    {
        $file = file($this->stack['file']);
        $line = $this->stack['line'];
        $_line = $line - 1;
        if ($_line - 5 >= 0) {
            $start = $_line - 5;
            $end = $_line + 5;
        } else {
            $start = $_line;
            $end = $line;
        }
        for ($i = $start; $i <= $end; $i++) {
            if (!isset($file[$i])) {
                break;
            }
            $text = trim($file[$i]);
            if ($i === $_line) {
                $this->stack['previewCode'] .=
                    "<span style='background:red' class='line'>".($i + 1).'</span>'.
                    "<span style='background:red'>".$text.'</span><br>';
                continue;
            }
            $this->stack['previewCode'] .=
                "<span class='line'>".($i + 1).'</span>'.
                '<span>'.$text.'</span><br>';
        }
    }
647045
public function phpdocContent()
    {
        $comment = preg_split('/(\n|\r\n)/', $this->comment);
        $comment[0] = preg_replace('/[ \t]*\\/\*\*/', '', $comment[0]); // strip '/**'
        $i = count($comment) - 1;
        $comment[$i] = preg_replace('/\*\/[ \t]*$/', '', $comment[$i]); // strip '*/'
        $lines = [];
        $append = false;
        foreach ($comment as $line) {
            $line = ltrim($line, "\t *");
            if (substr($line, 0, 1) === '@') {
                break;
            }
            if ($append) {
                $i = count($lines) - 1;
                $lines[$i] = substr($lines[$i], 0, -1) . $line;
            } else {
                $lines[] = $line;
            }
            $append = (substr($line, -1) === '\\');
        }
        $description = trim(implode("\n", $lines));
        if ($description === '') {
            return UNDEFINED;
        }

        return $description;
    }
532901
function getCode()
    {

        $out = $this->getHeaderCode();
        $out .= $this->getFormItemsCode();
        $out .= $this->getFooterCode();

        return $out;
    }
813951
public function generate()
    {
        $code = array();

        if ($this->namespace !== null) {
            $code[] = $this->getIndentation() . 'namespace ' . $this->namespace;
            $code[] = '{';
            $code[] = null;

            // Temporarily add one more level of indentation.
            $this->addIndentationLevel(1);
        }

        $code = array_merge($code, $this->renderUsesLines());

        $indentation = $this->getIndentation();

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        $line = $indentation;
        if ($this->isFinal() === true) {
            $line .= 'final ';
        } elseif ($this->isAbstract() === true) {
            $line .= 'abstract ';
        }

        $line .= 'class ' . $this->name;

        if ($this->extends !== null) {
            $line .= ' extends ' . $this->extends;
        }

        if (count($this->implements) > 0) {
            $line .= ' implements ' . implode(', ', $this->implements);
        }

        $code[] = $line;
        $code[] = $indentation . '{';

        // Class uses.
        $classElements = $this->generateTraitUsesLines();

        // Class constants.
        $classElements = array_merge($classElements, $this->generateConstantsLines());

        // Class properties.
        $classElements = array_merge($classElements, $this->generatePropertiesLines());

        // Class methods.
        $classElements = array_merge($classElements, $this->generateMethodsLines());

        if (count($classElements) > 0) {
            $code[] = null;
            $code = array_merge($code, $classElements);
            // Remove last empty line.
            array_pop($code);
        }

        $code[] = $indentation . '}';

        if ($this->namespace !== null) {
            // Set back the indentation.
            $this->addIndentationLevel(-1);

            $code[] = $this->getIndentation() . '}';
        }

        return implode($this->getLineFeed(), $code);
    }
723974
public function getNamespace()
    {
        if (array_key_exists('namespace', $this->prefs)) {
            return $this->prefs['namespace'];
        }

        if (!$this->getCapability('NAMESPACE')) {
            return self::ERROR_BAD;
        }

        list($code, $response) = $this->execute('NAMESPACE');

        if ($code == self::ERROR_OK && preg_match('/^\* NAMESPACE /', $response)) {
            $response = substr($response, 11);
            $data     = $this->tokenizeResponse($response);
        }

        if (!is_array($data)) {
            return $code;
        }

        $this->prefs['namespace'] = array(
            'personal' => $data[0],
            'other'    => $data[1],
            'shared'   => $data[2],
        );

        return $this->prefs['namespace'];
    }
831541
public function generate_class()
    {

        /**
         * generates the spaces
         *
         * @param int $amount
         *
         * @return string
         */
        function gen_spaces($amount)
        {
            $spaces = '';
            for ($i = 0; $i < $amount; $i++) {
                $spaces .= ' ';
            }

            return $spaces;
        }

        if (empty($this->table_model)) {
            return false;
        }

        // general initiation of the object properties based on the
        $this->init();

        $this->generate_class_definition();
        if (strpos($this->class_name, '_') !== false) {
            $tmp = explode('_', $this->class_name);
            foreach ($tmp as $key => $part) {
                $tmp[$key] = ucfirst(strtolower($part));
            }
            $this->class_name = implode('_', $tmp);
        }

        $this->tpl_replacements['class_name'] = $this->class_name;
        $file                                 = new File();
        $file->open($this->tpl_path);

        $this->generated_code = $file->read();

        foreach ($this->tpl_replacements as $pattern => $value) {
            if (!is_string($value)) continue;

            $pattern              = '#' . strtoupper($pattern) . '#';
            $this->generated_code = str_replace($pattern, $value, $this->generated_code);
        }

        $this->generated_code = str_replace("\t", gen_spaces(self::SPACE_AMOUNT), $this->generated_code);

        return true;
    }
1123887
public function getDocComment()
    {
        $docComment = false;
        $comments   = $this->namespaceNode->getAttribute('comments');

        if ($comments) {
            $docComment = (string)$comments[0];
        }

        return $docComment;
    }
505865
protected function getClassDocBlockLines() {
    $docblock_lines = parent::getClassDocBlockLines();

    // Do not include the annotation if this plugin is a class override.
    if (!empty($this->component_data['replace_parent_plugin'])) {
      return $docblock_lines;
    }

    $docblock_lines[] = '';

    $docblock_lines = array_merge($docblock_lines, $this->classAnnotation());

    return $docblock_lines;
  }