Completed
Push — master ( b064d7...7efdd4 )
by Oscar
02:40
created

Twig   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 7
Bugs 1 Features 2
Metric Value
c 7
b 1
f 2
dl 0
loc 31
rs 10
wmc 3
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 8 2
A createTwig() 0 7 1
1
<?php
2
3
namespace Gettext\Extractors;
4
5
use Gettext\Translations;
6
use Twig_Loader_String;
7
use Twig_Environment;
8
use Twig_Extensions_Extension_I18n;
9
10
/**
11
 * Class to get gettext strings from twig files returning arrays.
12
 */
13
class Twig extends Extractor implements ExtractorInterface
14
{
15
    public static $options = [
16
        'twig' => null
17
    ];
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public static function fromString($string, Translations $translations, array $options = [])
23
    {
24
        $options += static::$options;
25
26
        $twig = $options['twig'] ?: self::createTwig();
27
28
        PhpCode::fromString($twig->compileSource($string), $translations, $options);
29
    }
30
31
    /**
32
     * Returns a Twig instance.
33
     *
34
     * @return Twig_Environment
35
     */
36
    private static function createTwig()
37
    {
38
        $twig = new Twig_Environment(new Twig_Loader_String());
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Loader_String has been deprecated with message: since 1.18.1 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
39
        $twig->addExtension(new Twig_Extensions_Extension_I18n());
40
41
        return static::$options['twig'] = $twig;
42
    }
43
}
44