Passed
Push — feature/departments-admin-pane... ( 993c86...15fee0 )
by Grant
12:31
created

DepartmentController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 13
dl 0
loc 26
ccs 0
cts 10
cp 0
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Lookup\Department;
6
7
class DepartmentController extends Controller
8
{
9
    /**
10
     * Return all departments as an array
11
     *
12
     * @return mixed
13
     */
14
    public function index()
15
    {
16
        $departments = Department::all();
17
        $departmentsArray = [];
18
        // TODO: improve effiency of getting translations.
19
        foreach ($departments as $department) {
20
            $translations = [
21
                'en' => [
22
                    'name' => $department->getTranslation('name', 'en'),
23
                    'impact' => $department->getTranslation('impact', 'en'),
24
                ],
25
                'fr' => [
26
                    'name' => $department->getTranslation('name', 'fr'),
27
                    'impact' => $department->getTranslation('impact', 'fr'),
28
                ]
29
            ];
30
            $departmentsArray[] = array_merge($department->toArray(), $translations);
31
        }
32
        return ['departments' => $departmentsArray];
33
    }
34
}
35