Conditions | 2 |
Paths | 2 |
Total Lines | 14 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | 10 | public function execute(string $value, int $count, string $suffix = '..') |
|
18 | { |
||
19 | 10 | $value = \strip_tags($value); |
|
20 | |||
21 | 10 | $sentences = \preg_split('/(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\?)\s/um', \trim($value), null, PREG_SPLIT_DELIM_CAPTURE); |
|
22 | |||
23 | $sentences = array_map(function($value) { |
||
24 | 10 | return trim($value); |
|
25 | 10 | }, $sentences); |
|
|
|||
26 | |||
27 | 10 | if (\count($sentences) > $count) { |
|
28 | 6 | return \implode(' ', \array_slice($sentences, 0, $count)) . $suffix; |
|
29 | } |
||
30 | 5 | return $value; |
|
31 | } |
||
33 |