-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed hacky switch/case, migrated to if/else and early return statements #5860
Conversation
@guilhermeblanco @Ocramius I have no idea why it is done |
|
||
default: | ||
throw new \InvalidArgumentException("Invalid argument: " . $conn); | ||
if (is_array($conn)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you segregate this entire block into its own private static method?
@Ocramius it's better? |
protected static function createConnection($conn, Configuration $config, EventManager $eventManager = null) | ||
{ | ||
if (is_array($conn)) { | ||
$conn = DriverManager::getConnection( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return early
@Ocramius now? |
return DriverManager::getConnection( | ||
$conn, $config, ($eventManager ?: new EventManager()) | ||
); | ||
} elseif ( ! $conn instanceof Connection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else
not needed, since you return early
} | ||
|
||
return new EntityManager($conn, $config, $conn->getEventManager()); | ||
return $connection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking whether $conn->getEventManager() === $eventManager
is still required (sorry, previous comment may have been misleading)
@peter-gribanov thanks! |
Partially reverting #5860 due to type juggling horrors
No description provided.