DewPoint::calc()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @package Forecast\Models
7
 * @author  Sergey V.Kuzin <[email protected]>
8
 * @license MIT
9
 */
10
declare(strict_types=1);
11
namespace Forecast\Models;
12
13
14
class DewPoint
15
{
16
    /** @var float  */
17
    protected $temp = null;
18
    /** @var float  */
19
    protected $humidity = null;
20
21
    /**
22
     * @return float
23
     */
24 2
    public function getTemp(): float
25
    {
26 2
        return $this->temp;
27
    }
28
29
    /**
30
     * @param float $temp
31
     */
32 2
    public function setTemp(float $temp): self
33
    {
34 2
        $this->temp = $temp;
35 2
        return $this;
36
    }
37
38
    /**
39
     * @return float
40
     */
41 2
    public function getHumidity(): float
42
    {
43 2
        return $this->humidity;
44
    }
45
46
    /**
47
     * @param float $humidity
48
     */
49 2
    public function setHumidity(float $humidity): self
50
    {
51 2
        $this->humidity = $humidity;
52 2
        return $this;
53
    }
54
55
    /**
56
     * @return float
57
     */
58 1
    public function calc(): float
59
    {
60 1
        $a = 17.27;
61 1
        $b = 237.7;
62 1
        $t = $this->getTemp();
63
64 1
        $humidity = $this->getHumidity() / 100;
65
66 1
        $a1 = ($a * $t) / ($b + $t);
67 1
        $b1 = log($humidity);
68
69 1
        $dewPoint = ($b * ( $a1 + $b1)) / ( $a - ($a1 + $b1));
70
71 1
        return $dewPoint;
72
    }
73
}
74