Passed
Pull Request — master (#183)
by Luke
03:12
created

IsSeekable::seek()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
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
 * @copyright Copyright (c) 2018 Luke Visinoni
10
 * @author    Luke Visinoni <[email protected]>
11
 * @license   See LICENSE file (MIT license)
12
 */
13
namespace CSVelte\Traits;
14
15
use CSVelte\Exception\IOException;
16
use CSVelte\Exception\NotYetImplementedException;
17
18
/**
19
 * IO IsSeekable Trait.
20
 *
21
 * Seek methods shared between CSVelte\IO classes.
22
 */
23
trait IsSeekable
24
{
25
    /**
26
     * Seek to specific line (beginning).
27
     *
28
     * Seek to the line specified by $offset, starting from the $whence line.
29
     *
30
     * @param int    $offset Offset to seek to
31
     * @param int    $whence Position from whence to seek from
32
     * @param string $eol    The line terminator string/char
33
     *
34
     * @throws NotYetImplementedException
35
     *
36
     * @return bool True if successful
37
     */
38 1
    public function seekLine($offset, $whence = SEEK_SET, $eol = PHP_EOL)
39
    {
40 1
        throw new NotYetImplementedException(sprintf(
41 1
            'This method not yet implemented.',
42 1
            $offset,
43 1
            $whence,
44
            $eol // these are simply here to satisfy my code analysis tools
45 1
        ));
46
    }
47
48
    abstract public function isSeekable();
49
50
    abstract public function seek($offset, $whence = SEEK_SET);
51
52
    /**
53
     * Assert that this file/stream object is readable.
54
     *
55
     * @throws IOException
56
     */
57 11
    protected function assertIsSeekable()
58
    {
59 11
        if (!$this->isSeekable()) {
60 2
            throw new IOException('Stream not seekable', IOException::ERR_NOT_SEEKABLE);
61
        }
62 10
    }
63
}
64