Passed
Push — task/refactor-breadcrumbs ( 6a520e...b85733 )
by Yonathan
03:24
created

BreadcrumbsComposer::parseSegments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 18
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\ViewComposers;
4
5
use Facades\App\Services\WhichPortal;
6
use Illuminate\View\View;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Lang;
9
use Illuminate\Support\Facades\Log;
10
11
class BreadcrumbsComposer
12
{
13
    /**
14
     * The request instance.
15
     *
16
     * @var \Illuminate\Http\Request
17
     */
18
    protected $request;
19
20
    /**
21
     * Initialize a new composer instance.
22
     *
23
     * @param  \Illuminate\Http\Request  $request
24
     * @return void
25
     */
26
    public function __construct(Request $request)
27
    {
28
        $this->request = $request;
29
    }
30
31
    /**
32
     * Bind data to the view.
33
     *
34
     * @param  \Illuminate\View\View  $view
35
     * @return void
36
     */
37
    public function compose(View $view)
38
    {
39
        $segments = $this->parseSegments();
40
        $breadcrumbs_lang = Lang::get('common/breadcrumbs');
41
        $portal_specific_lang = [];
42
        $view->with('breadcrumbs_lang', $breadcrumbs_lang);
43
44
        if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) {
45
            $segments = $segments->slice(1);
46
            $portal_specific_lang = $breadcrumbs_lang['manager'];
47
        } elseif (WhichPortal::isHrPortal()) {
48
            $segments = $segments->slice(1);
49
            $portal_specific_lang = $breadcrumbs_lang['hr'];
50
        }
51
52
        $view->with('breadcrumbs', $segments);
53
        $view->with('portal_specific_lang', $portal_specific_lang);
54
    }
55
56
    /**
57
     * Parse the request route segments.
58
     *
59
     * @return \Illuminate\Support\Collection
60
     */
61
    protected function parseSegments()
62
    {
63
        return collect($this->request->segments())->mapWithKeys(function ($segment, $key) {
0 ignored issues
show
Bug introduced by
The function collect 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

63
        return /** @scrutinizer ignore-call */ collect($this->request->segments())->mapWithKeys(function ($segment, $key) {
Loading history...
64
            // Replaces any segment ID in url with the objects name or title.
65
            // if ($this->request->jobPoster && $this->request->jobPoster->id == $segment) {
66
            //     $segment = $this->request->jobPoster->title;
67
            // }
68
            // if ($this->request->manager && $this->request->manager->id == $segment) {
69
            //     $segment = $this->request->manager->user->full_name;
70
            // }
71
            // if ($this->request->applicant && $this->request->applicant->id == $segment) {
72
            //     $segment = $this->request->applicant->user->full_name;
73
            // }
74
            // if ($this->request->application && $this->request->application->id == $segment) {
75
            //     $segment = $this->request->application->user_name;
76
            // }
77
            return [
78
                $segment => implode('/', array_slice($this->request->segments(), 0, $key + 1)),
79
            ];
80
        });
81
    }
82
}
83