SchemaManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createSchemata() 0 10 4
A syncSchemata() 0 7 1
1
<?php
2
3
namespace As3\Modlr\Persister\MongoDb;
4
5
use Doctrine\MongoDB\Collection;
6
7
/**
8
 * Handles requests to create or sync schema
9
 *
10
 * @author  Josh Worden <[email protected]>
11
 * @todo    This should be updated to read indices from the metadata factory
12
 */
13
class SchemaManager
14
{
15
    /**
16
     * Applies schemata
17
     *
18
     * @param   Collection  $collection     The MongoDB Collection
19
     * @param   array       $index          Associative array containing index data
0 ignored issues
show
Bug introduced by
There is no parameter named $index. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
20
     */
21
    public function createSchemata(Collection $collection, array $schemata)
22
    {
23
        foreach ($schemata as $schema) {
24
            if (!isset($schema['keys']) || empty($schema['keys'])) {
25
                throw new \InvalidArgumentException('Cannot create an index with no keys defined.');
26
            }
27
            $schema['options']['background'] = true;
28
            $collection->ensureIndex($schema['keys'], $schema['options']);
29
        }
30
    }
31
32
    /**
33
     * Syncs schemata state
34
     * @todo    Implement
35
     *
36
     * @param   Collection  $collection     The MongoDB Collection
37
     * @param   array       $index              Associative array containing index data
0 ignored issues
show
Bug introduced by
There is no parameter named $index. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
38
     */
39
    public function syncSchemata(Collection $collection, array $schemata)
0 ignored issues
show
Unused Code introduced by
The parameter $collection is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $schemata is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        return false;
42
        // Remove all indices that match the expected format (modlr_md5hash) and are NOT present in $schemata
43
44
        // Loop over $schemata and force update or remove/add index. Ensure background:true
45
    }
46
}
47