Skip to content
Permalink
Browse files

Remove redundant code from toNamespacedString

  • Loading branch information...
muglug committed Jun 1, 2019
1 parent 8968488 commit 01f4e39719c402576ebd944a37627901d2966dda
@@ -1006,6 +1006,38 @@ public static function getFQCLNFromString($class, Aliases $aliases)
return ($namespace ? $namespace . '\\' : '') . $class;
}
/**
* @param array<string, string> $aliased_classes
*/
public static function getStringFromFQCLN(
string $value,
?string $namespace,
array $aliased_classes,
?string $this_class
) : string {
if ($value === $this_class) {
return 'self';
}
if ($namespace && stripos($value, $namespace . '\\') === 0) {
return preg_replace(
'/^' . preg_quote($namespace . '\\') . '/i',
'',
$value
);
}
if (!$namespace && stripos($value, '\\') === false) {
return $value;
}
if (isset($aliased_classes[strtolower($value)])) {
return $aliased_classes[strtolower($value)];
}
return '\\' . $value;
}
/**
* @param bool $from_calculation
* @param int|null $value
@@ -742,21 +742,22 @@ public function getAssertionString()
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
* @param array<string, string> $aliased_classes
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
return $this->getKey();
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param array<string, string> $aliased_classes
* @param string|null $this_class
* @param int $php_major_version
* @param int $php_minor_version
@@ -45,15 +45,16 @@ public function __clone()
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
* @param array<string, string> $aliased_classes
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if ($use_phpdoc_format) {
if ($this instanceof TNamedObject) {
return parent::toNamespacedString($namespace, $aliased_classes, $this_class, true);
@@ -112,7 +113,7 @@ function (FunctionLikeParameter $param) use ($namespace, $aliased_classes, $this
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param array<string, string> $aliased_classes
* @param string|null $this_class
* @param int $php_major_version
* @param int $php_minor_version
@@ -49,15 +49,16 @@ public function getId()
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
* @param array<string, string> $aliased_classes
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
$base_value = $this instanceof TNamedObject
? parent::toNamespacedString($namespace, $aliased_classes, $this_class, $use_phpdoc_format)
: $this->value;
@@ -13,15 +13,16 @@ trait HasIntersectionTrait
public $extra_types;
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
* @param array<string, string> $aliased_classes
*
* @return string
*/
private function getNamespacedIntersectionTypes($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
private function getNamespacedIntersectionTypes(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if (!$this->extra_types) {
return '';
}
@@ -95,15 +95,16 @@ function ($name, Union $type) {
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
* @param array<string, string> $aliased_classes
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if ($use_phpdoc_format) {
return $this->getGenericArrayType()->toNamespacedString(
$namespace,
@@ -67,8 +67,12 @@ public function toPhpString(
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if ($this->as === 'object') {
return 'class-string';
}
@@ -54,7 +54,7 @@ public function canBeFullyExpressedInPhp()
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param array<string, string> $aliased_classes
* @param string|null $this_class
* @param int $php_major_version
* @param int $php_minor_version
@@ -75,8 +75,12 @@ public function canBeFullyExpressedInPhp()
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if ($this->fq_classlike_name === 'static') {
return 'key-of<static::' . $this->const_name . '>';
}
@@ -75,8 +75,12 @@ public function getAssertionString()
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if ($this->value === 'static') {
return 'static::class';
}
@@ -57,8 +57,12 @@ public function toPhpString(
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
return 'float';
}
}
@@ -57,8 +57,12 @@ public function toPhpString(
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
return 'int';
}
}
@@ -69,8 +69,12 @@ public function toPhpString(
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
return 'string';
}
}
@@ -51,51 +51,35 @@ public function getId()
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param array<string, string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if ($this->value === 'static') {
return 'static';
}
$intersection_types = $this->getNamespacedIntersectionTypes(
$namespace,
$aliased_classes,
$this_class,
$use_phpdoc_format
);
if ($this->value === 'static') {
return 'static';
}
if ($this->value === $this_class) {
return 'self' . $intersection_types;
}
if ($namespace && stripos($this->value, $namespace . '\\') === 0) {
return preg_replace(
'/^' . preg_quote($namespace . '\\') . '/i',
'',
$this->value
) . $intersection_types;
}
if (!$namespace && stripos($this->value, '\\') === false) {
return $this->value . $intersection_types;
}
if (isset($aliased_classes[strtolower($this->value)])) {
return $aliased_classes[strtolower($this->value)] . $intersection_types;
}
return '\\' . $this->value . $intersection_types;
return Type::getStringFromFQCLN($this->value, $namespace, $aliased_classes, $this_class) . $intersection_types;
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param array<string, string> $aliased_classes
* @param string|null $this_class
* @param int $php_major_version
* @param int $php_minor_version
@@ -67,14 +67,18 @@ function ($name, Union $type) {
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param array<string, string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if ($use_phpdoc_format) {
return 'object';
}

0 comments on commit 01f4e39

Please sign in to comment.
You can’t perform that action at this time.