Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,15 @@ private function typeIncludesType( $existingType, $checkType ) {
}
}

// If checking for 'object', treat any class name as covering it.
if ( $checkType === 'object' ) {
foreach ( $existingTypes as $existing ) {
if ( $this->isClassName( $existing ) ) {
return true;
}
}
}

foreach ( $checkTypes as $singleType ) {
foreach ( $existingTypes as $existing ) {
// Normalize types for comparison.
Expand All @@ -446,6 +455,42 @@ private function typeIncludesType( $existingType, $checkType ) {
return false;
}

/**
* Check if a type string looks like a class name.
*
* @param string $type The type to check.
*
* @return bool
*/
private function isClassName( $type ) {
$type = trim( $type );

// Skip primitive types and known non-class types.
$primitives = array(
'int', 'integer', 'float', 'double', 'real', 'string', 'bool', 'boolean',
'array', 'object', 'null', 'mixed', 'void', 'callable', 'iterable',
'resource', 'true', 'false', 'self', 'static', 'parent',
);

$lowerType = strtolower( $type );

if ( in_array( $lowerType, $primitives, true ) ) {
return false;
}

// Skip if it's an array notation.
if ( preg_match( '/\[\]$/', $type ) || preg_match( '/^array\s*[<{]/', $lowerType ) ) {
return false;
}

// If it starts with uppercase or contains backslash (namespace), it's likely a class.
if ( preg_match( '/^[A-Z]/', $type ) || strpos( $type, '\\' ) !== false ) {
return true;
}

return false;
}

/**
* Normalize a type for comparison.
*
Expand Down Expand Up @@ -476,6 +521,11 @@ private function normalizeType( $type ) {
return 'array';
}

// Normalize shorthand array notation (int[], string[], etc.) to just 'array'.
if ( preg_match( '/\[\]$/', $type ) ) {
return 'array';
}

return $type;
}

Expand Down
Loading