Skip to content

Commit f544149

Browse files
committed
Small code cleaning
1 parent 0aec38d commit f544149

File tree

18 files changed

+65
-107
lines changed

18 files changed

+65
-107
lines changed

.docs/en/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
The purpose of this extension is to provide layer for parsing and handling [{JSON:API}](https://jsonapi.org/) requests
44
and responses
55

6+
***
7+
68
## Installation
79

810
The best way to install **fastybird/json-api** is using [Composer](http://getcomposer.org/):

src/Builder/Builder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
use function is_array;
3333
use function round;
3434
use function str_replace;
35+
use function str_starts_with;
3536
use function strval;
36-
use function substr;
3737
use const JSON_PRETTY_PRINT;
3838

3939
/**
@@ -63,9 +63,9 @@ class Builder
6363
* @param string|Array<string> $metaAuthor
6464
*/
6565
public function __construct(
66-
private DI\Container $container,
67-
private string|array $metaAuthor,
68-
private string|null $metaCopyright = null,
66+
private readonly DI\Container $container,
67+
private readonly string|array $metaAuthor,
68+
private readonly string|null $metaCopyright = null,
6969
)
7070
{
7171
}
@@ -218,7 +218,7 @@ private function uriToString(UriInterface $uri): string
218218
$result = '';
219219

220220
// Add a leading slash if necessary.
221-
if (substr($uri->getPath(), 0, 1) !== '/') {
221+
if (!str_starts_with($uri->getPath(), '/')) {
222222
$result .= '/';
223223
}
224224

src/Exceptions/JsonApiError.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class JsonApiError extends PHPException implements Exception, JsonApi
3535
public function __construct(
3636
int $code,
3737
string $title,
38-
private string|null $detail = null,
39-
private array|null $source = null,
40-
private string|null $type = null,
38+
private readonly string|null $detail = null,
39+
private readonly array|null $source = null,
40+
private readonly string|null $type = null,
4141
)
4242
{
4343
parent::__construct($title, $code);

src/Hydrators/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Container
3838
private JsonApi\SchemaContainer|null $jsonApiSchemaContainer = null;
3939

4040
public function __construct(
41-
private DI\Container $container,
41+
private readonly DI\Container $container,
4242
Log\LoggerInterface|null $logger = null,
4343
)
4444
{

src/Hydrators/Fields/ArrayField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class ArrayField extends Field
2929
{
3030

3131
public function __construct(
32-
private bool $isNullable,
32+
private readonly bool $isNullable,
3333
string $mappedName,
3434
string $fieldName,
3535
bool $isRequired,

src/Hydrators/Fields/BooleanField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class BooleanField extends Field
2929
{
3030

3131
public function __construct(
32-
private bool $isNullable,
32+
private readonly bool $isNullable,
3333
string $mappedName,
3434
string $fieldName,
3535
bool $isRequired,

src/Hydrators/Fields/DateTimeField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class DateTimeField extends Field
3232
{
3333

3434
public function __construct(
35-
private bool $isNullable,
35+
private readonly bool $isNullable,
3636
string $mappedName,
3737
string $fieldName,
3838
bool $isRequired,
@@ -43,7 +43,7 @@ public function __construct(
4343
}
4444

4545
/**
46-
* @param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
46+
* @phpstan-param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
4747
*/
4848
public function getValue(JsonAPIDocument\Objects\IStandardObject $attributes): DateTimeInterface|null
4949
{

src/Hydrators/Fields/EntityField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ abstract class EntityField extends Field
3434
*/
3535
public function __construct(
3636
string $className,
37-
private bool $nullable,
37+
private readonly bool $nullable,
3838
string $mappedName,
39-
private bool $isRelationship,
39+
private readonly bool $isRelationship,
4040
string $fieldName,
4141
bool $isRequired,
4242
bool $isWritable,

src/Hydrators/Fields/EnumField.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ final class EnumField extends Field
3232
{
3333

3434
public function __construct(
35-
private string $typeClass,
36-
private bool $isNullable,
35+
private readonly string $typeClass,
36+
private readonly bool $isNullable,
3737
string $mappedName,
3838
string $fieldName,
3939
bool $isRequired,
@@ -44,7 +44,7 @@ public function __construct(
4444
}
4545

4646
/**
47-
* @param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
47+
* @phpstan-param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
4848
*/
4949
public function getValue(JsonAPIDocument\Objects\IStandardObject $attributes): Consistence\Enum\Enum|null
5050
{

src/Hydrators/Fields/Field.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace FastyBird\JsonApi\Hydrators\Fields;
1717

18+
use IPub\JsonAPIDocument;
1819
use Nette;
1920

2021
/**
@@ -25,20 +26,25 @@
2526
*
2627
* @author Adam Kadlec <[email protected]>
2728
*/
28-
abstract class Field implements IField
29+
abstract class Field
2930
{
3031

3132
use Nette\SmartObject;
3233

3334
public function __construct(
34-
private string $mappedName,
35-
private string $fieldName,
36-
private bool $isRequired,
37-
private bool $isWritable,
35+
private readonly string $mappedName,
36+
private readonly string $fieldName,
37+
private readonly bool $isRequired,
38+
private readonly bool $isWritable,
3839
)
3940
{
4041
}
4142

43+
/**
44+
* @param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
45+
*/
46+
abstract public function getValue(JsonAPIDocument\Objects\IStandardObject $attributes): mixed;
47+
4248
public function getMappedName(): string
4349
{
4450
return $this->mappedName;

src/Hydrators/Fields/IField.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Hydrators/Fields/MixedField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class MixedField extends Field
2929
{
3030

3131
public function __construct(
32-
private bool $isNullable,
32+
private readonly bool $isNullable,
3333
string $mappedName,
3434
string $fieldName,
3535
bool $isRequired,
@@ -40,7 +40,7 @@ public function __construct(
4040
}
4141

4242
/**
43-
* @param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
43+
* @phpstan-param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
4444
*/
4545
public function getValue(JsonAPIDocument\Objects\IStandardObject $attributes): mixed
4646
{

src/Hydrators/Fields/NumberField.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ final class NumberField extends Field
3030
{
3131

3232
public function __construct(
33-
private bool $isDecimal,
34-
private bool $isNullable,
33+
private readonly bool $isDecimal,
34+
private readonly bool $isNullable,
3535
string $mappedName,
3636
string $fieldName,
3737
bool $isRequired,
@@ -42,7 +42,7 @@ public function __construct(
4242
}
4343

4444
/**
45-
* @param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
45+
* @phpstan-param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
4646
*/
4747
public function getValue(JsonAPIDocument\Objects\IStandardObject $attributes): float|int|null
4848
{

src/Hydrators/Fields/TextField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class TextField extends Field
3030
{
3131

3232
public function __construct(
33-
private bool $isNullable,
33+
private readonly bool $isNullable,
3434
string $mappedName,
3535
string $fieldName,
3636
bool $isRequired,
@@ -41,7 +41,7 @@ public function __construct(
4141
}
4242

4343
/**
44-
* @param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
44+
* @phpstan-param JsonAPIDocument\Objects\IStandardObject<string, mixed> $attributes
4545
*/
4646
public function getValue(JsonAPIDocument\Objects\IStandardObject $attributes): string|null
4747
{

0 commit comments

Comments
 (0)