Failed Conditions
Push — master ( ff7329...d32c3b )
by Sylvain
02:29
created

Format::removeAccents()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 338
Code Lines 314

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 314
nc 2
nop 1
dl 0
loc 338
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix;
6
7
use Money\Currencies\ISOCurrencies;
8
use Money\Formatter\DecimalMoneyFormatter;
9
use Money\Money;
10
11
abstract class Format
12
{
13
    /**
14
     * Truncate a string and append '…' at the end
15
     *
16
     * @param string $ellipsis the string to indicate truncation happened
17
     *
18
     * @return string truncated string
19
     */
20 5
    public static function truncate(string $string, int $maxLength, string $ellipsis = '…'): string
21
    {
22 5
        if (mb_strlen($string) > $maxLength) {
23 3
            $string = mb_substr($string, 0, $maxLength - mb_strlen($ellipsis));
24 3
            $string .= $ellipsis;
25
        }
26
27 5
        return $string;
28
    }
29
30
    /**
31
     * Shortcut to format money
32
     */
33
    public static function money(Money $money): string
34
    {
35
        $currencies = new ISOCurrencies();
36
        $moneyFormatter = new DecimalMoneyFormatter($currencies);
37
38
        return $moneyFormatter->format($money);
39
    }
40
}
41