Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Mail
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
0.00% covered (danger)
0.00%
0 / 1
 getDisplayMessage
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
1<?php
2
3/**
4 * Mail Exception
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2011-2023.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Exceptions
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development Wiki
28 */
29
30namespace VuFind\Exception;
31
32/**
33 * Mail Exception
34 *
35 * @category VuFind
36 * @package  Exceptions
37 * @author   Demian Katz <demian.katz@villanova.edu>
38 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
39 * @link     https://vufind.org/wiki/development Wiki
40 */
41class Mail extends \Exception
42{
43    /**
44     * Default error message when the error is not known exactly.
45     * Will return $defaultDisplayMessage if APPLICATION_ENV is not development.
46     *
47     * @var int
48     */
49    public const ERROR_UNKNOWN = 0;
50
51    /**
52     * Mail recipient address is invalid.
53     *
54     * @var int
55     */
56    public const ERROR_INVALID_RECIPIENT = 1;
57
58    /**
59     * Mail sender address is invalid.
60     *
61     * @var int
62     */
63    public const ERROR_INVALID_SENDER = 2;
64
65    /**
66     * Mail reply to address is invalid.
67     *
68     * @var int
69     */
70    public const ERROR_INVALID_REPLY_TO = 3;
71
72    /**
73     * Mail too many recipients.
74     *
75     * @var int
76     */
77    public const ERROR_TOO_MANY_RECIPIENTS = 4;
78
79    /**
80     * Safe error message to return
81     *
82     * @var string
83     */
84    protected $defaultDisplayMessage = 'email_failure';
85
86    /**
87     * Returns the error message, but excludes too technical messages.
88     *
89     * @return string
90     */
91    public function getDisplayMessage(): string
92    {
93        // If application env is development, we can display too technical messages
94        if ('development' === APPLICATION_ENV || $this->getCode() !== self::ERROR_UNKNOWN) {
95            return $this->getMessage();
96        }
97        return $this->defaultDisplayMessage;
98    }
99}