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

Twig::fromString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 2
Metric Value
cc 2
eloc 4
c 5
b 1
f 2
nc 2
nop 3
dl 0
loc 8
rs 9.4285
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