for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Facile\MongoDbBundle\Models;
/**
* Class ConnectionConfiguration.
*/
class ConnectionConfiguration
{
/** @var string */
private $host;
/** @var int */
private $port;
private $username;
private $password;
* ConnectionConfiguration constructor.
*
* @param string $host
* @param int $port
* @param string $username
* @param string $password
public function __construct(string $host, int $port, string $username = '', string $password = '')
$this->host = $host;
$this->port = $port;
$this->username = $username;
$this->password = $password;
}
* @return string
public function getHost(): string
return $this->host;
* @return int
public function getPort(): int
return $this->port;
public function getUsername(): string
return $this->username;
* @return bool
public function hasCredentials(): bool
return !empty($this->username);
public function getPassword(): string
return $this->password;
* @param string $databaseName
public function getConnectionUri(string $databaseName = null): string
// Refactor with a uriBuilder service or something like that
if ($this->hasCredentials() && !is_null($databaseName)) {
return sprintf(
'mongodb://%s:%s@%s:%d/%s',
$this->username,
$this->password,
$this->host,
$this->port,
$databaseName
);
if ($this->hasCredentials()) {
'mongodb://%s:%s@%s:%d',
$this->port
'mongodb://%s:%d',