Months   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 1
cbo 1
dl 30
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A toMilliseconds() 4 4 2

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
 * Loom
4
 * 
5
 * @copyright   Copyright (c) 2014 Warrick Bayman.
6
 * @author		Warrick Bayman <[email protected]>
7
 * @license     MIT License http://opensource.org/licenses/MIT
8
 * 
9
 */
10
11
namespace Loom;
12
13
14
/**
15
 * Class Months
16
 *
17
 * @package Loom
18
 */
19 View Code Duplication
class Months extends AbstractUnit
0 ignored issues
show
Duplication introduced by
This class 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...
20
{
21
    /**
22
     * @var null
23
     */
24
    private $daysPerMonth = null;
25
26
27
    /**
28
     * @param int      $value
29
     * @param int|null $daysPerMonth
30
     */
31
    public function __construct($value, $daysPerMonth = null)
32
    {
33
        parent::__construct($value);
34
35
        $this->daysPerMonth = $daysPerMonth;
0 ignored issues
show
Documentation Bug introduced by
It seems like $daysPerMonth can also be of type integer. However, the property $daysPerMonth is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
36
    }
37
38
39
    /**
40
     * Return the months in milliseconds
41
     *
42
     * @return int
43
     */
44
    public function toMilliseconds()
45
    {
46
        return $this->value * (is_null($this->daysPerMonth) ? 365 / 12 : $this->daysPerMonth) * 24 * 60 * 60 * 1000;
47
    }
48
}
49