Passed
Push — master ( 7cbfe3...bc244d )
by Krisztián
05:18
created

CacheDataLogger::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * All rights reserved © 2018 Legow Hosting Kft.
5
 */
6
7
namespace PhpCache\Example\Logger;
8
9
/**
10
 * Description of CacheDataLogger.
11
 *
12
 * @author kdudas
13
 */
14
class CacheDataLogger
15
{
16
    private $logFilePath;
17
    private $logFileDir;
18
19
    public function __construct($logFilePath)
20
    {
21
        $this->logFilePath = $logFilePath;
22
        $pathParts = explode('/', $logFilePath);
23
        if (count($pathParts) > 1) {
24
            unset($pathParts[count($pathParts) - 1]);
25
            $this->logFileDir = implode('/', $pathParts);
26
            if (!file_exists($this->logFileDir)) {
27
                mkdir($this->logFileDir);
28
            }
29
        }
30
    }
31
32
    public function log($entry)
33
    {
34
        return file_put_contents($this->logFilePath, $entry."\n", FILE_APPEND);
35
    }
36
}
37