gossi\codegen\generator\builder\parts\StructBuilderPart::buildUseStatements PHP Method

buildUseStatements() protected method

protected buildUseStatements ( AbstractPhpStruct $model )
$model gossi\codegen\model\AbstractPhpStruct
    protected function buildUseStatements(AbstractPhpStruct $model)
    {
        if ($useStatements = $model->getUseStatements()) {
            $this->ensureBlankLine();
            foreach ($useStatements as $alias => $namespace) {
                if (false === strpos($namespace, '\\')) {
                    $commonName = $namespace;
                } else {
                    $commonName = substr($namespace, strrpos($namespace, '\\') + 1);
                }
                if (false === strpos($namespace, '\\') && !$model->getNamespace()) {
                    //avoid fatal 'The use statement with non-compound name '$commonName' has no effect'
                    continue;
                }
                $this->writer->write('use ' . $namespace);
                if ($commonName !== $alias) {
                    $this->writer->write(' as ' . $alias);
                }
                $this->writer->writeln(';');
            }
            $this->ensureBlankLine();
        }
    }