Passed
Push — trunk ( a4e569...0674cc )
by Christian
14:29 queued 12s
created

IndexerOffset::setLanguageId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Elasticsearch\Framework\Indexing;
4
5
use Shopware\Core\Framework\Feature;
6
use Shopware\Core\Framework\Log\Package;
7
use Shopware\Elasticsearch\Framework\AbstractElasticsearchDefinition;
8
9
#[Package('core')]
10
class IndexerOffset
11
{
12
    /**
13
     * @var list<string>
0 ignored issues
show
Bug introduced by
The type Shopware\Elasticsearch\Framework\Indexing\list 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...
14
     */
15
    protected array $definitions;
16
17
    /**
18
     * @var list<string>
19
     */
20
    protected array $allDefinitions;
21
22
    /**
23
     * @deprecated tag:v6.6.0 - Property $languageId will be removed.
24
     */
25
    protected ?string $languageId = null;
26
27
    protected ?string $definition = null;
28
29
    /**
30
     * @param list<string> $languages
31
     * @param iterable<AbstractElasticsearchDefinition>|iterable<string> $mappingDefinitions
32
     * @param array{offset: int|null}|null $lastId
33
     *
34
     * @deprecated tag:v6.6.0 - Parameter $languages will be removed.
35
     */
36
    public function __construct(
37
        protected array $languages,
38
        iterable $mappingDefinitions,
39
        protected ?int $timestamp,
40
        protected ?array $lastId = null
41
    ) {
42
        $mapping = [];
43
        /** @var AbstractElasticsearchDefinition|string $mappingDefinition */
44
        foreach ($mappingDefinitions as $mappingDefinition) {
45
            if ($mappingDefinition instanceof AbstractElasticsearchDefinition) {
46
                Feature::triggerDeprecationOrThrow('v6.6.0.0', 'Passing definitions objects is deprecated. Pass the entity name instead.');
47
                $mapping[] = $mappingDefinition->getEntityDefinition()->getEntityName();
48
            } else {
49
                $mapping[] = $mappingDefinition;
50
            }
51
        }
52
53
        $this->allDefinitions = $mapping;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mapping of type array or array or string[] is incompatible with the declared type Shopware\Elasticsearch\Framework\Indexing\list of property $allDefinitions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54
        $this->definitions = $mapping;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mapping of type array or array or string[] is incompatible with the declared type Shopware\Elasticsearch\Framework\Indexing\list of property $definitions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
56
        if (!Feature::isActive('ES_MULTILINGUAL_INDEX')) {
57
            $this->selectNextLanguage();
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Elasticsearch\F...t::selectNextLanguage() has been deprecated: tag:v6.6.0 - reason:remove-getter-setter - will be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

57
            /** @scrutinizer ignore-deprecated */ $this->selectNextLanguage();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
58
        }
59
60
        $this->selectNextDefinition();
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Elasticsearch\F...:selectNextDefinition() has been deprecated: tag:v6.6.0 - reason:return-type-change - will be changed to void and not return anything anymore ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

60
        /** @scrutinizer ignore-deprecated */ $this->selectNextDefinition();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
61
    }
62
63
    /**
64
     * @deprecated tag:v6.6.0 - Will be removed. Use selectNextDefinition instead
65
     *
66
     * @phpstan-ignore-next-line ignore needs to be removed when deprecation is removed
67
     */
68
    public function setNextDefinition(): ?string
69
    {
70
        Feature::triggerDeprecationOrThrow(
71
            'v6.6.0.0',
72
            Feature::deprecatedMethodMessage(__CLASS__, __METHOD__, 'v6.6.0.0', 'selectNextDefinition')
73
        );
74
75
        return $this->selectNextDefinition();
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Elasticsearch\F...:selectNextDefinition() has been deprecated: tag:v6.6.0 - reason:return-type-change - will be changed to void and not return anything anymore ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

75
        return /** @scrutinizer ignore-deprecated */ $this->selectNextDefinition();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
76
    }
77
78
    /**
79
     * @deprecated tag:v6.6.0 - reason:return-type-change - will be changed to void and not return anything anymore
80
     */
81
    public function selectNextDefinition(): ?string
82
    {
83
        return $this->definition = array_shift($this->definitions);
84
    }
85
86
    public function resetDefinitions(): void
87
    {
88
        $this->definitions = $this->allDefinitions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->allDefinitions of type array is incompatible with the declared type Shopware\Elasticsearch\Framework\Indexing\list of property $allDefinitions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Documentation Bug introduced by
It seems like $this->allDefinitions of type array is incompatible with the declared type Shopware\Elasticsearch\Framework\Indexing\list of property $definitions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
89
        $this->definition = array_shift($this->definitions);
90
    }
91
92
    public function hasNextDefinition(): bool
93
    {
94
        return !empty($this->definitions);
95
    }
96
97
    /**
98
     * @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed.
99
     *
100
     * @phpstan-ignore-next-line ignore needs to be removed when deprecation is removed
101
     */
102
    public function setNextLanguage(): ?string
103
    {
104
        Feature::triggerDeprecationOrThrow(
105
            'v6.6.0.0',
106
            Feature::deprecatedMethodMessage(__CLASS__, __METHOD__, 'v6.6.0.0', 'selectNextLanguage')
107
        );
108
109
        return $this->selectNextLanguage();
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Elasticsearch\F...t::selectNextLanguage() has been deprecated: tag:v6.6.0 - reason:remove-getter-setter - will be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

109
        return /** @scrutinizer ignore-deprecated */ $this->selectNextLanguage();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
110
    }
111
112
    /**
113
     * @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed.
114
     */
115
    public function selectNextLanguage(): ?string
116
    {
117
        return $this->languageId = array_shift($this->languages);
0 ignored issues
show
Deprecated Code introduced by
The property Shopware\Elasticsearch\F...exerOffset::$languageId has been deprecated: tag:v6.6.0 - Property $languageId will be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

117
        return /** @scrutinizer ignore-deprecated */ $this->languageId = array_shift($this->languages);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
118
    }
119
120
    /**
121
     * @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed.
122
     */
123
    public function hasNextLanguage(): bool
124
    {
125
        return !empty($this->languages);
126
    }
127
128
    /**
129
     * @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed.
130
     */
131
    public function getLanguageId(): ?string
132
    {
133
        return $this->languageId;
0 ignored issues
show
Deprecated Code introduced by
The property Shopware\Elasticsearch\F...exerOffset::$languageId has been deprecated: tag:v6.6.0 - Property $languageId will be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

133
        return /** @scrutinizer ignore-deprecated */ $this->languageId;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
134
    }
135
136
    /**
137
     * @return list<string>
138
     *
139
     * @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed.
140
     */
141
    public function getLanguages(): array
142
    {
143
        return $this->languages;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->languages returns the type array which is incompatible with the documented return type Shopware\Elasticsearch\Framework\Indexing\list.
Loading history...
144
    }
145
146
    /**
147
     * @return list<string>
148
     */
149
    public function getDefinitions(): array
150
    {
151
        return $this->definitions;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->definitions returns the type array which is incompatible with the documented return type Shopware\Elasticsearch\Framework\Indexing\list.
Loading history...
152
    }
153
154
    public function getTimestamp(): ?int
155
    {
156
        return $this->timestamp;
157
    }
158
159
    /**
160
     * @return array{offset: int|null}|null
161
     */
162
    public function getLastId(): ?array
163
    {
164
        return $this->lastId;
165
    }
166
167
    public function getDefinition(): ?string
168
    {
169
        return $this->definition;
170
    }
171
172
    /**
173
     * @param array{offset: int|null}|null $lastId
174
     */
175
    public function setLastId(?array $lastId): void
176
    {
177
        $this->lastId = $lastId;
178
    }
179
180
    /**
181
     * @internal This method is internal and will be used by Symfony serializer
182
     *
183
     * @return array<string>
184
     */
185
    public function getAllDefinitions(): array
186
    {
187
        return $this->allDefinitions;
188
    }
189
190
    /**
191
     * @param list<string> $allDefinitions
192
     *
193
     * @internal This method is internal and will be used by Symfony serializer
194
     */
195
    public function setAllDefinitions(array $allDefinitions): void
196
    {
197
        $this->allDefinitions = $allDefinitions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $allDefinitions of type array is incompatible with the declared type Shopware\Elasticsearch\Framework\Indexing\list of property $allDefinitions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
198
    }
199
200
    /**
201
     * @param list<string> $definitions
202
     *
203
     * @internal This method is internal and will be used by Symfony serializer
204
     */
205
    public function setDefinitions(array $definitions): void
206
    {
207
        $this->definitions = $definitions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $definitions of type array is incompatible with the declared type Shopware\Elasticsearch\Framework\Indexing\list of property $definitions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
208
    }
209
210
    /**
211
     * @deprecated tag:v6.6.0 - reason:remove-getter-setter - will be removed.
212
     *
213
     * @internal This method is internal and will be used by Symfony serializer
214
     */
215
    public function setLanguageId(?string $languageId): void
216
    {
217
        $this->languageId = $languageId;
0 ignored issues
show
Deprecated Code introduced by
The property Shopware\Elasticsearch\F...exerOffset::$languageId has been deprecated: tag:v6.6.0 - Property $languageId will be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

217
        /** @scrutinizer ignore-deprecated */ $this->languageId = $languageId;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
218
    }
219
220
    /**
221
     * @internal This method is internal and will be used by Symfony serializer
222
     */
223
    public function setDefinition(?string $definition): void
224
    {
225
        $this->definition = $definition;
226
    }
227
}
228