MessageJsBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exportJsonp() 0 17 3
A __construct() 0 3 1
1
<?php
2
3
namespace Printful\GettextCms;
4
5
use Gettext\Generators\Jed;
6
7
/**
8
 * Class exports JS translations to JSONP callback files in JED translation format
9
 */
10
class MessageJsBuilder
11
{
12
    /** @var MessageStorage */
13
    private $storage;
14
15 2
    public function __construct(MessageStorage $storage)
16
    {
17 2
        $this->storage = $storage;
18 2
    }
19
20
    /**
21
     * Export one or multiple domains in a single JS file with JSONP callback that will load JED format translations
22
     *
23
     * @param string $locale
24
     * @param string[] $domains
25
     * @param string $jsonpCallback Function name, that will be called with domain translations
26
     * @return string
27
     */
28 2
    public function exportJsonp(string $locale, array $domains, string $jsonpCallback)
29
    {
30 2
        $js = '';
31
32 2
        foreach ($domains as $domain) {
33 2
            $translations = $this->storage->getEnabledTranslatedJs($locale, $domain);
34
35 2
            if (!count($translations)) {
36 1
                continue;
37
            }
38
39 1
            $jed = Jed::toString($translations);
40
41 1
            $js .= $jsonpCallback . '(' . $jed . ");\n";
42
        }
43
44 2
        return $js;
45
    }
46
}