Completed
Pull Request — master (#31)
by
unknown
02:02
created

FileReader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A readTranslation() 0 4 1
A readStream() 0 13 3
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