Skip to content

Commit

Permalink
Fix fromString phpdoc and improve type validation of arguments (#14)
Browse files Browse the repository at this point in the history
* Fix fromString phpdoc and improve type validation of arguments

* Update CHANGELOG

* Add CODEOWNERS

* Fix GHA workflow
  • Loading branch information
Slava authored Apr 19, 2021
1 parent 8c8467c commit 55a1e4a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Code Owners settings
# See: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners

# As soon as a PR is added or a project is published, these teams will be invited for review.
* @Rebilly/php
2 changes: 2 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.PHP_EXTENSIONS }}
tools: composer:v1

- name: Get Composer Cache Directory
id: composer-cache
Expand Down Expand Up @@ -77,6 +78,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.PHP_EXTENSIONS }}
tools: composer:v1

- name: Get Composer Cache Directory
id: composer-cache
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ Security - in case of vulnerabilities.

## [Unreleased]

## 1.1.2 (2021-04-19)

### Changed

+ Fix `Money::fromString` phpdoc and improve type validation of arguments.

## 1.1.0 (2020-02-21)

### Changed

+ Migrated CI from **Travis CI** to **GitHub Actions**.
+ Upgraded minimum PHP version to v7.3.
+ Migrated CI from **Travis CI** to **GitHub Actions**.
+ Upgraded minimum PHP version to v7.3.

### Added

Expand Down
6 changes: 3 additions & 3 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(int $amount, Currency $currency)
* number of fractional digits then the value will be rounded to the
* currency's number of fractional digits.
*
* @param string $value
* @param float|int|string $value
* @param Currency|string $currency
*
* @throws InvalidArgumentException
Expand All @@ -71,11 +71,11 @@ public function __construct(int $amount, Currency $currency)
*/
public static function fromString($value, $currency): self
{
if (!is_scalar($value) && !is_callable([$value, '__toString'])) {
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new InvalidArgumentException('$value must be a string');
}

if (!is_scalar($currency) && !is_callable([$currency, '__toString'])) {
if (!is_string($currency) && !(is_object($currency) && method_exists($currency, '__toString'))) {
throw new InvalidArgumentException('$currency must be a string');
}

Expand Down
1 change: 1 addition & 0 deletions tests/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testCannotBeConstructedUsingInvalidValueArgument(): void
public function testCannotBeConstructedUsingInvalidCurrencyArgument(): void
{
$this->expectException(InvalidArgumentException::class);
/** @noinspection PhpParamsInspection */
Money::fromString(0, new stdClass());
}

Expand Down

0 comments on commit 55a1e4a

Please sign in to comment.