Helpers::date_fmt()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 4
rs 10
1
<?php
2
namespace WagnerMontanini\LayoutSyspdv;
3
4
use DateTime;
5
6
abstract class Helpers
7
{
8
9
    /**
10
     * Helper constructor.
11
     */
12
     public function __construct()
13
     {
14
 
15
     }
16
 
17
     /**
18
     * @param string $string
19
     * @param int $limit
20
     * @return string
21
     */
22
     protected function str_limit_chars(string $string, int $limit): string
23
     {
24
         $string = trim(filter_var($string, FILTER_SANITIZE_SPECIAL_CHARS));
25
         if (mb_strlen($string) <= $limit) {
26
             return $string;
27
         }
28
 
29
         $chars = mb_substr($string, 0, mb_strrpos(mb_substr($string, 0, $limit), "&nbsp"));
30
         return $chars;
31
     }
32
 
33
     /**
34
     * @param string $input
35
     * @param int $pad_length
36
     * @param string $pad_string
37
     * @param int $pad_style
38
     * @param string $encoding
39
     * @return string
40
     */
41
     protected function mb_str_pad(string $input, int $pad_length, string $pad_string=" ", int $pad_style=STR_PAD_RIGHT, string $encoding="UTF-8"): string
42
     {
43
         return str_pad($input, strlen($input)-mb_strlen($input,$encoding)+$pad_length, $pad_string, $pad_style);
44
     } 
45
 
46
     /**
47
     * @param string $date
48
     * @param string $format
49
     * @return string
50
     * @throws Exception
51
     */
52
     protected function date_fmt(?string $date, string $format = "Ymd"): string
53
     {
54
         $date = (empty($date) ? "now" : $date);
55
         return (new DateTime($date))->format($format);
56
     }
57
}
58
59
60