Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
SharedRegularExpression
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 getDelimiter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getModifiers
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 createRandom
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\RegexValueObjects;
3
4use Faker\Generator;
5
6trait SharedRegularExpression
7{
8    public function getDelimiter(): string
9    {
10        return substr($this->internal, 0, 1);
11    }
12
13    public function getModifiers(): string
14    {
15        $delimiter = $this->getDelimiter();
16        return substr($this->internal, 1 + strrpos($this->internal, $delimiter));
17    }
18
19    public static function createRandom(Generator $generator): self
20    {
21        $parts = ['[A-Z]', '[a-z]', '\d', '(yes|no)'];
22        $repeats = ['{1,2}', '*', '+', ''];
23        $count = $generator->numberBetween(1, 8);
24        $content = [];
25        for ($i = 0; $i < $count; $i++) {
26            $content[] = $generator->randomElement($parts);
27            $content[] = $generator->randomElement($repeats);
28        }
29        return new self('/' . implode('', $content) . '/' . $generator->randomElement(['i', 'u', '']));
30    }
31}