1 | <?php |
||
10 | class TruncateStringFilter implements StringFilterInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var bool |
||
14 | */ |
||
15 | protected $wordSafe = false; |
||
16 | |||
17 | /** |
||
18 | * @var int |
||
19 | */ |
||
20 | protected $minWordSafeLength; |
||
21 | |||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | protected $addEllipsis = false; |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | protected $spaceBeforeEllipsis = false; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | protected $sentenceFriendly = false; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $maxLength; |
||
41 | |||
42 | /** |
||
43 | * @param int $maxLength |
||
44 | */ |
||
45 | public function __construct($maxLength) |
||
49 | |||
50 | /** |
||
51 | * @param int $maxLength |
||
52 | */ |
||
53 | public function setMaxLength($maxLength) |
||
57 | |||
58 | /** |
||
59 | * @param bool $toggle |
||
60 | */ |
||
61 | public function addEllipsis($toggle = true) |
||
65 | |||
66 | /** |
||
67 | * @param bool $toggle |
||
68 | */ |
||
69 | public function spaceBeforeEllipsis($toggle = true) |
||
73 | |||
74 | /** |
||
75 | * @param int $minWordSafeLength |
||
76 | */ |
||
77 | public function turnOnWordSafe($minWordSafeLength = 1) |
||
82 | |||
83 | /** |
||
84 | * When turned on, the filter will try not to truncate in the middle of a sentence. |
||
85 | */ |
||
86 | public function beSentenceFriendly() |
||
90 | |||
91 | /** |
||
92 | * @inheritdoc |
||
93 | */ |
||
94 | public function filter($string) |
||
144 | } |
||
145 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.