Helpers   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A str_limit_chars() 0 9 2
A date_fmt() 0 4 2
A mb_str_pad() 0 3 1
A __construct() 0 2 1
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