GetRegExpForPatternTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRegExpForPattern() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Crossjoin\Browscap\Source\Ini;
5
6
/**
7
 * Trait GetRegExpForPatternTrait
8
 *
9
 * @package Crossjoin\Browscap\Source\Ini
10
 * @author Christoph Ziegenberg <[email protected]>
11
 * @link https://github.com/crossjoin/browscap
12
 */
13
trait GetRegExpForPatternTrait
14
{
15
    /**
16
     * @param string $pattern
17
     *
18
     * @return string
19
     */
20
    protected function getRegExpForPattern(string $pattern) : string
21
    {
22
        $patternReplaced = str_replace(['*', '?'], ["\nA\n", "\nQ\n"], $pattern);
23
        $patternReplaced = preg_quote($patternReplaced, '/');
24
        $patternReplaced = str_replace(["\nA\n", "\nQ\n"], ['.*', '.'], $patternReplaced);
25
26
        return '/^' . $patternReplaced . '$/';
27
    }
28
}
29