for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @file
* Contains \Drupal\mongodb\ClientFactory.
*/
namespace Drupal\mongodb;
use Drupal\Core\Site\Settings;
use MongoDB\Client;
* Class ClientFactory.
*
* @package Drupal\mongodb
class ClientFactory {
* The 'mongodb' client settings.
* @var string[][]
protected $settings;
* A hash of connections per alias.
* @var \MongoDB\Client[]
protected $clients;
* Constructor.
* @param \Drupal\Core\Site\Settings $settings
* The system settings.
public function __construct(Settings $settings) {
$this->settings = $settings->get('mongodb')['clients'];
}
public function get($alias) {
if (!isset($this->clients[$alias]) || !$this->clients[$alias] instanceof \MongoDB\Client) {
$info = isset($this->settings[$alias]) ? $this->settings[$alias] : [];
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
$a = "a"; $ab = "ab"; $abc = "abc";
will produce issues in the first and second line, while this second example
will produce no issues.
$info += [
'uri' => 'mongodb://localhost:27017',
'uriOptions' => [],
'driverOptions' => [],
];
// Don't use ...$info: keys can be out of order.
$this->clients[$alias] = new Client($info['uri'], $info['uriOptions'], $info['driverOptions']);
return $this->clients[$alias];
This check marks files that end in a newline character, i.e. an empy line.