GaufretteAdapter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 50
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A read() 0 7 2
A write() 0 10 3
1
<?php
2
namespace Balloon\Reader;
3
4
use Gaufrette\Filesystem;
5
6
/**
7
 * Class GaufretteAdapter
8
 * @package Balloon\Reader
9
 * @author Raphaël Lefebvre <[email protected]>
10
 */
11
class GaufretteAdapter implements IFileReader
12
{
13
14
    /**
15
     * @var Filesystem
16
     */
17
    private $gaufrette;
18
19
    /**
20
     * @var string
21
     */
22
    private $filePath;
23
24
    /**
25
     * @param Filesystem $gaufrette
26
     * @param string $filePath
27
     */
28
    public function __construct(Filesystem $gaufrette, $filePath)
29
    {
30
        $this->gaufrette = $gaufrette;
31
        $this->filePath = $filePath;
32
    }
33
34
    /**
35
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
36
     */
37
    public function read()
38
    {
39
        if(!$this->gaufrette->has($this->filePath)){
40
            return '';
41
        }
42
        return $this->gaufrette->read($this->filePath);
43
    }
44
45
    /**
46
     * @param mixed $data
47
     * @param int $mode
48
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
49
     */
50
    public function write($data, $mode = 0)
51
    {
52
        if($mode & FILE_APPEND){
53
            $data = $this->read() . $data;
54
        }
55
        if(!$this->gaufrette->has($this->filePath)){
56
            $this->gaufrette->createFile($this->filePath);
57
        }
58
        return $this->gaufrette->write($this->filePath, $data, true);
59
    }
60
}
61