Completed
Branch releases/v0.2 (d913c4)
by Luke
02:17
created

IsSeekable::assertIsSeekable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 2
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
use CSVelte\Exception\NotYetImplementedException;
18
19
/**
20
 * IO IsSeekable Trait.
21
 *
22
 * Seek methods shared between CSVelte\IO classes.
23
 *
24
 * @package    CSVelte
25
 * @subpackage CSVelte\Traits
26
 * @copyright  (c) 2016, Luke Visinoni <[email protected]>
27
 * @author     Luke Visinoni <[email protected]>
28
 * @since      v0.2
29
 */
30
trait IsSeekable
31
{
32
    /**
33
     * Seek to specific line (beginning).
34
     *
35
     * Seek to the line specified by $offset, starting from the $whence line.
36
     *
37
     * @param int $offset Offset to seek to
38
     * @param int $whence Position from whence to seek from
39
     * @param string $eol The line terminator string/char
40
     * @return boolean True if successful
41
     * @throws CSVelte\Exception\NotYetImplementedException because it isn't
42
     *     implemented yet
43
     */
44 1
    public function seekLine($offset, $whence = SEEK_SET, $eol = PHP_EOL)
45
    {
46 1
        throw new NotYetImplementedException("This method not yet implemented.");
47
    }
48
49
    /**
50
     * Assert that this file/stream object is readable.
51
     *
52
     * @return void
53
     * @throws CSVelte\Exception\IOException if stream isn't readable
54
     */
55 3
    protected function assertIsSeekable()
56
    {
57 3
        if (!$this->isSeekable()) {
58 1
            throw new IOException("Stream not seekable: " . $this->getName(), IOException::ERR_NOT_SEEKABLE);
59
        }
60 2
    }
61
62
    abstract public function getName();
63
64
    abstract public function isSeekable();
65
66
    abstract public function seek($offset, $whence);
67
68
}
69