MoneyFormat   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 140
Duplicated Lines 31.43 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 44
loc 140
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A default() 0 4 1
A fromParameters() 13 13 1
A fromParametersWithPrecision() 16 16 1
A fromParametersWithExtraPrecision() 15 15 1
A getDecimalsSeparator() 0 4 1
A getThousandsSeparator() 0 4 1
A getExtraPrecision() 0 4 1
A getDecorationType() 0 4 1
A getPrecision() 0 4 1
A getDecorationSpace() 0 4 1

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
namespace Adsmurai\Currency;
4
5
use Adsmurai\Currency\Contracts\MoneyFormat as MoneyFormatInterface;
6
7
final class MoneyFormat implements MoneyFormatInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $decimalsSeparator;
13
    /**
14
     * @var string
15
     */
16
    private $thousandsSeparator;
17
    /**
18
     * @var int
19
     */
20
    private $extraPrecision;
21
    /**
22
     * @var int
23
     */
24
    private $decorationType;
25
    /**
26
     * @var int
27
     */
28
    private $precision;
29
    /**
30
     * @var int
31
     */
32
    private $decorationSpace;
33
34
    private function __construct(
35
        string $decimalsSeparator = self::DEFAULT_DECIMALS_SEPARATOR,
36
        string $thousandsSeparator = self::DEFAULT_THOUSANDS_SEPARATOR,
37
        int $decorationType = self::DECORATION_SYMBOL,
38
        int $decorationSpace = self::DECORATION_WITHOUT_SPACE,
39
        int $extraPrecision = 0,
40
        int $precision = null
41
    ) {
42
        $this->decimalsSeparator = $decimalsSeparator;
43
        $this->thousandsSeparator = $thousandsSeparator;
44
        $this->extraPrecision = $extraPrecision;
45
        $this->decorationType = $decorationType;
46
        $this->precision = $precision;
47
        $this->decorationSpace = $decorationSpace;
48
    }
49
50
    public static function default(): MoneyFormatInterface
51
    {
52
        return new self();
53
    }
54
55 View Code Duplication
    public static function fromParameters(
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...
56
        string $decimalsSeparator = self::DEFAULT_DECIMALS_SEPARATOR,
57
        string $thousandsSeparator = self::DEFAULT_THOUSANDS_SEPARATOR,
58
        int $decorationType = self::DECORATION_SYMBOL,
59
        int $decorationSpace = self::DECORATION_WITHOUT_SPACE
60
    ): MoneyFormatInterface {
61
        return new self(
62
            $decimalsSeparator,
63
            $thousandsSeparator,
64
            $decorationType,
65
            $decorationSpace
66
        );
67
    }
68
69 View Code Duplication
    public static function fromParametersWithPrecision(
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...
70
        int $precision,
71
        string $decimalsSeparator = self::DEFAULT_DECIMALS_SEPARATOR,
72
        string $thousandsSeparator = self::DEFAULT_THOUSANDS_SEPARATOR,
73
        int $decorationType = self::DECORATION_SYMBOL,
74
        int $decorationSpace = self::DECORATION_WITHOUT_SPACE
75
    ): MoneyFormatInterface {
76
        return new self(
77
            $decimalsSeparator,
78
            $thousandsSeparator,
79
            $decorationType,
80
            $decorationSpace,
81
            0,
82
            $precision
83
        );
84
    }
85
86 View Code Duplication
    public static function fromParametersWithExtraPrecision(
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...
87
        int $extraPrecision,
88
        string $decimalsSeparator = self::DEFAULT_DECIMALS_SEPARATOR,
89
        string $thousandsSeparator = self::DEFAULT_THOUSANDS_SEPARATOR,
90
        int $decorationType = self::DECORATION_SYMBOL,
91
        int $decorationSpace = self::DECORATION_WITHOUT_SPACE
92
    ): MoneyFormatInterface {
93
        return new self(
94
            $decimalsSeparator,
95
            $thousandsSeparator,
96
            $decorationType,
97
            $decorationSpace,
98
            $extraPrecision
99
        );
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getDecimalsSeparator(): string
106
    {
107
        return $this->decimalsSeparator;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getThousandsSeparator(): string
114
    {
115
        return $this->thousandsSeparator;
116
    }
117
118
    /**
119
     * @return int
120
     */
121
    public function getExtraPrecision(): int
122
    {
123
        return $this->extraPrecision;
124
    }
125
126
    /**
127
     * @return int
128
     */
129
    public function getDecorationType(): int
130
    {
131
        return $this->decorationType;
132
    }
133
134
    /**
135
     * @return int|null
136
     */
137
    public function getPrecision()
138
    {
139
        return $this->precision;
140
    }
141
142
    public function getDecorationSpace(): int
143
    {
144
        return $this->decorationSpace;
145
    }
146
}
147