File   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 27
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 5
1
<?php
2
3
/**
4
 * This file is part of the Apix Project.
5
 *
6
 * (c) Franck Cassedanne <franck at ouarz.net>
7
 *
8
 * @license http://opensource.org/licenses/BSD-3-Clause  New BSD License
9
 */
10
11
namespace Apix\Log\Logger;
12
13
use Psr\Log\InvalidArgumentException;
14
15
/**
16
 * Minimalist file based PSR-3 logger relying on PHP's error_log().
17
 *
18
 * @author Franck Cassedanne <franck at ouarz.net>
19
 */
20
class File extends ErrorLog
21
{
22
23
    /**
24
     * Constructor.
25
     *
26
     * @param  string $file The file to append to.
27
     * @throws InvalidArgumentException If the file cannot be created or written.
28
     */
29 180
    public function __construct($file)
30
    {
31 180
        if (null === $file || !file_exists($file) && !touch($file)) {
32 4
            throw new InvalidArgumentException(
33 4
                sprintf('Log file "%s" cannot be created', $file), 1
34 1
            );
35
        }
36 176
        if (!is_writable($file)) {
37 4
            throw new InvalidArgumentException(
38 4
                sprintf('Log file "%s" is not writable', $file), 2
39 1
            );
40
        }
41
42 172
        $this->destination = $file;
43 172
        $this->type = static::FILE;
44 43
    }
45
46
}
47