Twig::fromString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Gettext\Extractors;
4
5
use Gettext\Translations;
6
use Twig_Loader_Array;
7
use Twig_Environment;
8
use Twig_Source;
9
use Twig_Extensions_Extension_I18n;
10
11
/**
12
 * Class to get gettext strings from twig files returning arrays.
13
 */
14
class Twig extends Extractor implements ExtractorInterface
15
{
16
    public static $options = [
17
        'extractComments' => 'notes:',
18
        'twig' => null,
19
    ];
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public static function fromString($string, Translations $translations, array $options = [])
25
    {
26
        $options += static::$options;
27
28
        $twig = $options['twig'] ?: static::createTwig();
29
30
        PhpCode::fromString($twig->compileSource(new Twig_Source($string, '')), $translations, $options);
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Source has been deprecated with message: since Twig 2.7, use "Twig\Source" instead

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...
31
    }
32
33
    /**
34
     * Returns a Twig instance.
35
     *
36
     * @return Twig_Environment
37
     */
38
    protected static function createTwig()
39
    {
40
        $twig = new Twig_Environment(new Twig_Loader_Array(['' => '']));
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Loader_Array has been deprecated with message: since Twig 2.7, use "Twig\Loader\ArrayLoader" instead

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...
Deprecated Code introduced by
The class Twig_Environment has been deprecated with message: since Twig 2.7, use "Twig\Environment" instead

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...
41
        $twig->addExtension(new Twig_Extensions_Extension_I18n());
42
43
        return static::$options['twig'] = $twig;
44
    }
45
}
46