Failed Conditions
Push — master ( a2282e...ad0b68 )
by Mark
40s queued 35s
created

Scientific   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 5
c 1
b 0
f 0
dl 0
loc 25
ccs 7
cts 7
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 3 2
A getLocaleFormat() 0 3 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
4
5
use PhpOffice\PhpSpreadsheet\Exception;
6
7
class Scientific extends NumberBase implements Wizard
8
{
9
    /**
10
     * @param int $decimals number of decimal places to display, in the range 0-30
11
     * @param ?string $locale Set the locale for the scientific format; or leave as the default null.
12
     *          Locale has no effect for Scientific Format values, and is retained here for compatibility
13
     *              with the other Wizards.
14
     *          If provided, Locale values must be a valid formatted locale string (e.g. 'en-GB', 'fr', uz-Arab-AF).
15
     *
16
     * @throws Exception If a provided locale code is not a valid format
17
     */
18 13
    public function __construct(int $decimals = 2, ?string $locale = null)
19
    {
20 13
        $this->setDecimals($decimals);
21 13
        $this->setLocale($locale);
22
    }
23
24 6
    protected function getLocaleFormat(): string
25
    {
26 6
        return $this->format();
27
    }
28
29 12
    public function format(): string
30
    {
31 12
        return sprintf('0%sE+00', $this->decimals > 0 ? '.' . str_repeat('0', $this->decimals) : null);
32
    }
33
}
34