Skip to content

Commit b96c1dc

Browse files
authored
Merge pull request #68 from Art4/prepare-typehinting-in-interfaces
Prepare for typehints in interfaces
2 parents eafbd39 + 053b507 commit b96c1dc

13 files changed

+53
-15
lines changed

CHANGELOG.md

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

1212
- Added type hints for parameters and return types in internal and final classes
1313
- New tests for improving backward compatibility in interfaces
14+
- Support for PHP 8.1 is added in CI tests
1415

1516
### Changed
1617

1718
- Switched from Travis-CI to Github Actions
1819

20+
### Deprecated
21+
22+
- `\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.
23+
- `\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.
24+
- `\Art4\JsonApiClient\Exception\Exception` will extend `\Throwable` in v2.0, do the same in your implementation now to avoid errors.
25+
- `\Art4\JsonApiClient\Factory::make()` methods first parameter signature will be `string` in v2.0.
26+
- `\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.
27+
- `\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.
28+
- `\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.
29+
- `\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.
30+
- `\Art4\JsonApiClient\Manager::getParam()` methods first parameter signature will be `string` in v2.0.
31+
- `\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.
32+
1933
## [1.0.0 - 2021-03-05](https://github.com/Art4/json-api-client/compare/0.10.2...1.0.0)
2034

2135
### Added
2236

23-
- Support for PHP 8 added
37+
- Support for PHP 8.0 added
2438

2539
### Changed
2640

src/Accessable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,22 @@ public function get($key);
3636
/**
3737
* Check if a value exists
3838
*
39+
* @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.
40+
*
3941
* @param mixed $key The key
4042
*
4143
* @return bool
4244
*/
4345
public function has($key);
46+
// public function has($key): bool;
4447

4548
/**
4649
* Returns the keys of all setted values
4750
*
51+
* @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.
52+
*
4853
* @return array<string> Keys of all setted values
4954
*/
5055
public function getKeys();
56+
// public function getKeys(): array;
5157
}

src/Exception/AccessException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919

2020
namespace Art4\JsonApiClient\Exception;
2121

22-
class AccessException extends \RuntimeException implements Exception
22+
class AccessException extends \RuntimeException implements Exception, \Throwable
2323
{
2424
}

src/Exception/Exception.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
namespace Art4\JsonApiClient\Exception;
2121

22+
/**
23+
* @deprecated `\Art4\JsonApiClient\Exception\Exception` will extend `\Throwable` in v2.0. Do the same in your implementation now to avoid errors.
24+
*/
25+
// interface Exception extends \Throwable
2226
interface Exception
2327
{
2428
}

src/Exception/FactoryException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919

2020
namespace Art4\JsonApiClient\Exception;
2121

22-
class FactoryException extends \Exception implements Exception
22+
class FactoryException extends \Exception implements Exception, \Throwable
2323
{
2424
}

src/Exception/InputException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919

2020
namespace Art4\JsonApiClient\Exception;
2121

22-
class InputException extends \Exception implements Exception
22+
class InputException extends \Exception implements Exception, \Throwable
2323
{
2424
}

src/Exception/ValidationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919

2020
namespace Art4\JsonApiClient\Exception;
2121

22-
class ValidationException extends \InvalidArgumentException implements Exception
22+
class ValidationException extends \InvalidArgumentException implements Exception, \Throwable
2323
{
2424
}

src/Factory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
namespace Art4\JsonApiClient;
2121

22-
use Art4\JsonApiClient\Accessable;
23-
2422
/**
2523
* Factory Interface
2624
*/
@@ -29,10 +27,14 @@ interface Factory
2927
/**
3028
* Create a new instance of a class
3129
*
30+
* @deprecated The `\Art4\JsonApiClient\Factory::make()` methods first parameter signature will be `string` in v2.0.
31+
* @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.
32+
*
3233
* @param string $name
3334
* @param array<mixed|Manager|Accessable> $args
3435
*
3536
* @return \Art4\JsonApiClient\Accessable
3637
*/
3738
public function make($name, array $args = []);
39+
// public function make(string $name, array $args = []): Accessable;
3840
}

src/Helper/AccessableTrait.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ trait AccessableTrait
3232
/**
3333
* @var array<mixed>
3434
*/
35-
private $data = [];
35+
private array $data = [];
3636

3737
/**
3838
* Set a value
@@ -54,7 +54,7 @@ final protected function set(string $key, $value): void
5454
*
5555
* @return array<string> Keys of all setted values
5656
*/
57-
final public function getKeys()
57+
final public function getKeys(): array
5858
{
5959
return array_keys($this->data);
6060
}
@@ -63,10 +63,8 @@ final public function getKeys()
6363
* Check if a value exists
6464
*
6565
* @param mixed $key The key
66-
*
67-
* @return bool
6866
*/
69-
final public function has($key)
67+
final public function has($key): bool
7068
{
7169
$key = $this->parseKey($key);
7270

src/Input/Input.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ interface Input
2727
/**
2828
* Get the input as simple object
2929
*
30-
* This should be a native PH stdClass object, so Manager could
30+
* @deprecated `\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.
31+
*
32+
* This should be a native PHP stdClass object, so Manager could
3133
* iterate over all public attributes
3234
*
3335
* @throws \Art4\JsonApiClient\Exception\InputException if something went wrong with the input
3436
*
3537
* @return \stdClass
3638
*/
3739
public function getAsObject();
40+
// public function getAsObject(): \stdClass;
3841
}

0 commit comments

Comments
 (0)