Issues (404)

Branch: dev

app/Services/WhichPortal.php (11 issues)

1
<?php
2
3
namespace App\Services;
4
5
use Illuminate\Support\Facades\URL;
6
7
class WhichPortal
8
{
9
10
    public function home()
11 27
    {
12
        if ($this->isAdminPortal()) {
13 27
            return 'admin';
14
        } elseif ($this->isManagerPortal()) {
15
            return route('manager.home');
0 ignored issues
show
The function route 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

15
            return /** @scrutinizer ignore-call */ route('manager.home');
Loading history...
16 32
        }
17
        return route('home');
18 32
    }
19 32
20
    public function isApplicantPortal()
21
    {
22 34
        return !$this->isManagerPortal() && !$this->isHrPortal() && !$this->isAdminPortal();
23
    }
24 34
25 34
    public function isManagerPortal()
26 34
    {
27 34
        $url = URL::current();
28
        return $this->urlIsManagerPortal($url);
29
    }
30
31
    public function isHrPortal()
32
    {
33
        $url = URL::current();
34
        return $this->urlIsHrPortal($url);
35
    }
36
37
    public function isAdminPortal()
38
    {
39
        $url = URL::current();
40
        return $this->urlIsAdminPortal($url);
41
    }
42
43
    public function urlIsManagerPortal($url): bool
44
    {
45
        $baseUrl = config('app.url');
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

45
        $baseUrl = /** @scrutinizer ignore-call */ config('app.url');
Loading history...
46
        $managerPrefix = config('app.manager_prefix');
47
        $managerPattern = "#^$baseUrl/(\w+/)?$managerPrefix(/.*)?$#";
48
        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...
49
    }
50
51
    public function urlIsHrPortal($url): bool
52
    {
53
        $baseUrl = config('app.url');
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

53
        $baseUrl = /** @scrutinizer ignore-call */ config('app.url');
Loading history...
54
        $hrPrefix = config('app.hr_prefix');
55
        $hrPattern = "#^$baseUrl/(\w+/)?$hrPrefix(/.*)?$#";
56
        return preg_match($hrPattern, $url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match($hrPattern, $url) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
57
    }
58
59
    public function urlIsAdminPortal($url): bool
60
    {
61
        $baseUrl = config('app.url');
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

61
        $baseUrl = /** @scrutinizer ignore-call */ config('app.url');
Loading history...
62
        $adminPrefix = config('backpack.base.route_prefix', 'admin');
63
        $adminPattern = "#^$baseUrl/(\w+/)?$adminPrefix(/.*)?$#";
64
        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...
65
    }
66
67
    public function prefixRoute($routeName): string
68
    {
69
        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

69
        if (WhichPortal::/** @scrutinizer ignore-call */ isApplicantPortal()) {
Loading history...
70
            return $routeName;
71
        } 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

71
        } elseif (WhichPortal::/** @scrutinizer ignore-call */ isManagerPortal()) {
Loading history...
72
            return 'manager.' . $routeName;
73
        } elseif (WhichPortal::isHrPortal()) {
0 ignored issues
show
Bug Best Practice introduced by
The method App\Services\WhichPortal::isHrPortal() 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

73
        } elseif (WhichPortal::/** @scrutinizer ignore-call */ isHrPortal()) {
Loading history...
74
            return 'hr_advisor.' . $routeName;
75
        } 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

75
        } elseif (WhichPortal::/** @scrutinizer ignore-call */ isAdminPortal()) {
Loading history...
76
            return 'admin.' . $routeName;
77
        } elseif (WhichPortal::isHrPortal()) {
78
            return 'hr_advisor.' . $routeName;
79
        }
80
        return $routeName;
81
    }
82
}
83