Completed
Push — master ( 7a5cb9...59abba )
by Hannes
02:54
created

AbstractResourceReader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 51
ccs 19
cts 19
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
readHeader() 0 1 ?
getElevationFor() 0 1 ?
A __construct() 0 6 2
A __destruct() 0 4 1
A setResource() 0 10 2
A closeResource() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the Runalyze DEM Reader.
5
 *
6
 * (c) RUNALYZE <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Runalyze\DEM\Provider;
13
14
use Runalyze\DEM\Exception\RuntimeException;
15
16
abstract class AbstractResourceReader implements ResourceReaderInterface
17
{
18
    /** @var resource|bool */
19
    protected $FileResource = false;
20
21
    /**
22
     * @param resource|bool $resource
23
     */
24 16
    public function __construct($resource = false)
25
    {
26 16
        if (false !== $resource) {
27 1
            $this->setResource($resource);
28 1
        }
29 16
    }
30
31 3
    public function __destruct()
32
    {
33 3
        $this->closeResource();
34 3
    }
35
36
    /**
37
     * @param  resource         $resource
38
     * @throws RuntimeException
39
     */
40 9
    public function setResource($resource)
41
    {
42 9
        $this->closeResource();
43
44 9
        $this->FileResource = $resource;
45
46 9
        if (false === $this->FileResource) {
47 1
            throw new RuntimeException('Provided resource is invalid.');
48
        }
49 8
    }
50
51 10
    protected function closeResource()
52
    {
53 10
        if (is_resource($this->FileResource)) {
54 1
            fclose($this->FileResource);
55 1
        }
56 10
    }
57
58
    abstract public function readHeader();
59
60
    /**
61
     * @param  int      $row
62
     * @param  int      $col
63
     * @return int|bool elevation [m] can be false if nothing retrieved or value is unknown
64
     */
65
    abstract public function getElevationFor($row, $col);
66
}
67