Skip to content

Commit 58d21e2

Browse files
authored
Merge pull request #87 from Art4/86-add-return-types-in-final-classes
Add return types in final classes
2 parents 1d7e8ed + f015aa7 commit 58d21e2

33 files changed

+193
-124
lines changed

.phpstan.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,15 @@ parameters:
7676
count: 1
7777
path: tests/Unit/V1/ResourceNullTest.php
7878
# We are providing an invalid parameter to test the deprecation message
79+
80+
-
81+
message: "#^Parameter \\#1 \\$key of method Art4\\\\JsonApiClient\\\\Tests\\\\Fixtures\\\\AccessableTraitMock\\:\\:get\\(\\) expects Art4\\\\JsonApiClient\\\\Helper\\\\AccessKey\\|int\\|string, mixed given\\.$#"
82+
count: 1
83+
path: tests/Unit/Helper/AccessableTraitTest.php
84+
# We are providing an invalid parameter to test the deprecation message
85+
86+
-
87+
message: "#^Parameter \\#1 \\$key of method Art4\\\\JsonApiClient\\\\Tests\\\\Fixtures\\\\AccessableTraitMock\\:\\:has\\(\\) expects Art4\\\\JsonApiClient\\\\Helper\\\\AccessKey\\|int\\|string, mixed given\\.$#"
88+
count: 1
89+
path: tests/Unit/Helper/AccessableTraitTest.php
90+
# We are providing an invalid parameter to test the deprecation message

CHANGELOG.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- Add support for PHP 8.2
1313

14+
### Deprecated
15+
16+
- Providing Argument #1 ($key) in `\Art4\JsonApiClient\Accessable::has()` not as `int|string` is deprecated and will throw an Exception in 2.0.0.
17+
- Providing Argument #1 ($key) in `\Art4\JsonApiClient\Accessable::get()` not as `int|string` is deprecated and will throw an Exception in 2.0.0.
18+
1419
## [1.1.0 - 2021-10-05](https://github.com/Art4/json-api-client/compare/1.0.0...1.1.0)
1520

1621
### Added
@@ -25,16 +30,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2530

2631
### Deprecated
2732

28-
- `\Art4\JsonApiClient\Accessable::has()` will add `bool` as a native return type declaration in v2.0, do the same in your implementation now to avoid errors.
29-
- `\Art4\JsonApiClient\Accessable::getKeys()` will add `array` as a native return type declaration in v2.0, do the same in your implementation now to avoid errors.
30-
- `\Art4\JsonApiClient\Exception\Exception` will extend `\Throwable` in v2.0, do the same in your implementation now to avoid errors.
31-
- `\Art4\JsonApiClient\Factory::make()` methods first parameter signature will be `string` in v2.0.
32-
- `\Art4\JsonApiClient\Factory::make()` will add `\Art4\JsonApiClient\Accessable` as a native return type declaration in v2.0, do the same in your implementation now to avoid errors.
33-
- `\Art4\JsonApiClient\Input\Input::getAsObject()` will add `\stdClass` as a native return type declaration in v2.0, do the same in your implementation now to avoid errors.
34-
- `\Art4\JsonApiClient\Manager::parse()` will add `\Art4\JsonApiClient\Accessable` as a native return type declaration in v2.0, do the same in your implementation now to avoid errors.
35-
- `\Art4\JsonApiClient\Manager::getFactory()` will add `\Art4\JsonApiClient\Factory` as a native return type declaration in v2.0, do the same in your implementation now to avoid errors.
36-
- `\Art4\JsonApiClient\Manager::getParam()` methods first parameter signature will be `string` in v2.0.
37-
- `\Art4\JsonApiClient\Serializer\Serializer::serialize()` will add `?array` as a native return type declaration in v2.0, do the same in your implementation now to avoid errors.
33+
- `\Art4\JsonApiClient\Accessable::has()` will add `bool` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
34+
- `\Art4\JsonApiClient\Accessable::getKeys()` will add `array` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
35+
- `\Art4\JsonApiClient\Exception\Exception` will extend `\Throwable` in 2.0.0, do the same in your implementation now to avoid errors.
36+
- `\Art4\JsonApiClient\Factory::make()` methods first parameter signature will be `string` in 2.0.0.
37+
- `\Art4\JsonApiClient\Factory::make()` will add `\Art4\JsonApiClient\Accessable` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
38+
- `\Art4\JsonApiClient\Input\Input::getAsObject()` will add `\stdClass` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
39+
- `\Art4\JsonApiClient\Manager::parse()` will add `\Art4\JsonApiClient\Accessable` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
40+
- `\Art4\JsonApiClient\Manager::getFactory()` will add `\Art4\JsonApiClient\Factory` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
41+
- `\Art4\JsonApiClient\Manager::getParam()` methods first parameter signature will be `string` in 2.0.0.
42+
- `\Art4\JsonApiClient\Serializer\Serializer::serialize()` will add `?array` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
3843

