OnBeforeIBlockPropertyAdd   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 15.69 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 8
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getName() 0 4 1
A getTemplate() 0 4 1
A getReplace() 8 8 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 Arrilot\BitrixMigrations\Exceptions\SkipHandlerException;
6
7
class OnBeforeIBlockPropertyAdd extends BaseHandler implements HandlerInterface
8
{
9
    /**
10
     * Constructor.
11
     *
12
     * @param array $params
13
     * @throws SkipHandlerException
14
     */
15
    public function __construct($params)
16
    {
17
        $this->fields = $params[0];
18
19
        if (!$this->fields['IBLOCK_ID']) {
20
            throw new SkipHandlerException();
21
        }
22
    }
23
24
    /**
25
     * Get migration name.
26
     *
27
     * @return string
28
     */
29
    public function getName()
30
    {
31
        return "auto_add_iblock_element_property_{$this->fields['CODE']}_to_ib_{$this->fields['IBLOCK_ID']}";
32
    }
33
34
    /**
35
     * Get template name.
36
     *
37
     * @return string
38
     */
39
    public function getTemplate()
40
    {
41
        return 'auto_add_iblock_element_property';
42
    }
43
44
    /**
45
     * Get array of placeholders to replace.
46
     *
47
     * @return array
48
     */
49 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...
50
    {
51
        return [
52
            'fields'   => var_export($this->fields, true),
53
            'iblockId' => $this->fields['IBLOCK_ID'],
54
            'code'     => "'".$this->fields['CODE']."'",
55
        ];
56
    }
57
}
58