Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
FrmtrBoolean
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFormat
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFormat
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 format
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * @author Doug Wilbourne (dougwilbourne@gmail.com)
5 */
6
7declare(strict_types=1);
8
9namespace pvc\frmtr\boolean;
10
11use pvc\frmtr\Frmtr;
12use pvc\interfaces\frmtr\bool\FrmtrBooleanInterface;
13use pvc\interfaces\frmtr\msg\FrmtrMsgInterface;
14use pvc\interfaces\msg\MsgInterface;
15
16/**
17 * Class FrmtrBoolean
18 * @extends Frmtr<bool>
19 * Formats a boolean value into any one of several valid Formats.
20 */
21class FrmtrBoolean extends Frmtr implements FrmtrBooleanInterface
22{
23    /**
24     * @var string
25     *
26     * The 'format' string is the msgId in the messages data store.  For example, there are msgIds such as
27     * 'yes_no' and 'true_false'.  This preserves the language-neutral character of this class.
28     */
29    protected string $format;
30
31    /**
32     * FrmtrBoolean constructor.
33     * @param string $format
34     */
35    public function __construct(/**
36     * @var MsgInterface
37     * outputting a word for true or false (yes / no, etc) should be done in a language neutral way, so we use the Msg
38     * library.
39     */
40    protected MsgInterface $msg, protected FrmtrMsgInterface $msgFrmtr, string $format = 'yes')
41    {
42        $this->setFormat($format);
43    }
44
45    /**
46     * @function setFormat
47     * @param string $format
48     * there is no error checking the format (msgId) at this point.  When it comes time to output the message, the
49     * message library will throw an exception if the msgId cannot be found in the messages store.
50     */
51    public function setFormat(string $format): void
52    {
53        $this->format = $format;
54    }
55
56    /**
57     * @function getFormat
58     * @return string
59     */
60    public function getFormat(): string
61    {
62        return $this->format;
63    }
64
65    /**
66     * @function formatValue
67     * @param bool $value
68     * @return string
69     */
70    public function format($value): string
71    {
72        $domain = 'formatter';
73        $msgId = $this->getFormat();
74        $parameters = ['true_false' => ($value ? 'true' : 'false')];
75        $this->msg->setContent($domain, $msgId, $parameters);
76        return $this->msgFrmtr->format($this->msg);
77    }
78}