Failed Conditions
Push — master ( b7bcff...572aee )
by
unknown
03:12
created

server/Application/Utility.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application;
6
7
use Cake\Chronos\Chronos;
0 ignored issues
show
The type Cake\Chronos\Chronos was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use DateTimeZone;
9
10
abstract class Utility
11
{
12 42
    public static function dateToJulian(Chronos $date): int
13
    {
14 42
        return gregoriantojd((int) $date->format('m'), (int) $date->format('d'), (int) $date->format('Y'));
15
    }
16
17 41
    public static function julianToDate(int $date): Chronos
18
    {
19 41
        $parts = explode('/', jdtogregorian($date));
20
21 41
        $result = new Chronos('now', new DateTimeZone('UTC'));
22
23 41
        return $result->setDate((int) $parts[2], (int) $parts[0], (int) $parts[1])->setTime(0, 0, 0, 0);
24
    }
25
26 18
    public static function sanitizeRichText(string $string): string
27
    {
28 18
        $sanitized = self::noUnbreakableSpaces(strip_tags($string, '<p><br><strong><em><u>'));
29
30 18
        return $sanitized;
31
    }
32
33 66
    public static function noUnbreakableSpaces(string $string): string
34
    {
35 66
        return str_replace(['&nbsp;', html_entity_decode('&nbsp;')], ' ', $string);
36
    }
37
38 54
    public static function sanitizeSingleLineRichText(string $string): string
39
    {
40 54
        $sanitized = self::noUnbreakableSpaces(strip_tags($string, '<strong><em><u>'));
41
42 54
        return $sanitized;
43
    }
44
45 56
    public static function richTextToPlainText(string $string): string
46
    {
47 56
        return trim(self::noUnbreakableSpaces(html_entity_decode(strip_tags(preg_replace(
48 56
            [
49 56
                '~<br\s*/?>~i',
50 56
                '~<p\s*>~i',
51 56
                '~</p\s*>~i',
52 56
                '~\n{2,}~i',
53 56
            ],
54 56
            [
55 56
                "\n",
56 56
                "\n\n",
57 56
                "\n\n",
58 56
                "\n\n",
59 56
            ],
60 56
            $string
61 56
        )))));
62
    }
63
}
64