Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StringValueObjectWithRegexFaker
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fakeFor
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Faker\Fakers;
3
4use Apie\Core\RegexUtils;
5use Apie\Core\ValueObjects\Interfaces\HasRegexValueObjectInterface;
6use Apie\Faker\Interfaces\ApieClassFaker;
7use Faker\Generator;
8use ReflectionClass;
9use RegRev\RegRev;
10
11/** @implements ApieClassFaker<HasRegexValueObjectInterface> */
12class StringValueObjectWithRegexFaker implements ApieClassFaker
13{
14    public function supports(ReflectionClass $class): bool
15    {
16        return $class->implementsInterface(HasRegexValueObjectInterface::class);
17    }
18
19    public function fakeFor(Generator $generator, ReflectionClass $class): HasRegexValueObjectInterface
20    {
21        $className = $class->name;
22        $regularExpressionWithDelimiter = $className::getRegularExpression();
23        $regex = RegexUtils::removeDelimiters($regularExpressionWithDelimiter);
24        return $className::fromNative(RegRev::generate($regex));
25    }
26}