Completed
Push — master ( 766aca...d9f01f )
by Nicolas
7s
created

FileReader::readTranslation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
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
     * @return resource
16
     */
17
    public function readTranslation(Translation $translation)
18
    {
19
        return $this->readStream($translation->getLocalPath());
20
    }
21
22
    /**
23
     * @return resource
24
     */
25
    public function readStream($filename)
26
    {
27
        if (!file_exists($filename)) {
28
            throw new FileNotFoundException(sprintf('The file "%s" does not exists.', $filename));
29
        }
30
31
        $stream = fopen($filename, 'r');
32
        if (!$stream) {
33
            throw new FileNotFoundException(sprintf('The file "%s" can\'t be opened.', $filename));
34
        }
35
36
        return $stream;
37
    }
38
}
39