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 (#136)
by Owen
03:20
created

CheckUnique   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 37
rs 10
wmc 6
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B checkUniqueString() 0 30 6
1
<?php
2
3
namespace Backpack\CRUD\app\Http\Controllers\CrudFeatures;
4
5
trait CheckUnique
6
{
7
    /**
8
     * Checks if the given string is unique, and return existing entity.
9
     * @return JSON containing success, message and data.
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
10
     */
11
    public function checkUniqueString()
12
    {
13
        $response = ['success' => false, 'message' => trans('backpack::crud.unique_error'), 'meta' => ['link' => null, 'snippet' => null, 'entity_key' => null]];
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 161 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...
14
15
        $field_name = \Request::input('field_name', null);
16
        $check_value = \Request::input('check_value', null);
17
        $display_name = \Request::input('display_name', null);
18
19
        if (empty($field_name)) {
20
            $response['message'] = trans('backpack::crud.unique_field_name_missing');
21
        } elseif (empty($check_value) && $check_value !== '0') {
22
            $response['message'] = trans('backpack::crud.unique_check_value_missing');
23
        } else {
24
            $existing_entity = $this->crud->model->where([$field_name => $check_value])->first();
0 ignored issues
show
Bug introduced by
The property crud does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
26
            if (! $existing_entity) {
27
                $response['success'] = true;
28
                $response['message'] = null;
29
            } else {
30
                $response['message'] = $this->crud->entity_name.' '.trans('backpack::crud.unique_exists');
31
                $response['meta'] = [
32
                   'link' => url($this->crud->route.'/'.$existing_entity->getKey().'/edit'),
33
                   'snippet' => $display_name ? $existing_entity->{$display_name} : $this->crud->entity_name,
34
                   'entity_key' => $existing_entity->getKey(),
35
               ];
36
            }
37
        }
38
39
        return $response;
40
    }
41
}
42