Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( d32009...399c68 )
by Ghitu
02:15
created

LanguageCrudController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 49
rs 9.2258
cc 1
eloc 34
nc 1
nop 0
1
<?php
2
3
namespace Backpack\LangFileManager\app\Http\Controllers;
4
5
use App\Http\Requests;
6
use Backpack\CRUD\app\Http\Controllers\CrudController;
7
use Backpack\LangFileManager\app\Services\LangFiles;
8
use Backpack\LangFileManager\app\Models\Language;
9
use Illuminate\Http\Request;
10
// VALIDATION: change the requests to match your own file names if you need form validation
11
use Backpack\LangFileManager\app\Http\Requests\LanguageRequest as StoreRequest;
12
use Backpack\LangFileManager\app\Http\Requests\LanguageRequest as UpdateRequest;
13
14
class LanguageCrudController extends CrudController
15
{
16
    public function __construct() {
17
        parent::__construct();
18
19
        $this->crud->setModel("Backpack\LangFileManager\app\Models\Language");
20
        $this->crud->setRoute("admin/language");
21
        $this->crud->setEntityNameStrings('language', 'languages');
22
23
        $this->crud->setColumns([
24
            [
25
                'name' => 'name',
26
                'label' => 'Language name',
27
            ],
28
            [
29
                'name' => 'active',
30
                'label' => 'Active',
31
                'type' => 'boolean',
32
            ],
33
            [
34
                'name' => 'default',
35
                'label' => 'Default',
36
                'type' => 'boolean',
37
            ],
38
        ]);
39
        $this->crud->addField([
40
            'name' => 'name',
41
            'label' => 'Language Name',
42
            'type' => 'text',
43
        ]);
44
        $this->crud->addField([
45
            'name' => 'abbr',
46
            'label' => 'Code (ISO 639-1)',
47
            'type' => 'text',
48
        ]);
49
        $this->crud->addField([
50
            'name' => 'flag',
51
            'label' => 'Flag image',
52
            'type' => 'browse',
53
        ]);
54
        $this->crud->addField([
55
            'name' => 'active',
56
            'label' => 'Active',
57
            'type' => 'checkbox',
58
        ]);
59
        $this->crud->addField([
60
            'name' => 'default',
61
            'label' => 'Default',
62
            'type' => 'checkbox',
63
        ]);
64
    }
65
66
    public function store(StoreRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
        return parent::storeCrud();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (storeCrud() instead of store()). Are you sure this is correct? If so, you might want to change this to $this->storeCrud().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
69
    }
70
71
    public function update(UpdateRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    {
73
        return parent::updateCrud();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (updateCrud() instead of update()). Are you sure this is correct? If so, you might want to change this to $this->updateCrud().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
74
    }
75
76
    public function showTexts(LangFiles $langfile, Language $languages, $lang = '', $file = 'site')
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
77
    {
78
        // SECURITY
79
        // check if that file isn't forbidden in the config file
80
        if (in_array($file, config('langfilemanager.language_ignore'))) {
81
            abort('403', 'This language file cannot be edited online.');
82
        }
83
84
        if ($lang) {
85
            $langfile->setLanguage($lang);
86
        }
87
88
        $langfile->setFile($file);
89
        $this->data['crud'] = $this->crud;
90
        $this->data['currentFile'] = $file;
91
        $this->data['currentLang'] = $lang ?: config('app.locale');
92
        $this->data['currentLangObj'] = Language::where('abbr', '=', $this->data['currentLang'])->first();
93
        $this->data['browsingLangObj'] = Language::where('abbr', '=', config('app.locale'))->first();
94
        $this->data['languages'] = $languages->orderBy('name')->get();
95
        $this->data['langFiles'] = $langfile->getlangFiles();
96
        $this->data['fileArray'] = $langfile->getFileContent();
97
        $this->data['langfile'] = $langfile;
98
        $this->data['title'] = 'Translations';
99
100
        return view('langfilemanager::translations', $this->data);
101
    }
102
103
    public function updateTexts(LangFiles $langfile, Request $request, $lang = '', $file = 'site')
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
104
    {
105
        // SECURITY
106
        // check if that file isn't forbidden in the config file
107
        if (in_array($file, config('langfilemanager.language_ignore'))) {
108
            abort('403', 'This language file cannot be edited online.');
109
        }
110
111
        $message = trans('error.error_general');
0 ignored issues
show
Unused Code introduced by
$message is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
112
        $status = false;
0 ignored issues
show
Unused Code introduced by
$status is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
113
114
        if ($lang) {
115
            $langfile->setLanguage($lang);
116
        }
117
118
        $langfile->setFile($file);
119
120
        $fields = $langfile->testFields($request->all());
121
        if (empty($fields)) {
122
            if ($langfile->setFileContent($request->all())) {
123
                \Alert::success('Saved')->flash();
124
                $status = true;
0 ignored issues
show
Unused Code introduced by
$status is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
125
            }
126
        } else {
127
            $message = trans('admin.language.fields_required');
0 ignored issues
show
Unused Code introduced by
$message is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
128
            \Alert::error('Please fill all fields')->flash();
129
        }
130
131
        return redirect()->back();
132
    }
133
}
134