Completed
Push — master ( a20241...2c1d12 )
by Oscar
13s queued 10s
created

JsCode   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 11.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 4 1
A fromStringMultiple() 0 7 1
A fromFileMultiple() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Gettext\Extractors;
4
5
use Exception;
6
use Gettext\Translations;
7
use Gettext\Utils\JsFunctionsScanner;
8
9
/**
10
 * Class to get gettext strings from javascript files.
11
 */
12
class JsCode extends Extractor implements ExtractorInterface, ExtractorMultiInterface
13
{
14
    public static $options = [
15
        'constants' => [],
16
17
        'functions' => [
18
            'gettext' => 'gettext',
19
            '__' => 'gettext',
20
            'ngettext' => 'ngettext',
21
            'n__' => 'ngettext',
22
            'pgettext' => 'pgettext',
23
            'p__' => 'pgettext',
24
            'dgettext' => 'dgettext',
25
            'd__' => 'dgettext',
26
            'dngettext' => 'dngettext',
27
            'dn__' => 'dngettext',
28
            'dpgettext' => 'dpgettext',
29
            'dp__' => 'dpgettext',
30
            'npgettext' => 'npgettext',
31
            'np__' => 'npgettext',
32
            'dnpgettext' => 'dnpgettext',
33
            'dnp__' => 'dnpgettext',
34
            'noop' => 'noop',
35
            'noop__' => 'noop',
36
        ],
37
    ];
38
39
    /**
40
     * @inheritdoc
41
     * @throws Exception
42
     */
43
    public static function fromString($string, Translations $translations, array $options = [])
44
    {
45
        self::fromStringMultiple($string, [$translations], $options);
46
    }
47
48
    /**
49
     * @inheritDoc
50
     * @throws Exception
51
     */
52
    public static function fromStringMultiple($string, array $translations, array $options = [])
53
    {
54
        $options += static::$options;
55
56
        $functions = new JsFunctionsScanner($string);
57
        $functions->saveGettextFunctions($translations, $options);
58
    }
59
60
    /**
61
     * @inheritDoc
62
     * @throws Exception
63
     */
64 View Code Duplication
    public static function fromFileMultiple($file, array $translations, array $options = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        foreach (self::getFiles($file) as $file) {
67
            $options['file'] = $file;
68
            static::fromStringMultiple(self::readFile($file), $translations, $options);
69
        }
70
    }
71
}
72