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
Pull Request — master (#19)
by
unknown
02:39
created

LanguageCrudController::destroy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
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
        {
101
            \File::deleteDirectory(resource_path('lang/' . $language->abbr));
102
        }
103
104
        return $destroyResult;
105
    }
106
107
    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...
108
    {
109
        // SECURITY
110
        // check if that file isn't forbidden in the config file
111
        if (in_array($file, config('backpack.langfilemanager.language_ignore'))) {
112
            abort('403', trans('backpack::langfilemanager.cant_edit_online'));
113
        }
114
115
        if ($lang) {
116
            $langfile->setLanguage($lang);
117
        }
118
119
        $langfile->setFile($file);
120
        $this->data['crud'] = $this->crud;
121
        $this->data['currentFile'] = $file;
122
        $this->data['currentLang'] = $lang ?: config('app.locale');
123
        $this->data['currentLangObj'] = Language::where('abbr', '=', $this->data['currentLang'])->first();
124
        $this->data['browsingLangObj'] = Language::where('abbr', '=', config('app.locale'))->first();
125
        $this->data['languages'] = $languages->orderBy('name')->get();
126
        $this->data['langFiles'] = $langfile->getlangFiles();
127
        $this->data['fileArray'] = $langfile->getFileContent();
128
        $this->data['langfile'] = $langfile;
129
        $this->data['title'] = trans('backpack::langfilemanager.translations');
130
131
        return view('langfilemanager::translations', $this->data);
132
    }
133
134
    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...
135
    {
136
        // SECURITY
137
        // check if that file isn't forbidden in the config file
138
        if (in_array($file, config('backpack.langfilemanager.language_ignore'))) {
139
            abort('403', trans('backpack::langfilemanager.cant_edit_online'));
140
        }
141
142
        $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...
143
        $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...
144
145
        if ($lang) {
146
            $langfile->setLanguage($lang);
147
        }
148
149
        $langfile->setFile($file);
150
151
        $fields = $langfile->testFields($request->all());
152
        if (empty($fields)) {
153
            if ($langfile->setFileContent($request->all())) {
154
                \Alert::success(trans('backpack::langfilemanager.saved'))->flash();
155
                $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...
156
            }
157
        } else {
158
            $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...
159
            \Alert::error(trans('backpack::langfilemanager.please_fill_all_fields'))->flash();
160
        }
161
162
        return redirect()->back();
163
    }
164
}
165