RewritingRouterLast   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A matchRequest() 0 21 5
1
<?php
2
3
namespace RewriteUrl\Service;
4
5
use RewriteUrl\Model\RewriteurlRule;
6
use RewriteUrl\Model\RewriteurlRuleQuery;
7
use Thelia\Core\Routing\RewritingRouter;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
10
use Thelia\Core\HttpFoundation\Request as TheliaRequest;
11
use Thelia\Model\ConfigQuery;
12
use Thelia\Tools\URL;
13
14
/**
15
 * This router is intended to be the very last checked by the ChainRouter on a request.
16
 */
17
class RewritingRouterLast extends RewritingRouter
18
{
19
    /**
20
     * @inheritdoc
21
     */
22
    public function matchRequest(Request $request)
23
    {
24
        if (ConfigQuery::isRewritingEnable()) {
25
            $urlTool = URL::getInstance();
26
27
            $ruleCollection = RewriteurlRuleQuery::create()
28
                ->filterByOnly404(1)
29
                ->orderByPosition()
30
                ->find();
31
32
            $pathInfo = $request instanceof TheliaRequest ? $request->getRealPathInfo() : $request->getPathInfo();
0 ignored issues
show
Bug introduced by
The class Thelia\Core\HttpFoundation\Request does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
33
34
            /** @var RewriteurlRule $rule */
35
            foreach ($ruleCollection as $rule) {
36
                if ($rule->isMatching($pathInfo, $request->query->all())) {
37
                    $this->redirect($urlTool->absoluteUrl($rule->getRedirectUrl()), 301);
38
                }
39
            }
40
        }
41
        throw new ResourceNotFoundException();
42
    }
43
}
44