IsWritable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
isWritable() 0 1 ?
write() 0 1 ?
A writeLine() 0 4 1
A assertIsWritable() 0 6 2
1
<?php
2
3
/*
4
 * CSVelte: Slender, elegant CSV for PHP
5
 * Inspired by Python's CSV module and Frictionless Data and the W3C's CSV
6
 * standardization efforts, CSVelte was written in an effort to take all the
7
 * suck out of working with CSV.
8
 *
9
 * @version   {version}
10
 * @copyright Copyright (c) 2016 Luke Visinoni <[email protected]>
11
 * @author    Luke Visinoni <[email protected]>
12
 * @license   https://github.com/deni-zen/csvelte/blob/master/LICENSE The MIT License (MIT)
13
 */
14
namespace CSVelte\Traits;
15
16
use CSVelte\Exception\IOException;
17
18
/**
19
 * IO IsWritable Trait.
20
 *
21
 * Write methods shared between CSVelte\IO classes.
22
 *
23
 * @package    CSVelte
24
 * @subpackage CSVelte\Traits
25
 *
26
 * @copyright  (c) 2016, Luke Visinoni <[email protected]>
27
 * @author     Luke Visinoni <[email protected]>
28
 *
29
 * @since      v0.2
30
 */
31
trait IsWritable
32
{
33
    /**
34
     * Write single line to file/stream.
35
     *
36
     * Writes a line to the file/stream (if it is writable)
37
     *
38
     * @param string $line The line to be written to the stream
39
     * @param string $eol  The end of line string
40
     *
41
     * @throws IOException
42
     *
43
     * @return int The number of bytes written to the stream
44
     */
45 15
    public function writeLine($line, $eol = PHP_EOL)
46
    {
47 15
        return $this->write($line . $eol);
48
    }
49
50
    abstract public function isWritable();
51
52
    abstract public function write($str);
53
54
    /**
55
     * Assert that this file/stream object is readable.
56
     *
57
     * @throws IOException
58
     */
59 18
    protected function assertIsWritable()
60
    {
61 18
        if (!$this->isWritable()) {
62 2
            throw new IOException('Stream not writable', IOException::ERR_NOT_WRITABLE);
63
        }
64 16
    }
65
}
66