AddForm   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setModel() 4 4 1
A add() 13 13 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\Alerts\Alert;
6
use Rudolf\Component\Alerts\AlertsCollection;
7
8 View Code Duplication
class AddForm extends FormCheck
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...
9
{
10
    /**
11
     * @var AddModel
12
     */
13
    protected $model;
14
15
    /**
16
     * @param AddModel $model
17
     */
18
    public function setModel(AddModel $model)
19
    {
20
        $this->model = $model;
21
    }
22
23
    /**
24
     * @return int
25
     * @throws \Exception
26
     */
27
    public function add()
28
    {
29
        $status = $this->model->add($this->dataValidated);
30
31
        if ($status) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $status of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
32
            AlertsCollection::add(new Alert(
33
                'success',
34
                'Pomyślnie dodano galerię.'
35
            ));
36
        }
37
38
        return $status;
39
    }
40
}
41