Skip to content

Commit

Permalink
#2273 - Remove .zep in stubs filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Oct 3, 2021
1 parent bcb9db3 commit 50be8dc
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions Library/Stubs/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function generate(string $namespace, string $path, string $indent, string
$class = $file->getClassDefinition();
$source = $this->buildClass($class, $indent, $banner);

$filename = ucfirst($class->getName()).'.zep.php';
$filename = ucfirst($class->getName()).'.php';
$filePath = $path.str_ireplace(
$namespace,
'',
Expand Down Expand Up @@ -177,30 +177,43 @@ protected function buildClass(ClassDefinition $class, string $indent, string $ba

$source .= PHP_EOL.'{'.PHP_EOL;

/**
* Build Class constants
*/
$constants = [];
foreach ($class->getConstants() as $constant) {
$source .= $this->buildConstant($constant, $indent).PHP_EOL.PHP_EOL;
$constants[] = $this->buildConstant($constant, $indent).PHP_EOL;
}

$source .= implode(PHP_EOL, $constants);
unset($constants);

/**
* Build Class properties
*/
$properties = [];
foreach ($class->getProperties() as $property) {
$source .= $this->buildProperty($property, $indent).PHP_EOL.PHP_EOL;
$properties[] = $this->buildProperty($property, $indent).PHP_EOL;
}

$source .= PHP_EOL;
$source .= implode(PHP_EOL, $properties).PHP_EOL;
unset($properties);

/**
* Build Class methods
*/
$methods = [];
foreach ($class->getMethods() as $method) {
if ($method->isInternal()) {
continue;
}

$source .= $this->buildMethod(
$method,
'interface' === $class->getType(),
$indent
);

$source .= PHP_EOL.PHP_EOL;
$methods[] = $this->buildMethod($method, 'interface' === $class->getType(), $indent).PHP_EOL;
}

$source .= implode(PHP_EOL, $methods);
unset($methods);

return $source.'}'.PHP_EOL;
}

Expand All @@ -224,7 +237,7 @@ protected function buildProperty(ClassProperty $property, string $indent): strin
$visibility = 'static '.$visibility;
}

$source = $visibility.' $'.$property->getName();
$source = $indent.$visibility.' $'.$property->getName();
$original = $property->getOriginal();

if (isset($original['default'])) {
Expand All @@ -233,9 +246,7 @@ protected function buildProperty(ClassProperty $property, string $indent): strin
]);
}

$docBlock = new DocBlock($property->getDocBlock(), $indent);

return $docBlock."\n".$indent.$source.';';
return $this->fetchDocBlock($property->getDocBlock(), $indent).$source.';';
}

/**
Expand All @@ -252,9 +263,7 @@ protected function buildConstant(ClassConstant $constant, string $indent): strin
'default' => $constant->getValue(),
]);

$docBlock = new DocBlock($constant->getDocBlock(), $indent);

return $docBlock."\n".$indent.$source.' = '.$value.';';
return $this->fetchDocBlock($constant->getDocBlock(), $indent).$indent.$source.' = '.$value.';';
}

/**
Expand Down Expand Up @@ -368,7 +377,10 @@ protected function buildMethod(ClassMethod $method, bool $isInterface, string $i
$methodBody .= PHP_EOL.$indent.'{'.PHP_EOL.$indent.'}';
}

return $docBlock->processMethodDocBlock().PHP_EOL.$methodBody;
$docs = $docBlock->processMethodDocBlock();
$docs = $docs ? $docs.PHP_EOL : '';

return $docs.$methodBody;
}

/**
Expand Down Expand Up @@ -439,4 +451,14 @@ protected function wrapPHPValue(array $parameter): string

return (string) $returnValue;
}

private function fetchDocBlock(?string $docBlock, string $indent): string
{
$docBlock = (new DocBlock($docBlock, $indent))->__toString();
if ($docBlock) {
return $docBlock.PHP_EOL;
}

return '';
}
}

0 comments on commit 50be8dc

Please sign in to comment.