Passed
Push — feature/html-code-handler ( fe2642...5a7209 )
by Arnaud
02:37
created

HtmlHandler::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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 ('{{' === substr($content, 0, 2) && '}}' === substr($content, -2)) {
42
43
44
//                $provider = $this->registry->get('default');
45
//                $provider->getRequirements($routeName, [
46
//                    'where' => '',
47
//                ]);
48
            }
49
50
            if (false === strpos($crawler->filter($selector)->text(), $content)) {
51
                throw new Exception();
52
            }
53
        }
54
    }
55
56
    /**
57
     * Return the unique name of the response handler.
58
     *
59
     * @return string
60
     */
61
    public function getName(): string
62
    {
63
        return 'html';
64
    }
65
}
66