Skip to content

Commit

Permalink
Add types for parameter and return in final classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Oct 26, 2023
1 parent ac25355 commit 7790b3b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 20 deletions.
6 changes: 2 additions & 4 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ interface Factory
/**
* Create a new instance of a class
*
* @deprecated The `\Art4\JsonApiClient\Factory::make()` methods first parameter signature will be `string` in v2.0.
* @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.
*
* @param string $name
* @param array<mixed|Manager|Accessable> $args
* @param array<mixed|Manager|Accessable> $args
*
* @return \Art4\JsonApiClient\Accessable
*/
public function make($name, array $args = []);
public function make(string $name, array $args = []);
// public function make(string $name, array $args = []): Accessable;
}
2 changes: 0 additions & 2 deletions src/Helper/RootAccessable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
namespace Art4\JsonApiClient\Helper;

use Art4\JsonApiClient\Accessable;
use Art4\JsonApiClient\Element;
use Art4\JsonApiClient\Manager;

/**
* RootAccessable
Expand Down
7 changes: 2 additions & 5 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ public function getFactory();
/**
* Get a param by key
*
* @deprecated The `\Art4\JsonApiClient\Manager::getParam()` methods first parameter signature will be `string` in v2.0.
*
* @param string $key
* @param mixed $default
* @param mixed $default
*
* @return mixed
*/
public function getParam($key, $default);
public function getParam(string $key, $default);
// public function getParam(string $key, $default);
}
5 changes: 2 additions & 3 deletions src/Manager/ErrorAbortManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ public function getFactory(): Factory
/**
* Get a param by key
*
* @param string $key
* @param mixed $default
* @param mixed $default
*
* @return mixed
*/
public function getParam($key, $default)
public function getParam(string $key, $default)
{
if (array_key_exists($key, $this->config)) {
return $this->config[$key];
Expand Down
5 changes: 2 additions & 3 deletions src/V1/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ public function __construct(array $overload = [])
/**
* Create a new instance of a class
*
* @param string $name
* @param array<mixed> $args
* @param array<mixed> $args
*/
public function make($name, array $args = []): Accessable
public function make(string $name, array $args = []): Accessable
{
if (! isset($this->classes[$name])) {
throw new FactoryException('"' . $name . '" is not a registered class');
Expand Down
1 change: 0 additions & 1 deletion src/V1/ResourceItemLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function get($key)
/**
* Set a link
*
* @param string $name The Name
* @param string|object|mixed $link The Link
*/
private function setLink(string $name, $link): void
Expand Down
4 changes: 2 additions & 2 deletions src/V1/ResourceNull.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct($data, Manager $manager, Accessable $parent) {}
*
* @return bool false
*/
public function has($key)
public function has($key): bool
{
if (! is_int($key) && ! is_string($key) && (! is_object($key) || ! $key instanceof AccessKey)) {
trigger_error(sprintf(
Expand All @@ -54,7 +54,7 @@ public function has($key)
*
* @return array<string> Keys of all setted values
*/
public function getKeys()
public function getKeys(): array
{
return [];
}
Expand Down

0 comments on commit 7790b3b

Please sign in to comment.