ThemeDetailViewModel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 23
loc 23
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setTitle() 6 6 2
A setAction() 6 6 2
A setMethod() 6 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\ViewModels;
4
5 View Code Duplication
class ThemeDetailViewModel extends FormViewModel
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
{
7
    protected function setTitle()
8
    {
9
        $this->title = $this->model->exists
10
            ? "Edit Theme: {$this->model->name}"
11
            : 'Create Theme';
12
    }
13
14
    protected function setAction()
15
    {
16
        $this->action = $this->model->exists
17
            ? route('backend.themes.update', $this->model)
0 ignored issues
show
Documentation introduced by
$this->model is of type object<Illuminate\Database\Eloquent\Model>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
18
            : route('backend.themes.store');
19
    }
20
21
    protected function setMethod()
22
    {
23
        $this->method = $this->model->exists
24
            ? 'PUT'
25
            : 'POST';
26
    }
27
}
28