| 1 | <?php |
||
| 9 | trait MonitorPresenter |
||
| 10 | { |
||
| 11 | public function getUptimeStatusAsEmojiAttribute(): string |
||
| 12 | { |
||
| 13 | if ($this->uptime_status === UptimeStatus::UP) { |
||
|
|
|||
| 14 | return Emoji::ok(); |
||
| 15 | } |
||
| 16 | |||
| 17 | if ($this->uptime_status === UptimeStatus::DOWN) { |
||
| 18 | return Emoji::notOk(); |
||
| 19 | } |
||
| 20 | |||
| 21 | return ''; |
||
| 22 | } |
||
| 23 | |||
| 24 | public function getCertificateStatusAsEmojiAttribute(): string |
||
| 25 | { |
||
| 26 | if ($this->certificate_status === CertificateStatus::VALID) { |
||
| 27 | return Emoji::ok(); |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($this->certificate_status === CertificateStatus::INVALID) { |
||
| 31 | return Emoji::notOk(); |
||
| 32 | } |
||
| 33 | |||
| 34 | return ''; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function getFormattedLastUpdatedStatusChangeDateAttribute(): string |
||
| 41 | |||
| 42 | public function getFormattedCertificateExpirationDateAttribute(): string |
||
| 43 | { |
||
| 44 | return $this->formatDate('certificate_expiration_date'); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getChunkedLastFailureReasonAttribute(): string |
||
| 55 | |||
| 56 | public function getChunkedLastCertificateCheckFailureReasonAttribute(): string |
||
| 57 | { |
||
| 58 | if ($this->certificate_check_failure_reason == '') { |
||
| 59 | return ''; |
||
| 60 | } |
||
| 61 | |||
| 62 | return chunk_split($this->certificate_check_failure_reason, 60, "\n"); |
||
| 63 | } |
||
| 64 | |||
| 65 | protected function formatDate(string $attributeName): string |
||
| 73 | } |
||
| 74 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: