Passed
Push — feature/resources ( 00a731...ac736e )
by Yonathan
05:58 queued 12s
created

ResourcesController::show()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 25
rs 9.8333
c 2
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\Resource;
7
use Illuminate\Support\Facades\Lang;
8
use Illuminate\Support\Facades\Log;
9
use Illuminate\Support\Facades\Storage;
10
11
class ResourcesController extends Controller
12
{
13
14
    /**
15
     * Display the resources template
16
     *
17
     * @return \Illuminate\Http\Response
18
     */
19
    public function show()
20
    {
21
        $resources_template = Lang::get('common/resources');
22
        $resources = [];
23
24
        // Iterate through resource files, and push link type array into resources array.
25
        $files = Resource::all();
26
        foreach ($files as $file) {
27
            array_push($resources, [
28
              'link' => Storage::url($file->file),
29
              'title' => '',
30
              'text' => $file->name,
31
            ]);
32
        }
33
34
        // Sort the list alphabetically.
35
        usort($resources, function ($a, $b) {
36
            return strcmp($a['text'], $b['text']);
37
        });
38
39
        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

39
        return /** @scrutinizer ignore-call */ view('common/resources', [
Loading history...
40
          // Localized strings.
41
          'resources_template' => $resources_template,
42
          // List of resource downloads.
43
          'resources' => $resources,
44
        ]);
45
    }
46
}
47