jcb-compiler/src/a6052fe9-0d2b-4b36-b3e7-03b47c483542/code.power
2024-04-16 16:05:26 +02:00

65 lines
1.7 KiB
Plaintext

/**
* Builds the namespace statement from the power object's namespace and class name.
*
* @param object $power The power object.
*
* @return string The constructed use statement.
* @since 3.2.0
*/
protected function buildNamespaceStatment(object $power): string
{
return $power->_namespace . '\\' . $power->class_name;
}
/**
* Ensures the name for the use statement is unique, avoiding conflicts with other classes.
*
* @param string $name The current name
* @param object $power The power object containing type, namespace, and class name.
*
* @return string The unique name
* @since 3.2.0
*/
protected function getUniqueName(string $name, object $power): string
{
// set search namespace
$namespace = ($name !== $power->class_name) ? $this->buildNamespaceStatment($power) : $power->_namespace;
// check if we need to update the name
if (isset($this->other[$name]))
{
// if the name is already used
while (isset($this->other[$name]))
{
if (($tmp = $this->extractClassNameOrAlias($namespace)) !== null)
{
$name = ucfirst($tmp) . $name;
$namespace = $this->removeLastNameFromNamespace($namespace);
}
else
{
$name = 'Unique' . $name;
}
}
}
// also loop new found use statements
if (isset($this->useStatements[$name]))
{
// if the name is already used
while (isset($this->useStatements[$name]))
{
if (($tmp = $this->extractClassNameOrAlias($namespace)) !== null)
{
$name = ucfirst($tmp) . $name;
$namespace = $this->removeLastNameFromNamespace($namespace);
}
else
{
$name = 'Unique' . $name;
}
}
}
return $name;
}