Completed
Pull Request — master (#183)
by Luke
02:49 queued 17s
created

IsSeekable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
isSeekable() 0 1 ?
seek() 0 1 ?
A seekLine() 0 4 1
A assertIsSeekable() 0 6 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
 * @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)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $whence is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $eol is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40 1
        throw new NotYetImplementedException('This method not yet implemented.');
41
    }
42
43
    abstract public function isSeekable();
44
45
    abstract public function seek($offset, $whence = SEEK_SET);
46
47
    /**
48
     * Assert that this file/stream object is readable.
49
     *
50
     * @throws IOException
51
     */
52 7
    protected function assertIsSeekable()
53
    {
54 7
        if (!$this->isSeekable()) {
55 2
            throw new IOException('Stream not seekable', IOException::ERR_NOT_SEEKABLE);
56
        }
57 6
    }
58
}
59