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

CacheDataLogger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A log() 0 3 1
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