Passed
Push — master ( aca0dd...3e5121 )
by Doug
22:36
created

NTv2SubGrid::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 9
dl 0
loc 22
ccs 12
cts 12
cp 1
crap 1
rs 9.9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\CoordinateOperation;
10
11
use SplFileObject;
12
use function unpack;
13
14
class NTv2SubGrid extends SplFileObject
15
{
16
    use BilinearInterpolation;
17
18
    private const RECORD_SIZE = 16;
19
20
    private int $offsetStart;
21
    private string $floatFormatChar;
22
23 5
    public function __construct(
24
        string $filename,
25
        int $offsetStart,
26
        float $minLatitude,
27
        float $maxLatitude,
28
        float $minLongitude,
29
        float $maxLongitude,
30
        float $latitudeInterval,
31
        float $longitudeInterval,
32
        string $floatFormatChar
33
    ) {
34 5
        parent::__construct($filename);
35 5
        $this->offsetStart = $offsetStart;
36 5
        $this->startX = $minLongitude;
37 5
        $this->endX = $maxLongitude;
38 5
        $this->startY = $minLatitude;
39 5
        $this->endY = $maxLatitude;
40 5
        $this->columnGridInterval = $longitudeInterval;
41 5
        $this->rowGridInterval = $latitudeInterval;
42 5
        $this->floatFormatChar = $floatFormatChar;
43 5
        $this->numberOfColumns = (int) (($this->endX - $this->startX) / $this->columnGridInterval);
44 5
        $this->numberOfRows = (int) (($this->endY - $this->startY) / $this->rowGridInterval);
45 5
    }
46
47 5
    public function getRecord(int $longitudeIndex, int $latitudeIndex): GridValues
48
    {
49 5
        $recordIndex = $latitudeIndex * ($this->numberOfColumns + 1) + $longitudeIndex;
50 5
        $recordOffset = $this->offsetStart + ((11 + $recordIndex) * self::RECORD_SIZE);
51 5
        $this->fseek($recordOffset);
52 5
        $rawRecord = $this->fread(self::RECORD_SIZE);
53 5
        $shifts = unpack("{$this->floatFormatChar}LATITUDE_SHIFT/{$this->floatFormatChar}LONGITUDE_SHIFT/{$this->floatFormatChar}LATITUDE_ACCURACY/{$this->floatFormatChar}LONGITUDE_ACCURACY", $rawRecord);
54
55 5
        return new GridValues(
56 5
            $longitudeIndex * $this->columnGridInterval + $this->startX,
57 5
            $latitudeIndex * $this->rowGridInterval + $this->startY,
58 5
            [$shifts['LATITUDE_SHIFT'], $shifts['LONGITUDE_SHIFT']]
59
        );
60
    }
61
}
62