OnBeforeIBlockDelete   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A getTemplate() 0 4 1
A getReplace() 0 6 1
A getIBlockById() 0 9 1
1
<?php
2
3
namespace Arrilot\BitrixMigrations\Autocreate\Handlers;
4
5
use CIBlock;
6
7
class OnBeforeIBlockDelete extends BaseHandler implements HandlerInterface
8
{
9
    /**
10
     * Constructor.
11
     *
12
     * @param array $params
13
     */
14
    public function __construct($params)
15
    {
16
        $this->fields = $this->getIBlockById($params[0]);
17
    }
18
19
    /**
20
     * Get migration name.
21
     *
22
     * @return string
23
     */
24
    public function getName()
25
    {
26
        return "auto_delete_iblock_{$this->fields['CODE']}";
27
    }
28
29
    /**
30
     * Get template name.
31
     *
32
     * @return string
33
     */
34
    public function getTemplate()
35
    {
36
        return 'auto_delete_iblock';
37
    }
38
39
    /**
40
     * Get array of placeholders to replace.
41
     *
42
     * @return array
43
     */
44
    public function getReplace()
45
    {
46
        return [
47
            'code' => "'".$this->fields['CODE']."'",
48
        ];
49
    }
50
51
    /**
52
     * Get iblock by id without checking permissions.
53
     *
54
     * @param $id
55
     *
56
     * @return array
57
     */
58
    protected function getIBlockById($id)
59
    {
60
        $filter = [
61
            'ID'                => $id,
62
            'CHECK_PERMISSIONS' => 'N',
63
        ];
64
65
        return (new CIBlock())->getList([], $filter)->fetch();
66
    }
67
}
68