Completed
Pull Request — master (#20)
by
unknown
02:56
created

CommandTrait::setType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace Notamedia\ConsoleJedi\Schema\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Bitrix\Main\IO\Directory;
7
use Bitrix\Main\SiteTable;
8
use Bitrix\Iblock\TypeTable;
9
use Bitrix\Iblock\IblockTable;
10
11
/**
12
 * Class CommandTrait
13
 * @package Notamedia\ConsoleJedi\Schema\Command
14
 */
15
trait CommandTrait
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $errors = [];
21
22
    /**
23
     * @var array
24
     */
25
    protected $sites = [];
26
27
    /**
28
     * @var string
29
     */
30
    protected $type = '';
31
32
    /**
33
     * @var array
34
     */
35
    protected $iblocks = [];
36
37
    /**
38
     * @var string
39
     */
40
    protected $dir;
41
42
    /**
43
     * @var string
44
     */
45
    protected $extension = '.xml';
46
47
    /**
48
     * @param InputInterface $input
49
     */
50
    private function setDir(InputInterface $input)
51
    {
52
        $dir = $input->getArgument('dir');
53
54
        if (!$dir) {
55
            $dir = getcwd();
56
        }
57
58
        $dir = rtrim($dir, '/');
59
60
        if (!Directory::isDirectoryExists($dir) || !Directory::isDirectory($dir)) {
61
            $this->errors[] = 'Directory not found';
62
        }
63
64
        $this->dir = $dir;
65
    }
66
67
    /**
68
     * @param InputInterface $input
69
     */
70
    private function setIblocks(InputInterface $input)
71
    {
72
        $iblocks = IblockTable::query()
73
            ->setFilter([
74
                'IBLOCK_TYPE_ID' => $input->getArgument('type'),
75
                'CODE' => $input->getArgument('code')
76
            ])
77
            ->setSelect(['ID', 'CODE'])
78
            ->exec();
79
80
        if ($iblocks->getSelectedRowsCount() <= 0) {
81
            $this->errors[] = 'Iblock(s) not found';
82
        }
83
84
        $this->iblocks = $iblocks->fetchAll();
85
    }
86
87
    /**
88
     * @param InputInterface $input
89
     */
90 View Code Duplication
    private function setType(InputInterface $input)
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...
91
    {
92
        $type = TypeTable::query()
93
            ->setFilter([
94
                'ID' => $input->getArgument('type'),
95
            ])
96
            ->setSelect(['ID'])
97
            ->exec();
98
99
        if ($type->getSelectedRowsCount() <= 0) {
100
            $this->errors[] = 'Type not found';
101
        }
102
103
        $this->type = $type->fetch()['ID'];
104
    }
105
106
    /**
107
     * @param InputInterface $input
108
     */
109 View Code Duplication
    private function setSites(InputInterface $input)
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...
110
    {
111
        $sites = SiteTable::query()
112
            ->setFilter([
113
                'LID' => $input->getArgument('sites'),
114
            ])
115
            ->setSelect(['LID'])
116
            ->exec();
117
118
        if ($sites->getSelectedRowsCount() <= 0) {
119
            $this->errors[] = 'Sites not found';
120
        }
121
122
        $this->sites = $sites->fetchAll();
123
    }
124
}