Completed
Push — 8.x-2.x ( 8af97d...4c7eae )
by Frédéric G.
03:11
created

DatabaseFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * @file
4
 * Contains \Drupal\mongodb\DatabaseFactory.
5
 */
6
7
namespace Drupal\mongodb;
8
9
use Drupal\Core\Site\Settings;
10
11
/**
12
 * Class DatabaseFactory.
13
 *
14
 * @package Drupal\mongodb
15
 */
16
class DatabaseFactory {
17
18
  /**
19
   * The Client factory service.
20
   *
21
   * @var \Drupal\mongodb\ClientFactory
22
   */
23
  protected $clientFactory;
24
25
  /**
26
   * The 'mongodb' database settings array.
27
   *
28
   * @var string[][]
29
   */
30
  protected $settings;
31
32
  /**
33
   * Constructor.
34
   *
35
   * @param \Drupal\mongodb\ClientFactory $client_factory
36
   *   The Client factory service.
37
   */
38
  public function __construct(ClientFactory $client_factory, Settings $settings) {
39
    $this->clientFactory = $client_factory;
40
    $this->settings = $settings->get('mongodb')['databases'];
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

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

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
41
  }
42
43
  /**
44
   * Return the MongoDB database matching an alias.
45
   *
46
   * @param string $alias
47
   *   The alias string, like "default".
48
   *
49
   * @return \MongoDB\Database|null
50
   *   The selected database, or NULL if an error occurred.
51
   */
52
  public function get($alias) {
53
    try {
54
      list($client_alias, $database) = $this->settings[$alias];
55
      $client = $this->clientFactory->get($client_alias);
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 24 spaces but found 1 space

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

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
56
      $result = $client->selectDatabase($database);
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 24 spaces but found 1 space

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

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
57
    }
58
    catch (\InvalidArgumentException $e) {
59
      $result = NULL;
60
    }
61
    catch (\MongoConnectionException $e) {
62
      $result = NULL;
63
    }
64
65
    return $result;
66
  }
67
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
68