Passed
Push — feature/settings-2fa ( 2ec45d...d5e36c )
by Tristan
10:06
created

WhichPortal   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 26
dl 0
loc 56
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A urlIsManagerPortal() 0 6 1
A isManagerPortal() 0 4 1
A isAdminPortal() 0 4 1
A isApplicantPortal() 0 3 2
A urlIsAdminPortal() 0 6 1
A home() 0 8 3
A prefixRoute() 0 10 4
1
<?php
2
3
namespace App\Services;
4
5
use Illuminate\Support\Facades\Route;
6
use Illuminate\Support\Facades\URL;
7
8
class WhichPortal
9
{
10
11
    public function home()
1 ignored issue
show
introduced by
Method \App\Services\WhichPortal::home() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function home()
Loading history...
12
    {
13
        if ($this->isAdminPortal()) {
14
            return 'admin';
15
        } elseif ($this->isManagerPortal()) {
16
            return route('manager.home');
17
        }
18
        return route('home');
19
    }
20
21
    public function isApplicantPortal()
1 ignored issue
show
introduced by
Method \App\Services\WhichPortal::isApplicantPortal() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function isApplicantPortal()
Loading history...
22
    {
23
        return !$this->isManagerPortal() && !$this->isAdminPortal();
24
    }
25
26
    public function isManagerPortal()
1 ignored issue
show
introduced by
Method \App\Services\WhichPortal::isManagerPortal() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function isManagerPortal()
Loading history...
27
    {
28
        $url = URL::current();
29
        return $this->urlIsManagerPortal($url);
30
    }
31
32
    public function isAdminPortal()
1 ignored issue
show
introduced by
Method \App\Services\WhichPortal::isAdminPortal() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function isAdminPortal()
Loading history...
33
    {
34
        $url = URL::current();
35
        return $this->urlIsAdminPortal($url);
36
    }
37
38
    public function urlIsManagerPortal($url): bool
1 ignored issue
show
introduced by
Method \App\Services\WhichPortal::urlIsManagerPortal() does not have parameter type hint nor @param annotation for its parameter $url.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function urlIsManagerPortal()
Loading history...
39
    {
40
        $baseUrl = config('app.url');
41
        $managerPrefix = config('app.manager_prefix');
42
        $managerPattern = "#^$baseUrl/(\w+/)?$managerPrefix(/.*)?$#";
43
        return preg_match($managerPattern, $url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match($managerPattern, $url) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
44
    }
45
46
    public function urlIsAdminPortal($url): bool
1 ignored issue
show
introduced by
Method \App\Services\WhichPortal::urlIsAdminPortal() does not have parameter type hint nor @param annotation for its parameter $url.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function urlIsAdminPortal()
Loading history...
47
    {
48
        $baseUrl = config('app.url');
49
        $adminPrefix = config('backpack.base.route_prefix', 'admin');
50
        $adminPattern = "#^$baseUrl/(\w+/)?$adminPrefix(/.*)?$#";
51
        return preg_match($adminPattern, $url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match($adminPattern, $url) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
52
    }
53
54
    public function prefixRoute($routeName): string
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function prefixRoute()
Loading history...
introduced by
Method \App\Services\WhichPortal::prefixRoute() does not have parameter type hint nor @param annotation for its parameter $routeName.
Loading history...
55
    {
56
        if (WhichPortal::isApplicantPortal()) {
0 ignored issues
show
Bug Best Practice introduced by
The method App\Services\WhichPortal::isApplicantPortal() is not static, but was called statically. ( Ignorable by Annotation )

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

56
        if (WhichPortal::/** @scrutinizer ignore-call */ isApplicantPortal()) {
Loading history...
57
            return $routeName;
58
        } elseif (WhichPortal::isManagerPortal()) {
0 ignored issues
show
Bug Best Practice introduced by
The method App\Services\WhichPortal::isManagerPortal() is not static, but was called statically. ( Ignorable by Annotation )

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

58
        } elseif (WhichPortal::/** @scrutinizer ignore-call */ isManagerPortal()) {
Loading history...
59
            return 'manager.' . $routeName;
60
        } elseif (WhichPortal::isAdminPortal()) {
0 ignored issues
show
Bug Best Practice introduced by
The method App\Services\WhichPortal::isAdminPortal() is not static, but was called statically. ( Ignorable by Annotation )

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

60
        } elseif (WhichPortal::/** @scrutinizer ignore-call */ isAdminPortal()) {
Loading history...
61
            return 'admin.' . $routeName;
62
        }
63
        return $routeName;
64
    }
65
}
66