Skip to content

Commit 1b587a6

Browse files
committed
chore: cleanup Areas annotation
1 parent 3aaa734 commit 1b587a6

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# CHANGELOG
22

3+
## 4.36.1
4+
- Passing an array key `values` with a list of strings to the `Areas` annotation/attribute is deprecated. Pass the list of strings directly.
5+
```diff
6+
-#[Areas(properties: ['values' => ['foo', 'bar']])]
7+
+#[Areas(properties: ['foo', 'bar'])]
8+
9+
-#[Areas(['values' => ['foo', 'bar']])]
10+
+#[Areas(['foo', 'bar'])]
11+
```
12+
313
## 4.36.0
414
* Configuration option `with_annotation` has been deprecated in favor of `with_attribute`
515
```diff

src/Attribute/Areas.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ class Areas
2525
*/
2626
public function __construct(array $properties)
2727
{
28-
if (!array_key_exists('value', $properties) || !is_array($properties['value'])) {
29-
$properties['value'] = array_values($properties);
28+
if (array_key_exists('value', $properties) && is_array($properties['value'])) {
29+
trigger_deprecation('nelmio/api-doc-bundle', '4.36.1', 'Passing an array with key `value` is deprecated, pass the list of strings directly.');
30+
31+
$this->areas = array_values($properties['value']);
32+
} else {
33+
$this->areas = [];
34+
foreach ($properties as $area) {
35+
if (!is_string($area)) {
36+
throw new \InvalidArgumentException('An area must be given as a string');
37+
}
38+
39+
if (!in_array($area, $this->areas, true)) {
40+
$this->areas[] = $area;
41+
}
42+
}
3043
}
3144

32-
if ([] === $properties['value']) {
45+
if ([] === $this->areas) {
3346
throw new \InvalidArgumentException('An array of areas was expected');
3447
}
35-
36-
$areas = [];
37-
foreach ($properties['value'] as $area) {
38-
if (!is_string($area)) {
39-
throw new \InvalidArgumentException('An area must be given as a string');
40-
}
41-
42-
if (!in_array($area, $areas, true)) {
43-
$areas[] = $area;
44-
}
45-
}
46-
47-
$this->areas = $areas;
4848
}
4949

5050
public function has(string $area): bool

0 commit comments

Comments
 (0)