Skip to content

Commit 80eb301

Browse files
committed
Merge remote-tracking branch 'yii/master' into enh-getValue
2 parents 20da553 + cb102a3 commit 80eb301

17 files changed

+275
-103
lines changed

.gitattributes

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
/.gitattributes export-ignore
2828
/.gitignore export-ignore
2929
/.phpunit-watcher.yml export-ignore
30-
/.scrutinizer.yml export-ignore
3130
/.styleci.yml export-ignore
3231
/infection.json.dist export-ignore
3332
/phpunit.xml.dist export-ignore

.scrutinizer.yml

-35
This file was deleted.

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
## 4.0.0 under development
44

55
- Chg #142: Redefine the callable parameter in `ArrayHelper::getValue()` to be a value matcher (yus-ham)
6+
- Enh #156: Improve psalm types in `ArrayHelper::getObjectVars()`, `ArrayableInterface`, `ArrayableTrait` and
7+
`ArrayAccessTrait` (@vjik)
8+
9+
## 3.1.0 April 04, 2024
10+
611
- New #139: Add `ArrayHelper::parametrizedMerge()` method that allows to merge two or more arrays recursively with
712
specified depth (@vjik)
8-
- Enh #140: Remove `null` from return type of `ArrayHelper::getObjectVars()` method (@Tigrov)
13+
- New #149, #152: Add `ArrayrHelper::renameKey()` (@vjik, @Tigrov)
14+
- Enh #140: Remove `null` from return type of `ArrayHelper::getObjectVars()` method (@Tigrov)
15+
- Enh #152: Minor `ArrayableTrait` refactoring (@Tigrov)
916

1017
## 3.0.0 January 12, 2023
1118

