Passed
Pull Request — 8.x-2.x (#69)
by Frédéric G.
06:32
created

QueueMongodbFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Drupal\mongodb\Queue;
5
6
use Drupal\Core\Site\Settings;
7
use MongoDB\Database;
8
9
/**
10
 * Defines the queue factory for the MongoDB backend.
11
 */
12
class QueueMongodbFactory {
13
14
  /**
15
   * The queue storage.
16
   *
17
   * @var \MongoDB\Database
18
   */
19
  protected $database;
20
21
  /**
22
   * The settings array.
23
   *
24
   * @var \Drupal\Core\Site\Settings
25
   */
26
  protected $settings;
27
28
  /**
29
   * Constructs this factory object.
30
   *
31
   * @param \MongoDB\Database $database
32
   *   The database object.
33
   * @param \Drupal\Core\Site\Settings $settings
34
   *   The system settings.
35
   */
36
  public function __construct(Database $database, Settings $settings) {
37
    $this->database = $database;
38
    $this->settings = $settings;
39
  }
40
41
  /**
42
   * Constructs a new queue object for a given name.
43
   *
44
   * @param string $name
45
   *   The name of the collection holding key and value pairs.
46
   *
47
   * @return \Drupal\Core\Queue\DatabaseQueue
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use MongodbQueue.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
48
   *   A key/value store implementation for the given $collection.
49
   */
50
  public function get($name) {
51
    $settings = $this->settings->get('mongodb_queue_' . $name);
52
    return new MongodbQueue($name, $settings, $this->database);
53
  }
54
55
}
56