Precipitation   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 21.43 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 0
dl 15
loc 70
ccs 0
cts 18
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getIntensity() 0 4 1
A getProbability() 0 4 1
A getType() 0 4 1
A __toString() 0 4 1
A setData() 15 15 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @package Forecast\Model
7
 * @author  Sergey V.Kuzin <[email protected]>
8
 * @license MIT
9
 */
10
declare(strict_types=1);
11
namespace Forecast\Model;
12
13
14
use Forecast\ForecastItemInterface;
15
16
class Precipitation implements ModelInterface
17
{
18
    /** @var  int */
19
    protected $probability;
20
21
    /** @var  float */
22
    protected $intensity;
23
24
    /** @var  float */
25
    protected $accumulation;
26
27
28
29
    /** @var  string */
30
    protected $type;
31
32
    /**
33
     * @return mixed
34
     */
35
    public function getIntensity()
36
    {
37
        return $this->intensity;
38
    }
39
40
    /**
41
     * @return mixed
42
     */
43
    public function getProbability()
44
    {
45
        return $this->probability;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getType()
52
    {
53
        return $this->type;
54
    }
55
56
    /**
57
     * @api
58
     *
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        return 'Вероятность дождя ' . $this->probability . '%';
64
    }
65
66
    /**
67
     * @param array $data
68
     * @return $this
69
     */
70 View Code Duplication
    public function setData(array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        if (
73
            !($trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)) ||
74
            !(isset($trace[1]['class']) && in_array(ForecastItemInterface::class, class_implements($trace[1]['class'])))
75
        ) {
76
            trigger_error('Member not available: setData', E_USER_ERROR);
77
        }
78
79
        $this->intensity = $data['intensity'];
80
        $this->probability = $data['probability'];
81
        $this->type = $data['type'];
82
83
        return $this;
84
    }
85
}
86