Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Frmtr
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 getLocale
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 setLocale
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 format
n/a
0 / 0
n/a
0 / 0
0
1<?php
2
3/**
4 * @author: Doug Wilbourne (dougwilbourne@gmail.com)
5 */
6
7declare(strict_types=1);
8
9namespace pvc\frmtr;
10
11use pvc\frmtr\err\UnsetLocaleException;
12use pvc\interfaces\frmtr\FrmtrInterface;
13use pvc\interfaces\intl\LocaleInterface;
14
15/**
16 * Class Frmtr
17 *
18 * The underlying icu formatters that this class uses all have a method called 'setPattern', which allows you to
19 * customize the exact formatting of the value(s) so that it deviates from the 'standard pattern' which is indicated
20 * by the locale.  This set of classes is meant to do nothing more than provide quick and easy formatting according
21 * to the locale defaults, resulting in a narrow interface which should fit the vast majority of use cases.  If you
22 * need the flexibiity of customizing a pattern, then just use the appropriate underlying icu formatter (e.g.
23 * NumberFormatter, IntlDateFormatter and MessageFormatter).
24 *
25 * @template DataType
26 * @implements FrmtrInterface<DataType>
27 */
28abstract class Frmtr implements FrmtrInterface
29{
30    protected LocaleInterface $locale;
31
32    /**
33     * getLocale
34     * @return LocaleInterface
35     */
36    public function getLocale(): LocaleInterface
37    {
38        if (!isset($this->locale)) {
39            throw new UnsetLocaleException();
40        }
41        return $this->locale;
42    }
43
44    /**
45     * setLocale
46     * @param LocaleInterface $locale
47     */
48    public function setLocale(LocaleInterface $locale): void
49    {
50        $this->locale = $locale;
51    }
52
53    /**
54     * format
55     * @param DataType $value
56     * @return string
57     */
58    abstract public function format($value): string;
59}