Failed Conditions
Push — master ( 27554e...857869 )
by Luca
09:08
created

Utility::noUnbreakableSpaces()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application;
6
7
use Cake\Chronos\Chronos;
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);
0 ignored issues
show
Bug introduced by
The method setTime() does not exist on Cake\Chronos\ChronosInterface. Did you maybe mean setTimezone()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        return $result->setDate((int) $parts[2], (int) $parts[0], (int) $parts[1])->/** @scrutinizer ignore-call */ setTime(0, 0, 0, 0);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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 67
    public static function noUnbreakableSpaces(string $string): string
34
    {
35 67
        return str_replace(['&nbsp;', html_entity_decode('&nbsp;')], ' ', $string);
36
    }
37
38 55
    public static function sanitizeSingleLineRichText(string $string): string
39
    {
40 55
        $sanitized = self::noUnbreakableSpaces(strip_tags($string, '<strong><em><u>'));
41
42 55
        return $sanitized;
43
    }
44
45 57
    public static function richTextToPlainText(string $string): string
46
    {
47 57
        return trim(self::noUnbreakableSpaces(html_entity_decode(strip_tags(preg_replace(
48 57
            [
49 57
                '~<br\s*/?>~i',
50 57
                '~<p\s*>~i',
51 57
                '~</p\s*>~i',
52 57
                '~\n{2,}~i',
53 57
            ],
54 57
            [
55 57
                "\n",
56 57
                "\n\n",
57 57
                "\n\n",
58 57
                "\n\n",
59 57
            ],
60 57
            $string
61 57
        )))));
62
    }
63
}
64