Issues (53)

src/Iblock/IblockModel.php (7 issues)

1
<?php
2
3
namespace Alex19pov31\BitrixHelper\Iblock;
4
5
use Bitrix\Main\ORM\Query\Result;
0 ignored issues
show
The type Bitrix\Main\ORM\Query\Result 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\AddResult;
0 ignored issues
show
The type Bitrix\Main\ORM\Data\AddResult 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\Data\UpdateResult;
0 ignored issues
show
The type Bitrix\Main\ORM\Data\UpdateResult 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\Data\DeleteResult;
0 ignored issues
show
The type Bitrix\Main\ORM\Data\DeleteResult 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
10
abstract class IblockModel
11
{
12
    const TTL = 3600;
13
14
    /**
15
     * Объект для работы с инфоблоком
16
     *
17
     * @var IblockElementTable
18
     */
19
    private static $entity;
20
21
    abstract protected static function getIblockCode(): string;
22
23
    /**
24
     * Возвращает элемент по идентификатору
25
     *
26
     * @param integer $id
27
     * @return array|null
28
     */
29
    public static function getById(int $id)
30
    {
31
        return static::getList([
32
            'filter' => [
33
                'ID' => $id,
34
            ],
35
        ])->fetch();
36
    }
37
38
    /**
39
     * Список элементов
40
     *
41
     * @param array $params
42
     * @return Result
43
     */
44
    public static function getList(array $params): Result
45
    {
46
        if (empty($params['cache'])) {
47
            $params['cache']['ttl'] = static::TTL;
48
        }
49
50
        return static::getEntity()->getList($params);
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::getEntity()->getList($params) returns the type null which is incompatible with the type-hinted return Bitrix\Main\ORM\Query\Result.
Loading history...
Are you sure the usage of static::getEntity()->getList($params) targeting Alex19pov31\BitrixHelper...ElementTable::getList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
51
    }
52
53
    /**
54
     * Добавление элемента
55
     *
56
     * @param array $data
57
     * @return AddResult
58
     */
59
    public static function add(array $data): AddResult
60
    {
61
        return static::getEntity()->add($data);
62
    }
63
64
    /**
65
     * Обновление элемента
66
     *
67
     * @param integer $id
68
     * @param array $data
69
     * @return UpdateResult
70
     */
71
    public static function update(int $id, array $data): UpdateResult
72
    {
73
        return static::getEntity()->update($id, $data);
74
    }
75
76
    /**
77
     * Удаление элемента по идентификатору
78
     *
79
     * @param integer $id
80
     * @return DeleteResult
81
     */
82
    public static function delete(int $id): DeleteResult
83
    {
84
        return static::getEntity()->delete($id);
85
    }
86
87
    /**
88
     * Объект для работы с инфоблоком
89
     *
90
     * @return IblockElementTable
91
     */
92
    private static function getEntity(): IblockElementTable
93
    {
94
        if (!is_null(static::$entity)) {
0 ignored issues
show
Since $entity 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 $entity to at least protected.
Loading history...
95
            return static::$entity;
96
        }
97
98
        return static::$entity = new  class (static::getIblockCode()) extends IblockElementTable
99
        { };
100
    }
101
}
102