FileReader::readTranslation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Akeneo\Crowdin;
4
5
/**
6
 * Reads a stream from the translation local file path
7
 *
8
 * @author Nicolas Dupont <[email protected]>
9
 */
10
class FileReader
11
{
12
    /**
13
     * @param Translation $translation
14
     *
15
     * @throw FileNotFoundException
16
     *
17
     * @return resource
18
     */
19
    public function readTranslation(Translation $translation)
20
    {
21
        return $this->readStream($translation->getLocalPath());
22
    }
23
24
    /**
25
     * @throw FileNotFoundException
26
     *
27
     * @return resource
28
     */
29
    protected function readStream($filename)
30
    {
31
        if (!file_exists($filename)) {
32
            throw new FileNotFoundException(sprintf('The file "%s" does not exists.', $filename));
33
        }
34
35
        $stream = fopen($filename, 'r');
36
        if (!$stream) {
37
            throw new FileNotFoundException(sprintf('The file "%s" can\'t be opened.', $filename));
38
        }
39
40
        return $stream;
41
    }
42
}
43