[CLEANUP] Add phpDoc to properties in several extensions
[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
17 /**
18 * A class representing a certain status
19 *
20 * @author Ingo Renner <ingo@typo3.org>
21 */
22 class Status {
23
24 const NOTICE = -2;
25 const INFO = -1;
26 const OK = 0;
27 const WARNING = 1;
28 const ERROR = 2;
29
30 /**
31 * @var string
32 */
33 protected $title;
34
35 /**
36 * @var string
37 */
38 protected $value;
39
40 /**
41 * @var string
42 */
43 protected $message;
44
45 /**
46 * @var int
47 */
48 protected $severity;
49
50 /**
51 * Construct a status
52 *
53 * All values must be given as constructor arguments.
54 * All strings should be localized.
55 *
56 * @param string $title Status title, eg. "Deprecation log"
57 * @param string $value Status value, eg. "Disabled"
58 * @param string $message Optional message further describing the title/value combination
59 * Example:, eg "The deprecation log is important and does foo, to disable it do bar"
60 * @param int $severity A severity level. Use one of the constants above!
61 */
62 public function __construct($title, $value, $message = '', $severity = self::OK) {
63 $this->title = (string)$title;
64 $this->value = (string)$value;
65 $this->message = (string)$message;
66 $this->severity = \TYPO3\CMS\Core\Utility\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 return $this->title;
76 }
77
78 /**
79 * Gets the status' value
80 *
81 * @return string
82 */
83 public function getValue() {
84 return $this->value;
85 }
86
87 /**
88 * Gets the status' message (if any)
89 *
90 * @return string
91 */
92 public function getMessage() {
93 return $this->message;
94 }
95
96 /**
97 * Gets the status' severity
98 *
99 * @return int
100 */
101 public function getSeverity() {
102 return $this->severity;
103 }
104
105 /**
106 * Creates a string representation of a status.
107 *
108 * @return string String representation of this status.
109 */
110 public function __toString() {
111 $severity = array(
112 self::NOTICE => 'NOTE',
113 self::INFO => 'INFO',
114 self::OK => 'OK',
115 self::WARNING => 'WARN',
116 self::ERROR => 'ERR'
117 );
118 // Max length 80 characters
119 $stringRepresentation = str_pad(('[' . $severity[$this->severity] . ']'), 7) . str_pad($this->title, 40) . ' - ' . substr($this->value, 0, 30);
120 return $stringRepresentation;
121 }
122
123 }