Completed
Branch releases/v0.2 (da7ff5)
by Luke
02:45
created

IsWritable::getName()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
/**
3
 * CSVelte: Slender, elegant CSV for PHP.
4
 *
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   v0.2
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
 * @copyright  (c) 2016, Luke Visinoni <[email protected]>
26
 * @author     Luke Visinoni <[email protected]>
27
 * @since      v0.2
28
 */
29
trait IsWritable
30
{
31
    /**
32
     * Write single line to file/stream
33
     *
34
     * Writes a line to the file/stream (if it is writable)
35
     *
36
     * @param string $line The line to be written to the stream
37
     * @param string $eol The end of line string
38
     * @return int The number of bytes written to the stream
39
     * @throws CSVelte\Exception\IOException
40
     */
41 12
    public function writeLine($line, $eol = PHP_EOL)
42
    {
43 12
        return $this->write($line . $eol);
44
    }
45
46
    /**
47
     * Assert that this file/stream object is readable.
48
     *
49
     * @return void
50
     * @throws CSVelte\Exception\IOException if stream isn't readable
51
     */
52 13
    protected function assertIsWritable()
53
    {
54 13
        if (!$this->isWritable()) {
55
            throw new IOException("Stream not writable: " . $this->getName(), IOException::ERR_NOT_WRITABLE);
56
        }
57 13
    }
58
59
    abstract public function getName();
60
61
    abstract public function isWritable();
1 ignored issue
show
Best Practice introduced by
Using PHP4-style constructors that are named like the class is not recommend; better use the more explicit __construct method.
Loading history...
62
63
    abstract public function write($str);
64
65
}
66