[CLEANUP] Code cleanup in ext:reports
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Status.php
1 <?php
2 namespace TYPO3\CMS\Reports;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Core\Utility\MathUtility;
17
18 /**
19 * A class representing a certain status
20 */
21 class Status
22 {
23 const NOTICE = -2;
24 const INFO = -1;
25 const OK = 0;
26 const WARNING = 1;
27 const ERROR = 2;
28
29 /**
30 * @var string
31 */
32 protected $title;
33
34 /**
35 * @var string
36 */
37 protected $value;
38
39 /**
40 * @var string
41 */
42 protected $message;
43
44 /**
45 * @var int
46 */
47 protected $severity;
48
49 /**
50 * Construct a status
51 *
52 * All values must be given as constructor arguments.
53 * All strings should be localized.
54 *
55 * @param string $title Status title, eg. "Deprecation log"
56 * @param string $value Status value, eg. "Disabled"
57 * @param string $message Optional message further describing the title/value combination
58 * Example:, eg "The deprecation log is important and does foo, to disable it do bar"
59 * @param int $severity A severity level. Use one of the constants above!
60 */
61 public function __construct($title, $value, $message = '', $severity = self::OK)
62 {
63 $this->title = (string)$title;
64 $this->value = (string)$value;
65 $this->message = (string)$message;
66 $this->severity = MathUtility::forceIntegerInRange($severity, self::NOTICE, self::ERROR, self::OK);
67 }
68
69 /**
70 * Gets the status' title
71 *
72 * @return string
73 */
74 public function getTitle()
75 {
76 return $this->title;
77 }
78
79 /**
80 * Gets the status' value
81 *
82 * @return string
83 */
84 public function getValue()
85 {
86 return $this->value;
87 }
88
89 /**
90 * Gets the status' message (if any)
91 *
92 * @return string
93 */
94 public function getMessage()
95 {
96 return $this->message;
97 }
98
99 /**
100 * Gets the status' severity
101 *
102 * @return int
103 */
104 public function getSeverity()
105 {
106 return $this->severity;
107 }
108
109 /**
110 * Creates a string representation of a status.
111 *
112 * @return string String representation of this status.
113 */
114 public function __toString()
115 {
116 $severity = array(
117 self::NOTICE => 'NOTE',
118 self::INFO => 'INFO',
119 self::OK => 'OK',
120 self::WARNING => 'WARN',
121 self::ERROR => 'ERR'
122 );
123 // Max length 80 characters
124 $stringRepresentation = str_pad(('[' . $severity[$this->severity] . ']'), 7) . str_pad($this->title, 40) . ' - ' . substr($this->value, 0, 30);
125 return $stringRepresentation;
126 }
127 }