Completed
Push — master ( 784a42...226f28 )
by Gjero
03:03
created

File   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A open() 0 10 2
1
<?php
2
/**
3
 * Pimf
4
 *
5
 * @copyright Copyright (c)  Gjero Krsteski (http://krsteski.de)
6
 * @license   http://opensource.org/licenses/MIT MIT License
7
 */
8
9
namespace Pimf\Adapter;
10
11
use Pimf\Contracts\Streamable;
12
13
/**
14
 * Class File binds a named resource, specified by filename, to a stream.
15
 *
16
 * @package Pimf\Adapter
17
 */
18
class File implements Streamable
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $storageDir;
24
25
    /**
26
     * @var string
27
     */
28
    protected $fileName;
29
30
    /**
31
     * Specifies the type of access you require to the stream
32
     * @see http://php.net/manual/en/function.fopen.php#mode
33
     * @var string
34
     */
35
    protected $mode;
36
37
    /**
38
     * @param string $storageDir
39
     * @param string $fileName
40
     * @param string $mode
41
     */
42
    public function __construct($storageDir, $fileName = "pimf-logs.txt", $mode = "at+")
43
    {
44
        $this->storageDir = $storageDir;
45
        $this->fileName = $fileName;
46
        $this->mode = $mode;
47
    }
48
49
    /* @inheritdoc */
50
    public function open()
51
    {
52
        if (!is_dir($this->storageDir)) {
53
            mkdir($this->storageDir, 0777);
54
        }
55
56
        $this->storageDir = rtrim(realpath($this->storageDir), '\\/') . DS;
57
58
        return fopen($this->storageDir . $this->fileName, $this->mode);
59
    }
60
}