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 ( 867f65...d58812 )
by Cristian
18s
created

LanguageCrudController::destroy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
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
    {
18
        parent::__construct();
19
20
        $this->crud->setModel("Backpack\LangFileManager\app\Models\Language");
21
        $this->crud->setRoute('admin/language');
22
        $this->crud->setEntityNameStrings(trans('backpack::langfilemanager.language'), trans('backpack::langfilemanager.languages'));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
23
24
        $this->crud->setColumns([
25
            [
26
                'name' => 'name',
27
                'label' => trans('backpack::langfilemanager.language_name'),
28
            ],
29
            [
30
                'name' => 'active',
31
                'label' => trans('backpack::langfilemanager.active'),
32
                'type' => 'boolean',
33
            ],
34
            [
35
                'name' => 'default',
36
                'label' => trans('backpack::langfilemanager.default'),
37
                'type' => 'boolean',
38
            ],
39
        ]);
40
        $this->crud->addField([
41
            'name' => 'name',
42
            'label' => trans('backpack::langfilemanager.language_name'),
43
            'type' => 'text',
44
        ]);
45
        $this->crud->addField([
46
            'name' => 'native',
47
            'label' => trans('backpack::langfilemanager.native_name'),
48
            'type' => 'text',
49
        ]);
50
        $this->crud->addField([
51
            'name' => 'abbr',
52
            'label' => trans('backpack::langfilemanager.code_iso639-1'),
53
            'type' => 'text',
54
        ]);
55
        $this->crud->addField([
56
            'name' => 'flag',
57
            'label' => trans('backpack::langfilemanager.flag_image'),
58
            'type' => 'browse',
59
        ]);
60
        $this->crud->addField([
61
            'name' => 'active',
62
            'label' => trans('backpack::langfilemanager.active'),
63
            'type' => 'checkbox',
64
        ]);
65
        $this->crud->addField([
66
            'name' => 'default',
67
            'label' => trans('backpack::langfilemanager.default'),
68
            'type' => 'checkbox',
69
        ]);
70
    }
71
72
    public function store(StoreRequest $request)
73
    {
74
        $defaultLang = Language::where('default', 1)->first();
75
76
        // Copy the default language folder to the new language folder
77
        \File::copyDirectory(resource_path('lang/'.$defaultLang->abbr), resource_path('lang/'.$request->input('abbr')));
78
79
        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...
80
    }
81
82
    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...
83
    {
84
        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...
85
    }
86
87
    /**
88
     * After delete remove also the language folder.
89
     *
90
     * @param int $id
91
     *
92
     * @return string
93
     */
94
    public function destroy($id)
95
    {
96
        $language = Language::find($id);
97
        $destroyResult = parent::destroy($id);
98
99
        if ($destroyResult) {
100
            \File::deleteDirectory(resource_path('lang/'.$language->abbr));
101
        }
102
103
        return $destroyResult;
104
    }
105
106
    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...
107
    {
108
        // SECURITY
109
        // check if that file isn't forbidden in the config file
110
        if (in_array($file, config('backpack.langfilemanager.language_ignore'))) {
111
            abort('403', trans('backpack::langfilemanager.cant_edit_online'));
112
        }
113
114
        if ($lang) {
115
            $langfile->setLanguage($lang);
116
        }
117
118
        $langfile->setFile($file);
119
        $this->data['crud'] = $this->crud;
120
        $this->data['currentFile'] = $file;
121
        $this->data['currentLang'] = $lang ?: config('app.locale');
122
        $this->data['currentLangObj'] = Language::where('abbr', '=', $this->data['currentLang'])->first();
123
        $this->data['browsingLangObj'] = Language::where('abbr', '=', config('app.locale'))->first();
124
        $this->data['languages'] = $languages->orderBy('name')->get();
125
        $this->data['langFiles'] = $langfile->getlangFiles();
126
        $this->data['fileArray'] = $langfile->getFileContent();
127
        $this->data['langfile'] = $langfile;
128
        $this->data['title'] = trans('backpack::langfilemanager.translations');
129
130
        return view('langfilemanager::translations', $this->data);
131
    }
132
133
    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...
134
    {
135
        // SECURITY
136
        // check if that file isn't forbidden in the config file
137
        if (in_array($file, config('backpack.langfilemanager.language_ignore'))) {
138
            abort('403', trans('backpack::langfilemanager.cant_edit_online'));
139
        }
140
141
        $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...
142
        $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...
143
144
        if ($lang) {
145
            $langfile->setLanguage($lang);
146
        }
147
148
        $langfile->setFile($file);
149
150
        $fields = $langfile->testFields($request->all());
151
        if (empty($fields)) {
152
            if ($langfile->setFileContent($request->all())) {
153
                \Alert::success(trans('backpack::langfilemanager.saved'))->flash();
154
                $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...
155
            }
156
        } else {
157
            $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...
158
            \Alert::error(trans('backpack::langfilemanager.please_fill_all_fields'))->flash();
159
        }
160
161
        return redirect()->back();
162
    }
163
}
164