Passed
Push — feature/html-code-handler ( 5a7209...0228f1 )
by Arnaud
03:23
created

HtmlHandler::isDynamicString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LAG\SmokerBundle\Response\Handler;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Goutte\Client;
7
use LAG\SmokerBundle\Exception\Exception;
8
use LAG\SmokerBundle\Url\Requirements\Mapping\MappingResolverInterface;
9
use Symfony\Component\DomCrawler\Crawler;
10
11
class HtmlHandler extends AbstractHandler
12
{
13
    /**
14
     * @var MappingResolverInterface
15
     */
16
    private $mappingResolver;
17
18
    /**
19
     * @var EntityManagerInterface
20
     */
21
    private $entityManager;
22
23
    public function __construct(
24
        MappingResolverInterface $mappingResolver,
25
        EntityManagerInterface $entityManager,
26
        array $configuration = []
27
    ) {
28
        parent::__construct($configuration);
29
30
        $this->mappingResolver = $mappingResolver;
31
        $this->entityManager = $entityManager;
32
        $this->configuration = $configuration;
33
    }
34
35
    public function handle(string $routeName, Crawler $crawler, Client $client, array $options = []): void
36
    {
37
        $configuration = $this->getConfiguration($routeName);
38
        $mapping = $this->mappingResolver->resolve($this->getMappingName($routeName), $routeName);
0 ignored issues
show
Bug introduced by
It seems like $this->getMappingName($routeName) can also be of type null; however, parameter $providerName of LAG\SmokerBundle\Url\Req...verInterface::resolve() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $mapping = $this->mappingResolver->resolve(/** @scrutinizer ignore-type */ $this->getMappingName($routeName), $routeName);
Loading history...
Unused Code introduced by
The assignment to $mapping is dead and can be removed.
Loading history...
39
40
        foreach ($configuration as $selector => $content) {
41
            if ($this->isDynamicString($content)) {
42
//                $provider = $this->registry->get('default');
43
//                $provider->getRequirements($routeName, [
44
//                    'where' => '',
45
//                ]);
46
            } else {
47
                if (false === strpos($crawler->filter($selector)->text(), $content)) {
48
                    throw new Exception();
49
                }
50
            }
51
        }
52
    }
53
54
    /**
55
     * Return the unique name of the response handler.
56
     *
57
     * @return string
58
     */
59
    public function getName(): string
60
    {
61
        return 'html';
62
    }
63
64
    protected function isDynamicString(string $content)
65
    {
66
        if ('{{' !== substr($content, 0, 2)) {
67
            return false;
68
        }
69
70
        if ('}}' !== substr($content, -2)) {
71
            return false;
72
        }
73
74
        return true;
75
    }
76
}
77