Passed
Push — master ( 199c1a...b4b355 )
by Бабичев
01:42
created

PregMatch::first()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Bavix\Helpers;
4
5
class PregMatch
6
{
7
8
    /**
9
     * @param Results\PregObject|null $object
10
     *
11
     * @return Results\PregObject
12
     */
13 2
    protected static function pregObject(Results\PregObject $object = null): Results\PregObject
14
    {
15 2
        if (!$object)
16
        {
17 1
            return new Results\PregObject();
18
        }
19
20 1
        return $object;
21
    }
22
23
    /**
24
     * @param string                  $pattern
25
     * @param string                  $subject
26
     * @param Results\PregObject|null $object
27
     *
28
     * @return Results\PregObject
29
     */
30 1
    public static function first($pattern, $subject, Results\PregObject $object = null): Results\PregObject
31
    {
32 1
        $object = static::pregObject($object);
33
34 1
        $object->result = \preg_match(
35 1
            $pattern,
36 1
            $subject,
37 1
            $object->matches,
38 1
            $object->flags,
39 1
            $object->offset
40
        );
41
42 1
        return $object;
43
    }
44
45
    /**
46
     * @param string                  $pattern
47
     * @param string                  $subject
48
     * @param Results\PregObject|null $object
49
     *
50
     * @return Results\PregObject
51
     */
52 1
    public static function all($pattern, $subject, Results\PregObject $object = null): Results\PregObject
53
    {
54 1
        $object = static::pregObject($object);
55
56 1
        $object->flags  = null === $object->flags ? $object->flags : PREG_PATTERN_ORDER;
57 1
        $object->result = \preg_match_all(
58 1
            $pattern,
59 1
            $subject,
60 1
            $object->matches,
61 1
            $object->flags,
62 1
            $object->offset
63
        );
64
65 1
        return $object;
66
    }
67
68
}
69