Skip to content

Commit 12e80ff

Browse files
committed
Merge pull request #5 from Laravel-Backpack/scrutinizer-patch-1
Scrutinizer Auto-Fixes
2 parents edc19e4 + 6049c57 commit 12e80ff

File tree

7 files changed

+50
-57
lines changed

7 files changed

+50
-57
lines changed

src/CrudServiceProvider.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public function boot()
3232

3333
// PUBLISH FILES
3434
// publish lang files
35-
$this->publishes([ __DIR__.'/resources/lang' => resource_path('lang/vendor/backpack'), ], 'lang');
35+
$this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack'), ], 'lang');
3636
// publish views
37-
$this->publishes([ __DIR__.'/resources/views' => resource_path('views/vendor/backpack/crud'), ], 'views');
37+
$this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/crud'), ], 'views');
3838
// publish public Backpack CRUD assets
39-
$this->publishes([ __DIR__.'/public' => public_path('vendor/backpack'), ], 'public');
39+
$this->publishes([__DIR__.'/public' => public_path('vendor/backpack'), ], 'public');
4040
// publish custom files for elFinder
4141
$this->publishes([
4242
__DIR__.'/config/elfinder.php' => config_path('elfinder.php'),
@@ -68,7 +68,7 @@ public function register()
6868

6969
private function registerCRUD()
7070
{
71-
$this->app->bind('CRUD',function($app){
71+
$this->app->bind('CRUD', function($app) {
7272
return new CRUD($app);
7373
});
7474
}

src/CrudTrait.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait CrudTrait {
1212
|--------------------------------------------------------------------------
1313
*/
1414

15-
public static function getPossibleEnumValues($field_name){
15+
public static function getPossibleEnumValues($field_name){
1616
$instance = new static; // create an instance of the model to be able to get the table name
1717
$type = DB::select( DB::raw('SHOW COLUMNS FROM '.$instance->getTable().' WHERE Field = "'.$field_name.'"') )[0]->Type;
1818
preg_match('/^enum\((.*)\)$/', $type, $matches);
@@ -27,9 +27,9 @@ public static function getPossibleEnumValues($field_name){
2727

2828
public static function isColumnNullable($column_name) {
2929
$instance = new static; // create an instance of the model to be able to get the table name
30-
$answer = DB::select( DB::raw("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$instance->getTable()."' AND COLUMN_NAME='".$column_name."' AND table_schema='".env('DB_DATABASE')."'") )[0];
30+
$answer = DB::select(DB::raw("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$instance->getTable()."' AND COLUMN_NAME='".$column_name."' AND table_schema='".env('DB_DATABASE')."'"))[0];
3131

32-
return ($answer->IS_NULLABLE == 'YES'?true:false);
32+
return ($answer->IS_NULLABLE == 'YES' ? true : false);
3333
}
3434

3535

@@ -67,7 +67,7 @@ public function addFakes($columns = ['extras']) {
6767
* Return the entity with fake fields as attributes.
6868
*
6969
* @param array $columns - the database columns that contain the JSONs
70-
* @return obj
70+
* @return CrudTrait
7171
*/
7272
public function withFakes($columns = [])
7373
{
@@ -76,8 +76,7 @@ public function withFakes($columns = [])
7676
if (!count($columns)) {
7777
if (property_exists($model, 'fakeColumns')) {
7878
$columns = $this->fakeColumns;
79-
}
80-
else
79+
} else
8180
{
8281
$columns = ['extras'];
8382
}
@@ -128,7 +127,7 @@ public function allTranslations()
128127

129128
public function translation($translation_lang = false)
130129
{
131-
if ($translation_lang==false) {
130+
if ($translation_lang == false) {
132131
$translation_lang = Lang::locale();
133132
}
134133

src/app/Http/Controllers/CrudController.php

+22-28
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public function index()
5353
if (property_exists($model, 'translatable'))
5454
{
5555
$this->data['entries'] = $model::where('translation_lang', \Lang::locale())->get();
56-
}
57-
else
56+
} else
5857
{
5958
$this->data['entries'] = $model::all();
6059
}
@@ -106,7 +105,7 @@ public function create()
106105
* Store a newly created resource in the database.
107106
*
108107
* @param StoreRequest $request - type injection used for validation using Requests
109-
* @return Response
108+
* @return \Illuminate\Http\RedirectResponse
110109
*/
111110
public function storeCrud(StoreRequest $request = null)
112111
{
@@ -124,7 +123,7 @@ public function storeCrud(StoreRequest $request = null)
124123
// if it's a relationship with a pivot table, also sync that
125124
$this->prepareFields();
126125
foreach ($this->crud['fields'] as $k => $field) {
127-
if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name']))
126+
if (isset($field['pivot']) && $field['pivot'] == true && \Request::has($field['name']))
128127
{
129128
$model::find($item->id)->$field['name']()->attach(\Request::input($field['name']));
130129
}
@@ -182,7 +181,7 @@ public function edit($id)
182181
* Update the specified resource in the database.
183182
*
184183
* @param UpdateRequest $request - type injection used for validation using Requests
185-
* @return Response
184+
* @return \Illuminate\Http\RedirectResponse
186185
*/
187186
public function updateCrud(UpdateRequest $request = null)
188187
{
@@ -198,7 +197,7 @@ public function updateCrud(UpdateRequest $request = null)
198197

199198
// if it's a relationship with a pivot table, also sync that
200199
foreach ($this->crud['fields'] as $k => $field) {
201-
if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name']))
200+
if (isset($field['pivot']) && $field['pivot'] == true && \Request::has($field['name']))
202201
{
203202
$model::find(\Request::input('id'))->$field['name']()->sync(\Request::input($field['name']));
204203
}
@@ -235,7 +234,7 @@ public function show($id)
235234
* Remove the specified resource from storage.
236235
*
237236
* @param int $id
238-
* @return Response
237+
* @return string
239238
*/
240239
public function destroy($id)
241240
{
@@ -279,8 +278,7 @@ public function reorder($lang = false)
279278
$this->data['entries'] = $model::where('translation_lang', $lang)->get();
280279
$this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all();
281280
$this->data['active_language'] = $lang;
282-
}
283-
else
281+
} else
284282
{
285283
$this->data['entries'] = $model::all();
286284
}
@@ -323,8 +321,7 @@ public function saveReorder()
323321
$count++;
324322
}
325323
}
326-
}
327-
else
324+
} else
328325
{
329326
return false;
330327
}
@@ -358,7 +355,7 @@ public function showDetailsRow($id)
358355
$this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all();
359356
$this->data['languages_already_translated_in'] = $this->data['entry']->translationLanguages();
360357
$this->data['languages_to_translate_in'] = $this->data['languages']->diff($this->data['languages_already_translated_in']);
361-
$this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function ($item) {
358+
$this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function($item) {
362359
return $item->abbr == \Lang::locale();
363360
});
364361
}
@@ -381,8 +378,7 @@ public function translateItem($id, $lang)
381378
if ($existing_translation)
382379
{
383380
$new_entry = $existing_translation;
384-
}
385-
else
381+
} else
386382
{
387383
// get the info for that entry
388384
$new_entry_attributes = $this->data['entry']->getAttributes();
@@ -421,22 +417,21 @@ protected function compactFakeFields($request) {
421417
// go through each defined field
422418
foreach ($this->crud['fields'] as $k => $field) {
423419
// if it's a fake field
424-
if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) {
420+
if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake'] == true) {
425421
// add it to the request in its appropriate variable - the one defined, if defined
426422
if (isset($this->crud['fields'][$k]['store_in'])) {
427423
$request[$this->crud['fields'][$k]['store_in']][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']];
428424

429425
$remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']);
430-
if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){
426+
if (!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)) {
431427
array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']);
432428
}
433-
}
434-
else //otherwise in the one defined in the $crud variable
429+
} else //otherwise in the one defined in the $crud variable
435430
{
436431
$request['extras'][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']];
437432

438433
$remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']);
439-
if(!in_array('extras', $fake_field_columns_to_encode, true)){
434+
if (!in_array('extras', $fake_field_columns_to_encode, true)) {
440435
array_push($fake_field_columns_to_encode, 'extras');
441436
}
442437
}
@@ -469,16 +464,15 @@ protected function getFakeColumnsAsArray() {
469464

470465
foreach ($this->crud['fields'] as $k => $field) {
471466
// if it's a fake field
472-
if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) {
467+
if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake'] == true) {
473468
// add it to the request in its appropriate variable - the one defined, if defined
474469
if (isset($this->crud['fields'][$k]['store_in'])) {
475-
if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){
470+
if (!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)) {
476471
array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']);
477472
}
478-
}
479-
else //otherwise in the one defined in the $crud variable
473+
} else //otherwise in the one defined in the $crud variable
480474
{
481-
if(!in_array('extras', $fake_field_columns_to_encode, true)){
475+
if (!in_array('extras', $fake_field_columns_to_encode, true)) {
482476
array_push($fake_field_columns_to_encode, 'extras');
483477
}
484478
}
@@ -536,8 +530,7 @@ protected function prepareFields($entry = false)
536530
if (isset($this->crud['create_fields']))
537531
{
538532
$this->crud['fields'] = $this->crud['create_fields'];
539-
}
540-
elseif (isset($this->crud['update_fields']))
533+
} elseif (isset($this->crud['update_fields']))
541534
{
542535
$this->crud['fields'] = $this->crud['update_fields'];
543536
}
@@ -569,8 +562,9 @@ protected function prepareFields($entry = false)
569562

570563
// if no field type is defined, assume the "text" field type
571564
foreach ($this->crud['fields'] as $k => $field) {
572-
if (!isset($this->crud['fields'][$k]['type']))
573-
$this->crud['fields'][$k]['type'] = 'text';
565+
if (!isset($this->crud['fields'][$k]['type'])) {
566+
$this->crud['fields'][$k]['type'] = 'text';
567+
}
574568
}
575569

576570
// if an entry was passed, we're preparing for the update form, not create

src/resources/views-elfinder/filepicker.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
1111

1212
<!-- elFinder CSS (REQUIRED) -->
13-
<link rel="stylesheet" type="text/css" href="<?= asset($dir . '/css/elfinder.min.css') ?>">
13+
<link rel="stylesheet" type="text/css" href="<?= asset($dir.'/css/elfinder.min.css') ?>">
1414
<!-- <link rel="stylesheet" type="text/css" href="<?= asset($dir.'/css/theme.css') ?>"> -->
1515
<link rel="stylesheet" type="text/css" href="<?= asset('vendor/backpack/elfinder/elfinder.backpack.theme.css') ?>">
1616

1717
<!-- elFinder JS (REQUIRED) -->
18-
<script src="<?= asset($dir . '/js/elfinder.min.js') ?>"></script>
18+
<script src="<?= asset($dir.'/js/elfinder.min.js') ?>"></script>
1919

2020
<?php if ($locale) { ?>
2121
<!-- elFinder translation (OPTIONAL) -->
22-
<script src="<?= asset($dir . "/js/i18n/elfinder.$locale.js") ?>"></script>
22+
<script src="<?= asset($dir."/js/i18n/elfinder.$locale.js") ?>"></script>
2323
<?php } ?>
2424
<!-- Include jQuery, jQuery UI, elFinder (REQUIRED) -->
2525

2626
<?php
27-
$mimeTypes = implode(',',array_map(function($t){return "'".$t."'";}, explode(',',$type)));
27+
$mimeTypes = implode(',', array_map(function($t) {return "'".$t."'"; }, explode(',', $type)));
2828
?>
2929

3030
<script type="text/javascript">
3131
$().ready(function () {
3232
var elf = $('#elfinder').elfinder({
3333
// set your elFinder options here
34-
<?php if($locale){ ?>
34+
<?php if ($locale) { ?>
3535
lang: '<?= $locale ?>', // locale
3636
<?php } ?>
3737
customData: {

src/resources/views/fields/page_or_link.blade.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class="form-control"
4141
</div>
4242
<div class="col-sm-9">
4343
<!-- external link input -->
44-
<div class="page_or_link_value <?php if (!isset($entry) || $entry->type!='external_link') { echo 'hidden'; } ?>" id="page_or_link_external_link">
44+
<div class="page_or_link_value <?php if (!isset($entry) || $entry->type != 'external_link') { echo 'hidden'; } ?>" id="page_or_link_external_link">
4545
<input
4646
type="url"
4747
class="form-control"
@@ -58,7 +58,7 @@ class="form-control"
5858
>
5959
</div>
6060
<!-- internal link input -->
61-
<div class="page_or_link_value <?php if (!isset($entry) || $entry->type!='internal_link') { echo 'hidden'; } ?>" id="page_or_link_internal_link">
61+
<div class="page_or_link_value <?php if (!isset($entry) || $entry->type != 'internal_link') { echo 'hidden'; } ?>" id="page_or_link_internal_link">
6262
<input
6363
type="text"
6464
class="form-control"
@@ -75,7 +75,7 @@ class="form-control"
7575
>
7676
</div>
7777
<!-- page slug input -->
78-
<div class="page_or_link_value <?php if (isset($entry) && $entry->type!='page_link') { echo 'hidden'; } ?>" id="page_or_link_page">
78+
<div class="page_or_link_value <?php if (isset($entry) && $entry->type != 'page_link') { echo 'hidden'; } ?>" id="page_or_link_page">
7979
<select
8080
class="form-control"
8181
name="page_id"

src/resources/views/form_content.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
{{-- For each form type, load its assets, if needed --}}
2626
{{-- But only once per field type (no need to include the same css/js files multiple times on the same page) --}}
2727
<?php
28-
$loaded_form_types_css = array();
29-
$loaded_form_types_js = array();
28+
$loaded_form_types_css = array();
29+
$loaded_form_types_js = array();
3030
?>
3131

3232
@section('after_styles')

src/resources/views/list.blade.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,24 @@
7171
if ($results && $results->count()) {
7272
$results_array = $results->lists($column['attribute'], 'id');
7373
echo implode(', ', $results_array->toArray());
74-
}
75-
else
76-
{
74+
}
75+
else
76+
{
7777
echo '-';
78-
}
79-
?></td>
78+
}
79+
?></td>
8080
@elseif (isset($column['type']) && $column['type']=='select')
8181
{{-- single relationships (1-1, 1-n) --}}
8282
<td><?php
8383
if ($entry->{$column['entity']}()->getResults()) {
8484
echo $entry->{$column['entity']}()->getResults()->{$column['attribute']};
85-
}
86-
?></td>
85+
}
86+
?></td>
8787
@elseif (isset($column['type']) && $column['type']=='model_function')
8888
{{-- custom return value --}}
8989
<td><?php
9090
echo $entry->{$column['function_name']}();
91-
?></td>
91+
?></td>
9292
@else
9393
{{-- regular object attribute --}}
9494
<td>{{ str_limit(strip_tags($entry->$column['name']), 80, "[...]") }}</td>

0 commit comments

Comments
 (0)