Passed
Push — 4.x ( b027a1...820cf2 )
by Kit Loong
62:09
created

Regex   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 30
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTextBetween() 0 7 2
A getTextBetweenAll() 0 7 2
1
<?php
2
3
namespace KitLoong\MigrationsGenerator\Support;
4
5
class Regex
6
{
7
    /**
8
     * @param  string  $text
9
     * @param  string  $left
10
     * @param  string  $right
11
     * @return string|null
12
     */
13
    public function getTextBetween(string $text, string $left = '\(', string $right = '\)'): ?string
14
    {
15
        $matched = preg_match('/'.$left.'(.*?)'.$right.'/', $text, $output);
16
        if ($matched === 1) {
17
            return $output[1];
18
        }
19
        return null;
20
    }
21
22
    /**
23
     * @param  string  $text
24
     * @param  string  $left
25
     * @param  string  $right
26
     * @return array|null|string[]
27
     */
28
    public function getTextBetweenAll(string $text, string $left = '\(', string $right = '\)'): ?array
29
    {
30
        $matched = preg_match_all('/'.$left.'(.*?)'.$right.'/', $text, $output);
31
        if ($matched > 0) {
32
            return $output[1];
33
        }
34
        return null;
35
    }
36
}
37