BeaufortWindScale   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 78
ccs 36
cts 36
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getWind() 0 4 1
A setWind() 0 8 2
C calc() 0 34 14
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
/**
15
 * Class BeaufortWindScale
16
 *
17
 * Возвращает силу ветра в балах по шкале Бофорта в зависимости от скорости ветра
18
 * @see https://en.wikipedia.org/wiki/Beaufort_scale
19
 *
20
 * PHP version 5.5
21
 *
22
 * @package Forecast\Models
23
 * @author  Sergey V.Kuzin <[email protected]>
24
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
25
 *
26
 */
27
class BeaufortWindScale
28
{
29
    const BWS_CALM            = 0;
30
    const BWS_LIGHT_AIR       = 1;
31
    const BWS_LIGHT_BREEZE    = 2;
32
    const BWS_GENTLE_BREEZE   = 3;
33
    const BWS_MODERATE_BREEZE = 4;
34
    const BWS_FRESH_BREEZE    = 5;
35
    const BWS_STRONG_BREEZE   = 6;
36
    const BWS_HIGH_WIND       = 7;
37
    const BWS_FRESH_GALE      = 8;
38
    const BWS_STRONG          = 9;
39
    const BWS_WHOLE_GALE      = 10;
40
    const BWS_VIOLENT_STORM   = 11;
41
    const BWS_HURRICANE_FORCE = 12;
42
43
44
    /** @var double $wind скорость ветра в м/с */
45
    private $wind = 0;
46
47
    /**
48
     * @return float
49
     */
50 2
    public function getWind(): float
51
    {
52 2
        return $this->wind;
53
    }
54
55
    /**
56
     * @param float $wind
57
     */
58 3
    public function setWind(float $wind): self
59
    {
60 3
        if ($wind < 0) {
61 1
            throw new \InvalidArgumentException('Значение $windSpeed < 0');
62
        }
63 2
        $this->wind = $wind;
64 2
        return $this;
65
    }
66
67 1
    /**
68
     * @return int
69 1
     */
70
    public function calc(): int
71 1
    {
72 1
        $wind = $this->getWind();
73 1
74 1
        if ($wind >= 0 && $wind < 0.3) {
75 1
            $number = self::BWS_CALM;
76 1
        } elseif ($wind <= 1.5) {
77 1
            $number = self::BWS_LIGHT_AIR;
78 1
        } elseif ($wind <= 3.3) {
79 1
            $number = self::BWS_LIGHT_BREEZE;
80 1
        } elseif ($wind <= 5.5) {
81 1
            $number = self::BWS_GENTLE_BREEZE;
82 1
        } elseif ($wind <= 8.0) {
83 1
            $number = self::BWS_MODERATE_BREEZE;
84 1
        } elseif ($wind <= 10.8) {
85 1
            $number = self::BWS_FRESH_BREEZE;
86 1
        } elseif ($wind <= 13.9) {
87 1
            $number = self::BWS_STRONG_BREEZE;
88 1
        } elseif ($wind <= 17.2) {
89 1
            $number = self::BWS_HIGH_WIND;
90 1
        } elseif ($wind <= 20.7) {
91 1
            $number = self::BWS_FRESH_GALE;
92 1
        } elseif ($wind <= 24.5) {
93 1
                $number = self::BWS_STRONG;
94 1
        } elseif ($wind <= 28.4) {
95 1
            $number = self::BWS_WHOLE_GALE;
96 1
        } elseif ($wind <= 32.6) {
97
            $number = self::BWS_VIOLENT_STORM;
98
        } else {
99 1
            $number = self::BWS_HURRICANE_FORCE;
100
        }
101
102
        return $number;
103
    }
104
}
105