OnBeforeIBlockUpdate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 2
A getName() 4 4 1
A getTemplate() 4 4 1
A getReplace() 7 7 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 View Code Duplication
class OnBeforeIBlockUpdate extends BaseHandler implements HandlerInterface
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...
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
        // Если кода нет то миграция создастся битая.
20
        // Еще это позволяет решить проблему с тем что создается лишняя миграция для торгового каталога
21
        // когда обновляют связанный с ним инфоблок.
22
        if (!$this->fields['CODE']) {
23
            throw new SkipHandlerException();
24
        }
25
    }
26
27
    /**
28
     * Get migration name.
29
     *
30
     * @return string
31
     */
32
    public function getName()
33
    {
34
        return "auto_update_iblock_{$this->fields['CODE']}";
35
    }
36
37
    /**
38
     * Get template name.
39
     *
40
     * @return string
41
     */
42
    public function getTemplate()
43
    {
44
        return 'auto_update_iblock';
45
    }
46
47
    /**
48
     * Get array of placeholders to replace.
49
     *
50
     * @return array
51
     */
52
    public function getReplace()
53
    {
54
        return [
55
            'fields' => var_export($this->fields, true),
56
            'code'   => "'".$this->fields['CODE']."'",
57
        ];
58
    }
59
}
60