3944
## [1.0.0 - 2021-03-05](https://github.com/Art4/json-api-client/compare/0.10.2...1.0.0)
4045

src/Accessable.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,20 @@ public function get($key);
2727
/**
2828
* Check if a value exists
2929
*
30-
* @deprecated `\Art4\JsonApiClient\Accessable::has()` will add `bool` as a native return type declaration in v2.0. Do the same in your implementation now to avoid errors.
30+
* @return-type-will-change bool `\Art4\JsonApiClient\Accessable::has()` will add `bool` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
3131
*
3232
* @param mixed $key The key
3333
*
3434
* @return bool
3535
*/
36-
public function has($key);
37-
// public function has($key): bool;
36+
public function has($key)/*: bool */;
3837

3938
/**
4039
* Returns the keys of all setted values
4140
*
42-
* @deprecated `\Art4\JsonApiClient\Accessable::getKeys()` will add `array` as a native return type declaration in v2.0. Do the same in your implementation now to avoid errors.
41+
* @return-type-will-change array `\Art4\JsonApiClient\Accessable::getKeys()` will add `array` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
4342
*
4443
* @return array<string|int> Keys of all setted values
4544
*/
46-
public function getKeys();
47-
// public function getKeys(): array;
45+
public function getKeys()/*: array */;
4846
}

src/Exception/AccessException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
namespace Art4\JsonApiClient\Exception;
1010

11-
class AccessException extends \RuntimeException implements Exception, \Throwable {}
11+
class AccessException extends \RuntimeException implements Exception {}

src/Exception/Exception.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Art4\JsonApiClient\Exception;
1010

1111
/**
12-
* @deprecated `\Art4\JsonApiClient\Exception\Exception` will extend `\Throwable` in v2.0. Do the same in your implementation now to avoid errors.
12+
* Please note: `\Art4\JsonApiClient\Exception\Exception` will extend `\Throwable` in 2.0.0, do the same in your implementation now to avoid errors.
1313
*/
14-
// interface Exception extends \Throwable
15-
interface Exception {}
14+
interface Exception /*extends \Throwable */
15+
{}

src/Exception/FactoryException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
namespace Art4\JsonApiClient\Exception;
1010

11-
class FactoryException extends \Exception implements Exception, \Throwable {}
11+
class FactoryException extends \Exception implements Exception {}

src/Exception/InputException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
namespace Art4\JsonApiClient\Exception;
1010

11-
class InputException extends \Exception implements Exception, \Throwable {}
11+
class InputException extends \Exception implements Exception {}

src/Exception/ValidationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
namespace Art4\JsonApiClient\Exception;
1010

11-
class ValidationException extends \InvalidArgumentException implements Exception, \Throwable {}
11+
class ValidationException extends \InvalidArgumentException implements Exception {}

src/Factory.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ interface Factory
1616
/**
1717
* Create a new instance of a class
1818
*
19-
* @deprecated The `\Art4\JsonApiClient\Factory::make()` methods first parameter signature will be `string` in v2.0.
20-
* @deprecated `\Art4\JsonApiClient\Factory::make()` will add `\Art4\JsonApiClient\Accessable` as a native return type declaration in v2.0. Do the same in your implementation now to avoid errors.
19+
* @return-type-will-change Accessable `\Art4\JsonApiClient\Factory::make()` will add `\Art4\JsonApiClient\Accessable` as a native return type declaration in 2.0.0, do the same in your implementation now to avoid errors.
2120
*
22-
* @param string $name
23-
* @param array<mixed|Manager|Accessable> $args
21+
* @param array<mixed|Manager|Accessable> $args
2422
*
2523
* @return \Art4\JsonApiClient\Accessable
2624
*/
27-
public function make($name, array $args = []);
28-
// public function make(string $name, array $args = []): Accessable;
25+
public function make(string $name, array $args = [])/*: Accessable */;
2926
}

src/Helper/AccessKey.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,20 @@ final class AccessKey extends SplStack
2222
/**
2323
* Transforms the Key to a string
2424
*
25-
* @param int|string $key
26-
*
2725
* @return AccessKey<string>
2826
*/
29-
public static function create($key): AccessKey
27+
public static function create(string $key): AccessKey
3028
{
31-
// Ignore arrays and objects
32-
if (is_object($key) or is_array($key)) {
33-
$key = '';
34-
}
35-
36-
$key_string = strval($key);
37-
38-
$key = new self();
39-
$key->raw = $key_string;
40-
41-
$keys = explode('.', $key_string);
29+
$accessKey = new self();
30+
$accessKey->raw = $key;
4231

43-
foreach ($keys as $value) {
44-
$key->push($value);
32+
foreach (explode('.', $key) as $value) {
33+
$accessKey->push($value);
4534
}
4635

47-
$key->rewind();
36+
$accessKey->rewind();
4837

49-
return $key;
38+
return $accessKey;
5039
}
5140

5241
/**

0 commit comments

Comments
 (0)