Skip to content

Commit

Permalink
Add PHPDoc return types
Browse files Browse the repository at this point in the history
Symfony PHPUnit Bridge has a deprecation helper that warns when things might break in the future.

It currently reports the following errors when using Stripe PHP SDK:

```
Method "ArrayAccess::offsetExists()" might add "bool" as a native return type declaration in the future. Do the same in implementation "Stripe\StripeObject" now to avoid errors or add an explicit @return annotation to suppress this message.
Method "ArrayAccess::offsetGet()" might add "mixed" as a native return type declaration in the future. Do the same in implementation "Stripe\StripeObject" now to avoid errors or add an explicit @return annotation to suppress this message.
Method "ArrayAccess::offsetSet()" might add "void" as a native return type declaration in the future. Do the same in implementation "Stripe\StripeObject" now to avoid errors or add an explicit @return annotation to suppress this message.
Method "ArrayAccess::offsetUnset()" might add "void" as a native return type declaration in the future. Do the same in implementation "Stripe\StripeObject" now to avoid errors or add an explicit @return annotation to suppress this message.
Method "Countable::count()" might add "int" as a native return type declaration in the future. Do the same in implementation "Stripe\StripeObject" now to avoid errors or add an explicit @return annotation to suppress this message.
Method "JsonSerializable::jsonSerialize()" might add "mixed" as a native return type declaration in the future. Do the same in implementation "Stripe\StripeObject" now to avoid errors or add an explicit @return annotation to suppress this message.
```

By adding these PHPDoc types, the problem disappears. It's also more clear for users of the package.

Fixes #1210
  • Loading branch information
ruudk committed Jan 4, 2022
1 parent f70cb95 commit a18273d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/StripeObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ public function offsetGet($k)
return \array_key_exists($k, $this->_values) ? $this->_values[$k] : null;
}

// Countable method
/**
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
Expand Down Expand Up @@ -424,6 +426,9 @@ public function serializeParamsValue($value, $original, $unsaved, $force, $key =
}
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
Expand Down
12 changes: 12 additions & 0 deletions lib/Util/CaseInsensitiveArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function getIterator()
return new \ArrayIterator($this->container);
}

/**
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
Expand All @@ -44,6 +47,9 @@ public function offsetSet($offset, $value)
}
}

/**
* @return
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
Expand All @@ -52,13 +58,19 @@ public function offsetExists($offset)
return isset($this->container[$offset]);
}

/**
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$offset = static::maybeLowercase($offset);
unset($this->container[$offset]);
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
Expand Down

0 comments on commit a18273d

Please sign in to comment.