FlysystemXliffLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\PlatformAdapter\Flysystem\Loader;
13
14
use League\Flysystem\Filesystem;
15
use Symfony\Component\Translation\MessageCatalogue;
16
use Symfony\Component\Translation\Exception\NotFoundResourceException;
17
use Symfony\Component\Config\Resource\FileResource;
18
use Translation\SymfonyStorage\Loader\XliffLoader;
19
20
/**
21
 * XliffFileLoader loads translations from XLIFF files.
22
 *
23
 * @author Tobias Nyholm <[email protected]>
24
 */
25
final class FlysystemXliffLoader extends XliffLoader
26
{
27
    /**
28
     * @var Filesystem
29
     */
30
    private $filesystem;
31
32
    /**
33
     * @param Filesystem filesystem
34
     */
35 1
    public function __construct(Filesystem $filesystem)
36
    {
37 1
        $this->filesystem = $filesystem;
38 1
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function load($resource, $locale, $domain = 'messages')
44
    {
45
        if (!$this->filesystem->has($resource)) {
46
            throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
47
        }
48
49
        $catalogue = new MessageCatalogue($locale);
50
        $this->extractFromContent($this->filesystem->read($resource), $catalogue, $domain);
0 ignored issues
show
Security Bug introduced by
It seems like $this->filesystem->read($resource) targeting League\Flysystem\Filesystem::read() can also be of type false; however, Translation\SymfonyStora...r::extractFromContent() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
51
52
        if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
53
            $catalogue->addResource(new FileResource($resource));
54
        }
55
56
        return $catalogue;
57
    }
58
}
59