Issues (6)

src/Http/Middleware/DomainCheckerMiddleware.php (5 issues)

1
<?php
2
3
namespace Soumairi\DomainChecker\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Log;
7
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
0 ignored issues
show
The type Symfony\Component\HttpKe...cessDeniedHttpException 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...
8
9
class DomainCheckerMiddleware
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param \Illuminate\Http\Request $request
0 ignored issues
show
The type Illuminate\Http\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...
15
     * @param \Closure $next
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        $allowedHosts = config('domain-checker.allowed_domains');
0 ignored issues
show
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

20
        $allowedHosts = /** @scrutinizer ignore-call */ config('domain-checker.allowed_domains');
Loading history...
21
        $requestHost = $request->getHost();
22
23
        if (!app()->runningUnitTests()) {
0 ignored issues
show
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

23
        if (!/** @scrutinizer ignore-call */ app()->runningUnitTests()) {
Loading history...
24
            if (!\in_array($requestHost, $allowedHosts, false)) {
25
                $requestInfo = [
26
                    'host' => $requestHost,
27
                    'ip' => $request->getClientIp(),
28
                    'url' => $request->getRequestUri(),
29
                    'agent' => $request->header('User-Agent'),
30
                ];
31
                $error_msg=config('domain-checker.error_message');
32
                Log::alert('------------------------------------------Domaine Checker------------------------------------------');
33
                Log::alert('access_from_unauthorized_domain');
34
                Log::alert($requestInfo);
0 ignored issues
show
$requestInfo of type array is incompatible with the type string expected by parameter $message of Illuminate\Support\Facades\Log::alert(). ( Ignorable by Annotation )

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

34
                Log::alert(/** @scrutinizer ignore-type */ $requestInfo);
Loading history...
35
                Log::alert('---------------------------------------------------------------------------------------------------');
36
                throw new AccessDeniedHttpException($error_msg);
37
            }
38
        }
39
        return $next($request);
40
    }
41
}
42