Completed
Branch 1707_add_explain_command (4124c6)
by Alessandro
02:34
created

FacileMongoDbBundleExtension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace Facile\MongoDbBundle\Twig;
4
5
use Facile\MongoDbBundle\Services\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
    public function isQueryExplainable(string $methodName): bool
52
    {
53
        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
    public function getName()
62
    {
63
        return 'facile_mongo_db_extesion';
64
    }
65
}