Completed
Branch master (b4ab83)
by Mikołaj
03:16
created

DelForm   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 35
loc 35
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setModel() 4 4 1
A check() 9 9 1
A delete() 12 12 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 Rudolf\Modules\Galleries\One\Admin;
4
5
use Rudolf\Component\Forms\Form;
6
use Rudolf\Component\Alerts\Alert;
7
use Rudolf\Component\Alerts\AlertsCollection;
8
9 View Code Duplication
class DelForm extends Form
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...
10
{
11
    /**
12
     * @var DelModel
13
     */
14
    protected $model;
15
16
    public function setModel(DelModel $model)
17
    {
18
        $this->model = $model;
19
    }
20
21
    public function check()
22
    {
23
        $this->validator
0 ignored issues
show
Bug introduced by
The property validator 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...
24
            ->checkIsInt('id', $this->data['id'], [
25
                'not_int' => _('Page ID is not valid'),
26
            ]);
27
28
        $this->id = $this->data['id'];
0 ignored issues
show
Bug introduced by
The property id 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...
29
    }
30
31
    public function delete()
32
    {
33
        $status = $this->model->delete($this->id);
34
35
        if ($status) {
36
            AlertsCollection::add(new Alert(
37
                'success', 'Pomyślnie usunięto galerię.'
38
            ));
39
        }
40
41
        return $status;
42
    }
43
}
44