Skip to content

Commit 6f7f1a0

Browse files
committed
Add list collection
1 parent 6654ff5 commit 6f7f1a0

15 files changed

+111
-32
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88

9-
## [Unreleased](https://github.com/inspirum/arrayable-php/compare/v1.2.1...master)
9+
## [Unreleased](https://github.com/inspirum/arrayable-php/compare/v1.3.0...master)
10+
11+
12+
## [v1.3.0 (2023-03-19)](https://github.com/inspirum/balikobot-php/compare/v1.3.0...v1.2.1)
13+
### Added
14+
- Support `list` collections
15+
- Added [**ListCollection**](./src/ListCollection.php) interface
16+
- Added [**BaseListCollection**](./src/BaseListCollection.php) abstract class
1017

1118

1219
## [v1.2.1 (2023-09-10)](https://github.com/inspirum/balikobot-php/compare/v1.2.0...v1.2.1)

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
"ext-json": "*"
2121
},
2222
"require-dev": {
23-
"inspirum/coding-standard": "^1.5",
24-
"phpstan/phpstan": "^1.10",
23+
"inspirum/coding-standard": "^1.6",
24+
"phpstan/phpstan": "^1.12",
2525
"phpunit/phpunit": "^10.5",
26-
"shipmonk/composer-dependency-analyser": "^1.5",
27-
"squizlabs/php_codesniffer": "^3.9"
26+
"shipmonk/composer-dependency-analyser": "^1.7",
27+
"squizlabs/php_codesniffer": "^3.10"
2828
},
2929
"autoload": {
3030
"psr-4": {

core/Arrayable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @template TKey of array-key
88
* @template TValue
99
*
10-
* @extends \Inspirum\Arrayable\Arrayable<TKey, TValue>
10+
* @extends \Inspirum\Arrayable\Arrayable<TKey,TValue>
1111
*/
1212
interface Arrayable extends \Inspirum\Arrayable\Arrayable
1313
{

core/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function is_arrayable(mixed $data): bool
1818
/**
1919
* Cast anything to array
2020
*
21-
* @return array<int|string, mixed>
21+
* @return array<int|string,mixed>
2222
*/
2323
function to_array(mixed $data, ?int $limit = null): array
2424
{

src/Arrayable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
interface Arrayable
1212
{
1313
/**
14-
* @return array<TKey, TValue>
14+
* @return array<TKey,TValue>
1515
*/
1616
public function __toArray(): array;
1717
}

src/BaseCollection.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
abstract class BaseCollection implements Collection
2323
{
2424
/**
25-
* @param array<TKey, TValue> $items
25+
* @param array<TKey,TValue> $items
2626
*/
2727
public function __construct(
2828
protected array $items = [],
@@ -78,39 +78,39 @@ public function count(): int
7878
}
7979

8080
/**
81-
* @return \Traversable<TKey, TValue>
81+
* @return \Traversable<TKey,TValue>
8282
*/
8383
public function getIterator(): Traversable
8484
{
8585
return new ArrayIterator($this->items);
8686
}
8787

8888
/**
89-
* @return array<TKey, TValue>
89+
* @return array<TKey,TValue>
9090
*/
9191
public function getItems(): array
9292
{
9393
return $this->items;
9494
}
9595

9696
/**
97-
* @return array<TKey, array<TItemKey, TItemValue>>
97+
* @return array<TKey,array<TItemKey,TItemValue>>
9898
*/
9999
public function __toArray(): array
100100
{
101-
return array_map(static fn(Arrayable $item): array => $item->__toArray(), $this->items);
101+
return array_map(static fn (Arrayable $item): array => $item->__toArray(), $this->items);
102102
}
103103

104104
/**
105-
* @return array<TKey, array<TItemKey, TItemValue>>
105+
* @return array<TKey,array<TItemKey,TItemValue>>
106106
*/
107107
public function toArray(): array
108108
{
109109
return $this->__toArray();
110110
}
111111

112112
/**
113-
* @return array<TKey, array<TItemKey, TItemValue>>
113+
* @return array<TKey,array<TItemKey,TItemValue>>
114114
*/
115115
public function jsonSerialize(): array
116116
{

src/BaseListCollection.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Inspirum\Arrayable;
6+
7+
use Inspirum\Arrayable\Arrayable as TValue;
8+
use function array_values;
9+
10+
/**
11+
* @template TItemKey of array-key
12+
* @template TItemValue
13+
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey,TItemValue>
14+
* @extends \Inspirum\Arrayable\BaseCollection<TItemKey,TItemValue,int,TValue>
15+
*/
16+
abstract class BaseListCollection extends BaseCollection
17+
{
18+
/**
19+
* @param list<TValue> $items
20+
*/
21+
public function __construct(array $items = [])
22+
{
23+
parent::__construct($items);
24+
}
25+
26+
/**
27+
* @return list<TValue>
28+
*/
29+
public function getItems(): array
30+
{
31+
return array_values(parent::getItems());
32+
}
33+
34+
/**
35+
* @return list<array<TItemKey,TItemValue>>
36+
*/
37+
public function __toArray(): array
38+
{
39+
return array_values(parent::__toArray());
40+
}
41+
42+
/**
43+
* @return list<array<TItemKey,TItemValue>>
44+
*/
45+
public function toArray(): array
46+
{
47+
return array_values(parent::toArray());
48+
}
49+
50+
/**
51+
* @return list<array<TItemKey,TItemValue>>
52+
*/
53+
public function jsonSerialize(): array
54+
{
55+
return array_values(parent::jsonSerialize());
56+
}
57+
}

src/BaseModel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010
/**
1111
* @template TKey of array-key
1212
* @template TValue
13-
* @implements \Inspirum\Arrayable\Model<TKey, TValue>
13+
* @implements \Inspirum\Arrayable\Model<TKey,TValue>
1414
*/
1515
abstract class BaseModel implements Model
1616
{
1717
/**
18-
* @return array<TKey, TValue>
18+
* @return array<TKey,TValue>
1919
*/
2020
abstract public function __toArray(): array;
2121

2222
/**
23-
* @return array<TKey, TValue>
23+
* @return array<TKey,TValue>
2424
*/
2525
public function toArray(): array
2626
{
2727
return $this->__toArray();
2828
}
2929

3030
/**
31-
* @return array<TKey, TValue>
31+
* @return array<TKey,TValue>
3232
*/
3333
public function jsonSerialize(): array
3434
{

src/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* @template TItemKey of array-key
1515
* @template TItemValue
1616
* @template TKey of array-key
17-
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey, TItemValue>
18-
* @extends \ArrayAccess<TKey, TValue>
19-
* @extends \IteratorAggregate<TKey, TValue>
20-
* @extends \Inspirum\Arrayable\Arrayable<TKey, array<TItemKey, TItemValue>>
17+
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey,TItemValue>
18+
* @extends \ArrayAccess<TKey,TValue>
19+
* @extends \IteratorAggregate<TKey,TValue>
20+
* @extends \Inspirum\Arrayable\Arrayable<TKey, array<TItemKey,TItemValue>>
2121
*/
2222
interface Collection extends ArrayAccess, Countable, IteratorAggregate, Arrayable, JsonSerializable, Stringable
2323
{

src/Convertor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function isArrayable(mixed $data): bool
2525
*
2626
* @param positive-int|null $limit
2727
*
28-
* @return array<int|string, mixed>
28+
* @return array<int|string,mixed>
2929
*
3030
* @throws \RuntimeException
3131
*/

0 commit comments

Comments
 (0)