Passed
Push — master ( 795d23...149f73 )
by Grant
06:52 queued 12s
created

ResourcesController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 18
dl 0
loc 39
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A show() 0 31 5
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\Resource;
7
use Facades\App\Services\WhichPortal;
8
use Illuminate\Support\Facades\Auth;
9
use Illuminate\Support\Facades\Lang;
10
use Illuminate\Support\Facades\Log;
11
use Illuminate\Support\Facades\Storage;
12
13
class ResourcesController extends Controller
14
{
15
16
    /**
17
     * Display the resources template
18
     *
19
     * @return \Illuminate\Http\Response
20
     */
21
    public function show()
22
    {
23
        $user = Auth::user();
24
        $resources_template = Lang::get('common/resources');
25
        $resources = [];
26
27
        // Iterate through resource files, and push link type array into resources array.
28
        if ($user->isUpgradedManager() || $user->isHrAdvisor()) {
29
            $files = Resource::all();
30
            foreach ($files as $file) {
31
                array_push($resources, [
32
                  'link' => asset(Storage::url($file->file)),
0 ignored issues
show
Bug introduced by
The function asset 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

32
                  'link' => /** @scrutinizer ignore-call */ asset(Storage::url($file->file)),
Loading history...
33
                  'title' => '',
34
                  'text' => $file->name,
35
                ]);
36
            }
37
38
            // Sort the list alphabetically.
39
            usort($resources, function ($filenameA, $filenameB) {
40
                return strcmp($filenameA['text'], $filenameB['text']);
41
            });
42
        }
43
44
        $portal = WhichPortal::isHrPortal() ? 'hr' : 'manager';
45
46
        return view('common/resources', [
0 ignored issues
show
Bug introduced by
The function view 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

46
        return /** @scrutinizer ignore-call */ view('common/resources', [
Loading history...
47
          // Localized strings.
48
          'resources_template' => $resources_template,
49
          'portal' => $portal,
50
          // List of resource downloads.
51
          'resources' => $resources,
52
        ]);
53
    }
54
}
55