Skip to content

Commit 55a1e4a

Browse files
author
Slava
authored
Fix fromString phpdoc and improve type validation of arguments (#14)
* Fix fromString phpdoc and improve type validation of arguments * Update CHANGELOG * Add CODEOWNERS * Fix GHA workflow
1 parent 8c8467c commit 55a1e4a

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

.github/CODEOWNERS

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Code Owners settings
2+
# See: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
3+
4+
# As soon as a PR is added or a project is published, these teams will be invited for review.
5+
* @Rebilly/php

.github/workflows/workflow.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
with:
2626
php-version: ${{ matrix.php-version }}
2727
extensions: ${{ env.PHP_EXTENSIONS }}
28+
tools: composer:v1
2829

2930
- name: Get Composer Cache Directory
3031
id: composer-cache
@@ -77,6 +78,7 @@ jobs:
7778
with:
7879
php-version: ${{ matrix.php-version }}
7980
extensions: ${{ env.PHP_EXTENSIONS }}
81+
tools: composer:v1
8082

8183
- name: Get Composer Cache Directory
8284
id: composer-cache

CHANGELOG.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ Security - in case of vulnerabilities.
1616

1717
## [Unreleased]
1818

19+
## 1.1.2 (2021-04-19)
20+
21+
### Changed
22+
23+
+ Fix `Money::fromString` phpdoc and improve type validation of arguments.
24+
1925
## 1.1.0 (2020-02-21)
2026

2127
### Changed
2228

23-
+ Migrated CI from **Travis CI** to **GitHub Actions**.
24-
+ Upgraded minimum PHP version to v7.3.
29+
+ Migrated CI from **Travis CI** to **GitHub Actions**.
30+
+ Upgraded minimum PHP version to v7.3.
2531

2632
### Added
2733

src/Money.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct(int $amount, Currency $currency)
6262
* number of fractional digits then the value will be rounded to the
6363
* currency's number of fractional digits.
6464
*
65-
* @param string $value
65+
* @param float|int|string $value
6666
* @param Currency|string $currency
6767
*
6868
* @throws InvalidArgumentException
@@ -71,11 +71,11 @@ public function __construct(int $amount, Currency $currency)
7171
*/
7272
public static function fromString($value, $currency): self
7373
{
74-
if (!is_scalar($value) && !is_callable([$value, '__toString'])) {
74+
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
7575
throw new InvalidArgumentException('$value must be a string');
7676
}
7777

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

tests/MoneyTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function testCannotBeConstructedUsingInvalidValueArgument(): void
2727
public function testCannotBeConstructedUsingInvalidCurrencyArgument(): void
2828
{
2929
$this->expectException(InvalidArgumentException::class);
30+
/** @noinspection PhpParamsInspection */
3031
Money::fromString(0, new stdClass());
3132
}
3233

0 commit comments

Comments
 (0)