Passed
Push — master ( 70acbf...5b5bb9 )
by Luiz Kim
29:52 queued 27:33
created

DomainService::getDomain()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 21
rs 9.8333
cc 2
nc 2
nop 0
1
<?php
2
3
namespace ControleOnline\Service;
4
5
use Symfony\Component\HttpFoundation\RequestStack;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\RequestStack was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use InvalidArgumentException;
8
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
11
class DomainService
12
{
13
    private $request;
14
    public function __construct(
15
        private  EntityManagerInterface $manager,
16
        RequestStack $requestStack
17
    ) {
18
        $this->request = $requestStack->getCurrentRequest();
19
    }
20
    /**
21
     * @return string
22
     */
23
    public function getDomain()
24
    {
25
26
        $domain = preg_replace("/[^a-zA-Z0-9.:_-]/", "", str_replace(
27
            ['https://', 'http://'],
28
            '',
29
            $this->request->get(
30
                'app-domain',
31
                $this->request->headers->get(
32
                    'app-domain',
33
                    $this->request->headers->get(
34
                        'referer',
35
                        $this->getMainDomain()
36
                    )
37
                )
38
            )
39
        ));
40
41
        if (!$domain)
42
            throw new InvalidArgumentException('Please define header or get param "app-domain"', 301);
43
        return $domain;
44
    }
45
46
    public function getMainDomain()
47
    {
48
        return $this->request->server->get('HTTP_HOST');
49
    }
50
}
51