Completed
Branch 1707_add_explain_command (cbe7fb)
by Alessandro
02:54
created

FacileMongoDbBundleExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 59
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 8 1
A queryFilterTranslate() 0 4 1
A queryDataTranslate() 0 4 1
A isQueryExplainable() 0 4 1
A getName() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace Facile\MongoDbBundle\Twig;
4
5
use Facile\MongoDbBundle\Services\Explain\ExplainQueryService;
6
7
class FacileMongoDbBundleExtension extends \Twig_Extension
8
{
9
    private $methodDataTranslationMap  = [
10
        'aggregate' => 'Pipeline',
11
        'insertOne' => 'Document',
12
        'updateOne' => 'Update',
13
        'findOneAndUpdate' => 'Update',
14
        'replaceOne' => 'Replacement',
15
    ];
16
17
    /**
18
     * @return array
19
     */
20
    public function getFunctions()
21
    {
22
        return [
23
            new \Twig_Simplefunction('filterLabelTranslate', array($this, 'queryFilterTranslate')),
24
            new \Twig_Simplefunction('dataLabelTranslate', array($this, 'queryDataTranslate')),
25
            new \Twig_Simplefunction('isQueryExplainable', array($this, 'isQueryExplainable')),
26
        ];
27
    }
28
29
    /**
30
     * @param string $label
31
     * @param string $methodName
32
     *
33
     * @return string
34
     */
35 1
    public function queryFilterTranslate(string $label, string $methodName): string
0 ignored issues
show
Unused Code introduced by
The parameter $methodName 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...
36
    {
37 1
        return $label;
38
    }
39
40
    /**
41
     * @param string $label
42
     * @param string $methodName
43
     *
44
     * @return string
45
     */
46 6
    public function queryDataTranslate(string $label, string $methodName): string
47
    {
48 6
        return $this->methodDataTranslationMap[$methodName] ?? $label;
49
    }
50
51 12
    public function isQueryExplainable(string $methodName): bool
52
    {
53 12
        return in_array($methodName, ExplainQueryService::$acceptedMethods);
54
    }
55
56
    /**
57
     * Returns the name of the extension.
58
     *
59
     * @return string The extension name
60
     */
61 1
    public function getName()
62
    {
63 1
        return 'facile_mongo_db_extesion';
64
    }
65
}