LICENSE.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
Copyright © 2008 by Yii Software (https://www.yiiframework.com/)
1+
Copyright © 2008 by Yii Software (<https://www.yiiframework.com/>)
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without
55
modification, are permitted provided that the following conditions
66
are met:
77

8-
* Redistributions of source code must retain the above copyright
9-
notice, this list of conditions and the following disclaimer.
10-
* Redistributions in binary form must reproduce the above copyright
11-
notice, this list of conditions and the following disclaimer in
12-
the documentation and/or other materials provided with the
13-
distribution.
14-
* Neither the name of Yii Software nor the names of its
15-
contributors may be used to endorse or promote products derived
16-
from this software without specific prior written permission.
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
* Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in
12+
the documentation and/or other materials provided with the
13+
distribution.
14+
* Neither the name of Yii Software nor the names of its
15+
contributors may be used to endorse or promote products derived
16+
from this software without specific prior written permission.
1717

1818
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1919
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

README.md

+10-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<p align="center">
22
<a href="https://github.com/yiisoft" target="_blank">
3-
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px">
3+
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px" alt="Yii">
44
</a>
55
<h1 align="center">Yii Arrays</h1>
66
<br>
@@ -9,8 +9,7 @@
99
[![Latest Stable Version](https://poser.pugx.org/yiisoft/arrays/v/stable.png)](https://packagist.org/packages/yiisoft/arrays)
1010
[![Total Downloads](https://poser.pugx.org/yiisoft/arrays/downloads.png)](https://packagist.org/packages/yiisoft/arrays)
1111
[![Build status](https://github.com/yiisoft/arrays/workflows/build/badge.svg)](https://github.com/yiisoft/arrays/actions?query=workflow%3Abuild)
12-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/arrays/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/arrays/?branch=master)
13-
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/arrays/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/arrays/?branch=master)
12+
[![Code Coverage](https://codecov.io/gh/yiisoft/arrays/graph/badge.svg?token=SMTMNF4KT9)](https://codecov.io/gh/yiisoft/arrays)
1413
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Farrays%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/arrays/master)
1514
[![static analysis](https://github.com/yiisoft/arrays/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/arrays/actions?query=workflow%3A%22static+analysis%22)
1615
[![type-coverage](https://shepherd.dev/github/yiisoft/arrays/coverage.svg)](https://shepherd.dev/github/yiisoft/arrays)
@@ -88,6 +87,7 @@ Overall the helper has the following method groups.
8887
- map
8988
- merge
9089
- parametrizedMerge
90+
- renameKey
9191
- toArray
9292

9393
### Other
@@ -109,7 +109,7 @@ Array sorter has one static method which usage is like the following:
109109
[\IteratorAggregate](https://www.php.net/manual/class.iteratoraggregate),
110110
[\ArrayAccess](https://www.php.net/manual/class.arrayaccess) and
111111
[\Countable](https://www.php.net/manualn/class.countable.php).
112-
112+
113113
Note that `ArrayAccessTrait` requires the class using it contain a property named `data` which should be an array.
114114
The data will be exposed by ArrayAccessTrait to support accessing the class object like an array.
115115

@@ -164,36 +164,17 @@ $car = new Car();
164164
$data = $car->toArray(['type', 'color']); // ['type' => 'Crossover', 'color' => 'Red']
165165
```
166166

167-
## Testing
168-
169-
### Unit testing
170-
171-
The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
172-
173-
```shell
174-
./vendor/bin/phpunit
175-
```
176-
177-
### Mutation testing
167+
## Documentation
178168

179-
The package tests are checked with [Infection](https://infection.github.io/) mutation framework with
180-
[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:
169+
- [Internals](docs/internals.md)
181170

182-
```shell
183-
./vendor/bin/roave-infection-static-analysis-plugin
184-
```
185-
186-
### Static analysis
187-
188-
The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
189-
190-
```shell
191-
./vendor/bin/psalm
192-
```
171+
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
172+
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).
193173

194174
## License
195175

196-
The Yii Arrays is free software. It is released under the terms of the BSD License. Please see [`LICENSE`](./LICENSE.md) for more information.
176+
The Yii Arrays is free software. It is released under the terms of the BSD License.
177+
Please see [`LICENSE`](./LICENSE.md) for more information.
197178

198179
Maintained by [Yii Software](https://www.yiiframework.com/).
199180

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
"homepage": "https://www.yiiframework.com/",
1111
"license": "BSD-3-Clause",
1212
"support": {
13-
"issues": "https://github.com/yiisoft/arrays/issues",
13+
"issues": "https://github.com/yiisoft/arrays/issues?state=open",
14+
"source": "https://github.com/yiisoft/arrays",
1415
"forum": "https://forum.yiiframework.com/",
1516
"wiki": "https://www.yiiframework.com/wiki/",
16-
"irc": "irc://irc.freenode.net/yii",
17-
"chat": "https://t.me/yii3en",
18-
"source": "https://github.com/yiisoft/arrays"
17+
"irc": "ircs://irc.libera.chat:6697/yii",
18+
"chat": "https://t.me/yii3en"
1919
},
2020
"funding": [
2121
{
@@ -34,10 +34,10 @@
3434
"require-dev": {
3535
"maglnet/composer-require-checker": "^4.4",
3636
"phpunit/phpunit": "^9.5",
37-
"rector/rector": "^0.19.0",
37+
"rector/rector": "^1.0.0",
3838
"roave/infection-static-analysis-plugin": "^1.25",
3939
"spatie/phpunit-watcher": "^1.23",
40-
"vimeo/psalm": "^4.30|^5.20"
40+
"vimeo/psalm": "^4.30|^5.23"
4141
},
4242
"autoload": {
4343
"psr-4": {

docs/internals.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Internals
2+
3+
## Unit testing
4+
5+
The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
6+
7+
```shell
8+
./vendor/bin/phpunit
9+
```
10+
11+
## Mutation testing
12+
13+
The package tests are checked with [Infection](https://infection.github.io/) mutation framework with
14+
[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:
15+
16+
```shell
17+
./vendor/bin/roave-infection-static-analysis-plugin
18+
```
19+
20+
## Static analysis
21+
22+
The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
23+
24+
```shell
25+
./vendor/bin/psalm
26+
```
27+
28+
## Rector
29+
30+
Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or
31+
use either newest or any specific version of PHP:
32+
33+
```shell
34+
./vendor/bin/rector
35+
```
36+
37+
## Composer require checker
38+
39+
This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`.
40+
41+
To run the checker, execute the following command:
42+
43+
```shell
44+
./vendor/bin/composer-require-checker
45+
```

psalm.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
>
1010
<projectFiles>
1111
<directory name="src" />
12+
<file name="tests/PsalmTraitHelper.php" />
1213
<ignoreFiles>
13-
<directory name="vendor"/>
14+
<directory name="vendor" />
1415
</ignoreFiles>
1516
</projectFiles>
1617
<issueHandlers>

psalm80.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
>
1010
<projectFiles>
1111
<directory name="src" />
12+
<file name="tests/PsalmTraitHelper.php" />
1213
<ignoreFiles>
1314
<directory name="vendor"/>
1415
</ignoreFiles>

src/ArrayAccessTrait.php

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use ArrayIterator;
88

9+
use function count;
10+
911
/**
1012
* `ArrayAccessTrait` provides the implementation for {@see \IteratorAggregate}, {@see \ArrayAccess}
1113
* and {@see \Countable}.
@@ -14,6 +16,9 @@
1416
* The data will be exposed by `ArrayAccessTrait` to support accessing the class object like an array.
1517
*
1618
* @property array $data
19+
*
20+
* @psalm-template TKey as array-key
21+
* @psalm-template TValue as mixed
1722
*/
1823
trait ArrayAccessTrait
1924
{
@@ -44,6 +49,8 @@ public function count(): int
4449
* This method is required by the interface {@see \ArrayAccess}.
4550
*
4651
* @param mixed $offset The offset to check on.
52+
*
53+
* @psalm-param TKey $offset
4754
*/
4855
public function offsetExists(mixed $offset): bool
4956
{
@@ -56,6 +63,9 @@ public function offsetExists(mixed $offset): bool
5663
* @param mixed $offset The offset to retrieve element.
5764
*
5865
* @return mixed The element at the offset, null if no element is found at the offset.
66+
*
67+
* @psalm-param TKey $offset
68+
* @psalm-return TValue
5969
*/
6070
public function offsetGet(mixed $offset): mixed
6171
{
@@ -67,6 +77,9 @@ public function offsetGet(mixed $offset): mixed
6777
*
6878
* @param mixed $offset The offset to set element.
6979
* @param mixed $value The element value.
80+
*
81+
* @psalm-param TKey|null $offset
82+
* @psalm-param TValue $value
7083
*/
7184
public function offsetSet(mixed $offset, mixed $value): void
7285
{
@@ -81,6 +94,8 @@ public function offsetSet(mixed $offset, mixed $value): void
8194
* This method is required by the interface {@see \ArrayAccess}.
8295
*
8396
* @param mixed $offset The offset to unset element.
97+
*
98+
* @psalm-param TKey $offset
8499
*/
85100
public function offsetUnset(mixed $offset): void
86101
{

0 commit comments

Comments
 (0)