Passed
Push — feature/settings-2fa ( 142ad6...2ec45d )
by Tristan
08:38
created

WhichPortal::isAdminPortal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace App\Services;
4
5
use Illuminate\Support\Facades\Route;
6
use Illuminate\Support\Facades\URL;
7
8
class WhichPortal
0 ignored issues
show
Bug introduced by
Possible parse error: class missing opening or closing brace
Loading history...
9
{
10
11
public function home()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function home()
Loading history...
introduced by
Function \App\Services\home() does not have return type hint nor @return annotation for its return value.
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
Coding Style Documentation introduced by
Missing doc comment for function isApplicantPortal()
Loading history...
introduced by
Function \App\Services\isApplicantPortal() does not have return type hint nor @return annotation for its return value.
Loading history...
22
{
23
    return !$this->isManagerPortal() && !$this->isAdminPortal();
24
}
25
26
public function isManagerPortal()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function isManagerPortal()
Loading history...
introduced by
Function \App\Services\isManagerPortal() does not have return type hint nor @return annotation for its return value.
Loading history...
27
{
28
    $url = URL::current();
29
    return $this->urlIsManagerPortal($url);
30
}
31
32
public function isAdminPortal()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function isAdminPortal()
Loading history...
introduced by
Function \App\Services\isAdminPortal() does not have return type hint nor @return annotation for its return value.
Loading history...
33
{
34
    $url = URL::current();
35
    return $this->urlIsAdminPortal($url);
36
}
37
38
public function urlIsManagerPortal($url): bool
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function urlIsManagerPortal()
Loading history...
introduced by
Function \App\Services\urlIsManagerPortal() does not have parameter type hint nor @param annotation for its parameter $url.
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);
44
}
45
46
public function urlIsAdminPortal($url): bool
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function urlIsAdminPortal()
Loading history...
introduced by
Function \App\Services\urlIsAdminPortal() does not have parameter type hint nor @param annotation for its parameter $url.
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);
52
}
53
54
public function prefixRoute($routeName): string
1 ignored issue
show
introduced by
Function \App\Services\prefixRoute() does not have parameter type hint nor @param annotation for its parameter $routeName.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function prefixRoute()
Loading history...
55
{
56
    if (WhichPortal::isApplicantPortal()) {
57
        $routeName;
58
    } elseif (WhichPortal::isManagerPortal()) {
59
        return 'manager.' . $routeName;
60
    } elseif (WhichPortal::isAdminPortal()) {
61
        return 'admin.' . $routeName;
62
    }
63
    return $routeName;
64
}
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected EOF, expecting T_FUNCTION or T_CONST on line 64 at column 0
Loading history...
65