Completed
Pull Request — master (#31)
by Alessandro
06:14
created

queryFilterTranslate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace Facile\MongoDbBundle\Twig;
4
5
class FacileMongoDbBundleExtension extends \Twig_Extension
6
{
7
    public function getFunctions()
8
    {
9
        return array(
10
            new \Twig_Simplefunction('filterLabelTranslate', array($this, 'queryFilterTranslate')),
11
            new \Twig_Simplefunction('dataLabelTranslate', array($this, 'queryDataTranslate')),
12
        );
13
    }
14
15
    /**
16
     * @param string $label
17
     * @param string $methodName
18
     *
19
     * @return string
20
     */
21
    public function queryFilterTranslate(string $label, string $methodName)
22
    {
23
        switch(strtolower($methodName)) {
24
            default:
0 ignored issues
show
Unused Code introduced by
default: return $label; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
25
                return $label;
26
        }
27
    }
28
29
    /**
30
     * @param string $label
31
     * @param string $methodName
32
     *
33
     * @return string
34
     */
35
    public function queryDataTranslate(string $label, string $methodName)
36
    {
37
        switch(strtolower($methodName)) {
38
            case 'aggregate':
39
                return 'Pipeline';
40
            case 'insertOne':
41
                return 'Document';
42
            case 'updateOne':
43
            case 'findOneAndUpdate':
44
                return 'Update';
45
            case 'replaceOne':
46
                return 'Replacement';
47
            default:
48
                return $label;
49
        }
50
    }
51
52
    /**
53
     * Returns the name of the extension.
54
     *
55
     * @return string The extension name
56
     */
57
    public function getName()
58
    {
59
        return 'facile_mongo_db_extesion';
60
    }
61
}