OnBeforeGroupUpdate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 15.25 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 2
A getName() 0 4 1
A getTemplate() 0 4 1
A getReplace() 0 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\StopHandlerException;
6
7
class OnBeforeGroupUpdate extends BaseHandler implements HandlerInterface
8
{
9
    /**
10
     * Bitrix group id.
11
     *
12
     * @var int
13
     */
14
    protected $id;
15
16
    /**
17
     * Constructor.
18
     *
19
     * @param array $params
20
     *
21
     * @throws StopHandlerException
22
     */
23 View Code Duplication
    public function __construct($params)
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...
24
    {
25
        $this->id = $params[0];
26
        $this->fields = $params[1];
27
28
        if (!$this->fields['STRING_ID']) {
29
            throw new StopHandlerException('Code is required to create a migration');
30
        }
31
    }
32
33
    /**
34
     * Get migration name.
35
     *
36
     * @return string
37
     */
38
    public function getName()
39
    {
40
        return "auto_update_group_{$this->fields['STRING_ID']}";
41
    }
42
43
    /**
44
     * Get template name.
45
     *
46
     * @return string
47
     */
48
    public function getTemplate()
49
    {
50
        return 'auto_update_group';
51
    }
52
53
    /**
54
     * Get array of placeholders to replace.
55
     *
56
     * @return array
57
     */
58
    public function getReplace()
59
    {
60
        return [
61
            'fields' => var_export($this->fields, true),
62
            'id'     => $this->id,
63
        ];
64
    }
65
}
66