Issues (53)

src/Iblock/IblockPropertyTable.php (7 issues)

1
<?php
2
3
namespace Alex19pov31\BitrixHelper\Iblock;
4
5
use Bitrix\Iblock\PropertyTable;
0 ignored issues
show
The type Bitrix\Iblock\PropertyTable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Bitrix\Main\ORM\Data\DataManager;
0 ignored issues
show
The type Bitrix\Main\ORM\Data\DataManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Bitrix\Main\ORM\Fields\IntegerField;
0 ignored issues
show
The type Bitrix\Main\ORM\Fields\IntegerField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Bitrix\Main\ORM\Fields\StringField;
0 ignored issues
show
The type Bitrix\Main\ORM\Fields\StringField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Bitrix\Sender\Connector\Filter\NumberField;
0 ignored issues
show
The type Bitrix\Sender\Connector\Filter\NumberField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
abstract class IblockPropertyTable extends DataManager
12
{
13
    const TTL = 180;
14
15
    private static $map;
16
    protected static $iblockCode;
17
18
    public function __construct(string $iblockCode) {
19
        $this->iblockCode = $iblockCode;
20
    }
21
22
    public static function getIblockId()
23
    {
24
        return getIblockId(static::$iblockCode, 180);
25
    }
26
27
    public static function getTableName()
28
    {
29
        return 'b_iblock_element_prop_s' . static::getIblockId();
30
    }
31
32
    /**
33
     * Карта свойств
34
     *
35
     * @return void
36
     */
37
    public static function getMap()
38
    {
39
        if (!is_null(static::$map['IBLOCK_CODE'])) {
0 ignored issues
show
Since $map is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $map to at least protected.
Loading history...
40
            return static::$map['IBLOCK_CODE'];
41
        }
42
43
        $propertyList = PropertyTable::getList([
44
            'filter' => [
45
                'IBLOCK_ID' => static::getIblockId(),
46
            ],
47
            'cache' => [
48
                'ttl' => static::TTL * 60,
49
            ],
50
        ])->fetchAll();
51
52
        $fields = [
53
            'IBLOCK_ELEMENT_ID' => new IntegerField(
54
                'IBLOCK_ELEMENT_ID',
55
                [
56
                    'title' => 'Идентификатор элемента инфоблока',
57
                ]
58
            ),
59
        ];
60
        foreach ($propertyList as $property) {
61
            $class = StringField::class;
62
            switch ($property['PROPERTY_TYPE']) {
63
                case PropertyTable::TYPE_STRING:
64
                    $class = StringField::class;
65
                    break;
66
                case PropertyTable::TYPE_NUMBER:
67
                    $class = NumberField::class;
68
                    break;
69
                case PropertyTable::TYPE_FILE:
70
                    $class = NumberField::class;
71
                    break;
72
                case PropertyTable::TYPE_ELEMENT:
73
                    $class = StringField::class;
74
                    break;
75
                case PropertyTable::TYPE_SECTION:
76
                    $class = StringField::class;
77
                    break;
78
                case PropertyTable::TYPE_LIST:
79
                    $class = StringField::class;
80
                    break;
81
            }
82
83
            $fields[$property['CODE']] = new $class(
84
                'PROPERTY_' . $property['ID'],
85
                [
86
                    'title' => $property['NAME'],
87
                ]
88
            );
89
        }
90
91
        return static::$map['IBLOCK_CODE'] = $fields;
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::map['IBLOCK_CODE'] = $fields returns the type array<string,Bitrix\Main\ORM\Fields\IntegerField> which is incompatible with the documented return type void.
Loading history...
92
    }
93
}
94