OnBeforeUserTypeDelete   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 19.15 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 9
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A getName() 0 4 1
A getTemplate() 0 4 1
A getReplace() 9 9 1

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 Arrilot\BitrixMigrations\Autocreate\Handlers;
4
5
use CUserTypeEntity;
6
7
class OnBeforeUserTypeDelete extends BaseHandler implements HandlerInterface
8
{
9
    /**
10
     * Constructor.
11
     *
12
     * @param array $params
13
     */
14
    public function __construct($params)
15
    {
16
        $this->fields = is_array($params[0]) ? $params[0] : CUserTypeEntity::getByID($params[0]);
17
    }
18
19
    /**
20
     * Get migration name.
21
     *
22
     * @return string
23
     */
24
    public function getName()
25
    {
26
        return "auto_delete_uf_{$this->fields['FIELD_NAME']}_from_entity_{$this->fields['ENTITY_ID']}";
27
    }
28
29
    /**
30
     * Get template name.
31
     *
32
     * @return string
33
     */
34
    public function getTemplate()
35
    {
36
        return 'auto_delete_uf';
37
    }
38
39
    /**
40
     * Get array of placeholders to replace.
41
     *
42
     * @return array
43
     */
44 View Code Duplication
    public function getReplace()
0 ignored issues
show
Duplication introduced by
This method 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...
45
    {
46
        return [
47
            'iblockId' => $this->fields['IBLOCK_ID'],
48
            'code'     => "'".$this->fields['FIELD_NAME']."'",
49
            'entity'   => "'".$this->fields['ENTITY_ID']."'",
50
            'fields'   => var_export($this->fields, true),
51
        ];
52
    }
53
}
54