Passed
Push — trunk ( 0e4c2d...148418 )
by Christian
12:04 queued 12s
created

IndexerOffset::selectNextLanguage()   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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
    protected ?string $languageId = null;
23
24
    protected ?string $definition = null;
25
26
    /**
27
     * @param list<string> $languages
28
     * @param iterable<AbstractElasticsearchDefinition> $definitions
29
     * @param array{offset: int|null}|null $lastId
30
     */
31
    public function __construct(
32
        protected array $languages,
33
        iterable $definitions,
34
        protected ?int $timestamp,
35
        protected ?array $lastId = null
36
    ) {
37
        $mapping = [];
38
        /** @var AbstractElasticsearchDefinition $definition */
39
        foreach ($definitions as $definition) {
40
            $mapping[] = $definition->getEntityDefinition()->getEntityName();
41
        }
42
43
        $this->allDefinitions = $mapping;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mapping of type array or 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...
44
        $this->definitions = $mapping;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mapping of type array or 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...
45
46
        $this->selectNextLanguage();
47
        $this->selectNextDefinition();
48
    }
49
50
    /**
51
     * @deprecated tag:v6.6.0 - Will be removed. Use selectNextDefinition instead
52
     *
53
     * @phpstan-ignore-next-line ignore needs to be removed when deprecation is removed
54
     */
55
    public function setNextDefinition(): ?string
56
    {
57
        Feature::triggerDeprecationOrThrow(
58
            'v6.6.0.0',
59
            Feature::deprecatedMethodMessage(__CLASS__, __METHOD__, 'v6.6.0.0', 'selectNextDefinition')
60
        );
61
62
        return $this->selectNextDefinition();
63
    }
64
65
    public function selectNextDefinition(): ?string
66
    {
67
        return $this->definition = array_shift($this->definitions);
68
    }
69
70
    public function resetDefinitions(): void
71
    {
72
        $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 $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...
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...
73
        $this->definition = array_shift($this->definitions);
74
    }
75
76
    public function hasNextDefinition(): bool
77
    {
78
        return !empty($this->definitions);
79
    }
80
81
    /**
82
     * @deprecated tag:v6.6.0 - Will be removed. Use selectNextLanguage instead
83
     *
84
     * @phpstan-ignore-next-line ignore needs to be removed when deprecation is removed
85
     */
86
    public function setNextLanguage(): ?string
87
    {
88
        Feature::triggerDeprecationOrThrow(
89
            'v6.6.0.0',
90
            Feature::deprecatedMethodMessage(__CLASS__, __METHOD__, 'v6.6.0.0', 'selectNextLanguage')
91
        );
92
93
        return $this->selectNextLanguage();
94
    }
95
96
    public function selectNextLanguage(): ?string
97
    {
98
        return $this->languageId = array_shift($this->languages);
99
    }
100
101
    public function hasNextLanguage(): bool
102
    {
103
        return !empty($this->languages);
104
    }
105
106
    public function getLanguageId(): ?string
107
    {
108
        return $this->languageId;
109
    }
110
111
    /**
112
     * @return list<string>
113
     */
114
    public function getLanguages(): array
115
    {
116
        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...
117
    }
118
119
    /**
120
     * @return list<string>
121
     */
122
    public function getDefinitions(): array
123
    {
124
        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...
125
    }
126
127
    public function getTimestamp(): ?int
128
    {
129
        return $this->timestamp;
130
    }
131
132
    /**
133
     * @return array{offset: int|null}|null
134
     */
135
    public function getLastId(): ?array
136
    {
137
        return $this->lastId;
138
    }
139
140
    public function getDefinition(): ?string
141
    {
142
        return $this->definition;
143
    }
144
145
    /**
146
     * @param array{offset: int|null}|null $lastId
147
     */
148
    public function setLastId(?array $lastId): void
149
    {
150
        $this->lastId = $lastId;
151
    }
152
}
153