Skip to content

Commit 6884e80

Browse files
Deprecate non-variadic use of some functions
The new version of PHPCS no longer likes how we indicate the possible variadic use of these functions. PHP 5.6 has been released for quite a while; let’s start phasing out the non-variadic way to use these functions. (Eventually, we can then declare the parameters with a strict type hint, removing our own type checks e. g. in StatementList.) Bug: T253636
1 parent 35985b5 commit 6884e80

4 files changed

Lines changed: 30 additions & 15 deletions

File tree

RELEASE-NOTES.md

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

3+
## Version 9.6.0 (development)
4+
5+
* `ReferenceList::addNewReference()`, `Statement::addNewReference()` and the `StatementList` constructor
6+
supported being called with a variadic argument list, with a single array argument,
7+
or (in the case of `StatementList`) with a single `Traversable` argument.
8+
The latter two forms are now deprecated (though they still work);
9+
please update your code:
10+
for instance, change `->addNewReference( [ $x, $y ] )` to `->addNewReference( $x, $y )`,
11+
and `->addNewReference( $snaks )` to `->addNewReference( ...$snaks )`.
12+
313
## Version 9.5.1 (2020-06-03)
414

515
* Updated release notes

src/ReferenceList.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ public function addReference( Reference $reference, $index = null ) {
9090
/**
9191
* @since 1.1
9292
*
93-
* @param Snak[]|Snak $snaks
94-
* @param Snak [$snak2,...]
93+
* @param Snak ...$snaks
94+
* (passing a single Snak[] is still supported but deprecated)
9595
*
9696
* @throws InvalidArgumentException
9797
*/
98-
public function addNewReference( $snaks = [] /*...*/ ) {
99-
if ( $snaks instanceof Snak ) {
100-
$snaks = func_get_args();
98+
public function addNewReference( ...$snaks ) {
99+
if ( count( $snaks ) === 1 && is_array( $snaks[0] ) ) {
100+
// TODO stop supporting this
101+
$snaks = $snaks[0];
101102
}
102103

103104
$this->addReference( new Reference( $snaks ) );

src/Statement/Statement.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,15 @@ public function setReferences( ReferenceList $references ) {
175175
/**
176176
* @since 2.0
177177
*
178-
* @param Snak[]|Snak $snaks
179-
* @param Snak [$snak2,...]
178+
* @param Snak ...$snaks
179+
* (passing a single Snak[] is still supported but deprecated)
180180
*
181181
* @throws InvalidArgumentException
182182
*/
183-
public function addNewReference( $snaks = [] /*...*/ ) {
184-
if ( $snaks instanceof Snak ) {
185-
$snaks = func_get_args();
183+
public function addNewReference( ...$snaks ) {
184+
if ( count( $snaks ) === 1 && is_array( $snaks[0] ) ) {
185+
// TODO stop supporting this
186+
$snaks = $snaks[0];
186187
}
187188

188189
$this->references->addNewReference( $snaks );

src/Statement/StatementList.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ class StatementList implements IteratorAggregate, Comparable, Countable {
3636
private $statements = [];
3737

3838
/**
39-
* @param Statement[]|Traversable|Statement $statements
40-
* @param Statement [$statement2,...]
39+
* @param Statement ...$statements
40+
* (passing a single Statement[] or Traversable is still supported but deprecated)
4141
*
4242
* @throws InvalidArgumentException
4343
*/
44-
public function __construct( $statements = [] /*...*/ ) {
45-
if ( $statements instanceof Statement ) {
46-
$statements = func_get_args();
44+
public function __construct( ...$statements ) {
45+
if ( count( $statements ) === 1 && (
46+
is_array( $statements[0] ) || $statements[0] instanceof Traversable
47+
) ) {
48+
// TODO stop supporting this
49+
$statements = $statements[0];
4750
}
4851

4952
if ( !is_array( $statements ) && !( $statements instanceof Traversable ) ) {

0 commit comments

Comments
 (0)