Skip to content

Commit 0037af2

Browse files
author
Thorsten Suckow-Homberg
committed
style: update sources according to phpstan and PSR-12
1 parent 4e99379 commit 0037af2

File tree

19 files changed

+115
-245
lines changed

19 files changed

+115
-245
lines changed

src/JsonApi/Extensions/Query/Validation/Parameter/RelfieldRule.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
namespace Conjoon\JsonApi\Extensions\Query\Validation\Parameter;
3030

31+
use Conjoon\Data\Resource\ObjectDescriptionList;
3132
use Conjoon\Data\Validation\ValidationError;
3233
use Conjoon\Data\Validation\ValidationErrors;
33-
use Conjoon\Http\Query\Parameter;
3434
use Conjoon\JsonApi\Query\Validation\Parameter\FieldsetRule;
35-
use Conjoon\Data\Resource\ObjectDescriptionList;
35+
use Conjoon\Net\Uri\Component\Query\Parameter;
3636

3737
/**
3838
* An extension on sparse fieldset as specified with https://conjoon.org/json-api/ext/relfield.
@@ -54,7 +54,7 @@ class RelfieldRule extends FieldsetRule
5454
* this server supports wildcards.
5555
*
5656
* @param ObjectDescriptionList $resourceDescriptionList
57-
* @param array $includes
57+
* @param array<int, string> $includes
5858
* @param bool $wildcardEnabled
5959
*/
6060
public function __construct(
@@ -84,14 +84,14 @@ public function supports(object $obj): bool
8484
protected function validateValue(Parameter $parameter, ValidationErrors $errors): bool
8585
{
8686
$value = $parameter->getValue();
87-
$name = $parameter->getName();
88-
$type = $this->getGroupKey($parameter);
89-
$resourceFields = $this->getFields($type);
90-
91-
if ($value === "" || $value === null) {
87+
if ($value === "") {
9288
return true;
9389
}
9490

91+
$name = $parameter->getName();
92+
$type = $this->getGroupKey($parameter);
93+
$resourceFields = ($type ? $this->getFields($type) : []) ?? [];
94+
9595
$fields = explode(",", $value);
9696

9797
$wildcards = array_filter($fields, fn ($field) => $field === "*");

src/JsonApi/Query/Query.php

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

3030
namespace Conjoon\JsonApi\Query;
3131

32-
use Conjoon\Http\Query\Query as HttpQuery;
3332
use Conjoon\Data\Resource\ObjectDescription;
33+
use Conjoon\Net\Uri\Component\Query as HttpQuery;
3434

3535
/**
3636
* Query validated for JSON:API specifications, providing access to a $resourceTarget

src/JsonApi/Query/Validation/CollectionValidator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929

3030
namespace Conjoon\JsonApi\Query\Validation;
3131

32-
use Conjoon\Http\Query\Validation\Parameter\ParameterRuleList;
33-
use Conjoon\Http\Query\Validation\Parameter\ValuesInWhitelistRule;
34-
use Conjoon\Http\Query\Query as HttpQuery;
35-
use Conjoon\JsonApi\Query\Query;
3632
use Conjoon\Data\Resource\ObjectDescription;
33+
use Conjoon\JsonApi\Query\Query;
34+
use Conjoon\Net\Uri\Component\Query as HttpQuery;
35+
use Conjoon\Web\Validation\Parameter\ParameterRuleList;
36+
use Conjoon\Web\Validation\Parameter\Rule\ValuesInWhitelistRule;
3737

3838
/**
3939
* Class for validating queries that target resource collections(!) according to JSON:API
@@ -70,9 +70,9 @@ public function getParameterRules(HttpQuery $query): ParameterRuleList
7070
/**
7171
* Returns all the parameter names for a collection query, including sorting parameter options.
7272
*
73-
* @param HttpQuery $query
73+
* @param Query $query
7474
*
75-
* @return array
75+
* @return array<int, string>
7676
*/
7777
public function getAllowedParameterNames(HttpQuery $query): array
7878
{
@@ -89,7 +89,7 @@ public function getAllowedParameterNames(HttpQuery $query): array
8989
* first part of the name is the type of the resource target.
9090
*
9191
* @param ObjectDescription $resourceTarget
92-
* @return array
92+
* @return array<int, string>
9393
*/
9494
protected function getAvailableSortFields(ObjectDescription $resourceTarget): array
9595
{
@@ -105,7 +105,7 @@ protected function getAvailableSortFields(ObjectDescription $resourceTarget): ar
105105
* first part of the name is the type of the resource target, or the related resource target.
106106
*
107107
* @param ObjectDescription $resourceTarget
108-
* @return array
108+
* @return array<int, string>
109109
*/
110110
protected function getAvailableFields(ObjectDescription $resourceTarget): array
111111
{

src/JsonApi/Query/Validation/Parameter/FieldsetRule.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929
namespace Conjoon\JsonApi\Query\Validation\Parameter;
3030

31+
use Conjoon\Data\Resource\ObjectDescriptionList;
3132
use Conjoon\Data\Validation\ValidationError;
3233
use Conjoon\Data\Validation\ValidationErrors;
33-
use Conjoon\Http\Query\Parameter;
34-
use Conjoon\Http\Query\ParameterTrait;
35-
use Conjoon\Http\Query\Validation\Parameter\ParameterRule;
36-
use Conjoon\Data\Resource\ObjectDescriptionList;
34+
use Conjoon\Net\Uri\Component\Query\Parameter;
35+
use Conjoon\Net\Uri\Component\Query\ParameterTrait;
36+
use Conjoon\Web\Validation\Parameter\ParameterRule;
3737

3838
/**
3939
* Validates fieldset parameters of the type "fields[TYPE]=field,field2,field3" given the
@@ -62,7 +62,7 @@ class FieldsetRule extends ParameterRule
6262
protected ObjectDescriptionList $resourceDescriptionList;
6363

6464
/**
65-
* @var array $includes
65+
* @var array<int, string> $includes
6666
*/
6767
protected array $includes;
6868

@@ -72,8 +72,8 @@ class FieldsetRule extends ParameterRule
7272
* and the includes the rule should consider.
7373
*
7474
* @param ObjectDescriptionList $resourceDescriptionList
75-
* @param array $includes An array with all resource object types requested, against which a parameter's
76-
* fieldset must be validated
75+
* @param array<int, string> $includes An array with all resource object types requested,
76+
* against which a parameter's fieldset must be validated
7777
*/
7878
public function __construct(ObjectDescriptionList $resourceDescriptionList, array $includes)
7979
{
@@ -96,7 +96,7 @@ public function getResourceObjectDescriptions(): ObjectDescriptionList
9696
/**
9797
* Returns the list of includes this rule was configures with
9898
*
99-
* @return array
99+
* @return array<int, string>
100100
*/
101101
public function getIncludes(): array
102102
{
@@ -109,6 +109,9 @@ public function getIncludes(): array
109109
*/
110110
public function supports(object $obj): bool
111111
{
112+
/**
113+
* @var Parameter $obj
114+
*/
112115
return parent::supports($obj) &&
113116
$this->isGroupParameter($obj) &&
114117
$this->getGroupName($obj) === "fields";
@@ -127,7 +130,7 @@ protected function validate(Parameter $parameter, ValidationErrors $errors): boo
127130
return false;
128131
}
129132

130-
$resourceFields = $this->getFields($type);
133+
$resourceFields = $type ? $this->getFields($type) : null;
131134

132135
if (!$resourceFields) {
133136
$errors[] = new ValidationError(
@@ -152,7 +155,7 @@ protected function validate(Parameter $parameter, ValidationErrors $errors): boo
152155
*
153156
* @param string $type
154157
*
155-
* @return array|null
158+
* @return array<int, string>|null
156159
*/
157160
protected function getFields(string $type): ?array
158161
{
@@ -164,7 +167,7 @@ protected function getFields(string $type): ?array
164167
/**
165168
* Validates the key for the specified fieldset group parameter.
166169
*
167-
* @param $parameter
170+
* @param Parameter $parameter
168171
* @param ValidationErrors $errors
169172
*
170173
* @return bool
@@ -201,9 +204,9 @@ protected function validateValue(Parameter $parameter, ValidationErrors $errors)
201204
{
202205
$value = $parameter->getValue();
203206
$type = $this->getGroupKey($parameter);
204-
$resourceFields = $this->getFields($type);
207+
$resourceFields = ($type ? $this->getFields($type) : []) ?? [];
205208

206-
if ($value === "" || $value === null) {
209+
if ($value === "") {
207210
return true;
208211
}
209212

@@ -216,12 +219,12 @@ protected function validateValue(Parameter $parameter, ValidationErrors $errors)
216219
/**
217220
* Helper function for validating that the $actualFields appear in $allowedFields.
218221
*
219-
* @param array $actualFields
220-
* @param array $allowedFields
222+
* @param array<int, string> $actualFields
223+
* @param array<int, string> $allowedFields
221224
* @param Parameter $parameter
222225
* @param ValidationErrors $errors
223226
*
224-
* @return array
227+
* @return bool
225228
*/
226229
protected function checkFieldList(
227230
array $actualFields,

src/JsonApi/Query/Validation/Parameter/IncludeRule.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
namespace Conjoon\JsonApi\Query\Validation\Parameter;
3030

3131
use Conjoon\Core\Util\ArrayUtil;
32-
use Conjoon\Http\Query\Parameter;
33-
use Conjoon\Http\Query\Validation\Parameter\ValueInWhitelistRule;
32+
use Conjoon\Net\Uri\Component\Query\Parameter;
33+
use Conjoon\Web\Validation\Parameter\Rule\ValueInWhitelistRule;
3434

3535
/**
3636
* Class providing functionality for making sure a query's include parameter contains only valid
@@ -66,7 +66,7 @@ protected function isParameterValueValid(Parameter $parameter, $whitelist): bool
6666
* Returns an empty array for an array string.
6767
*
6868
* @param string $value
69-
* @return array
69+
* @return array<int, string>
7070
*/
7171
protected function parse(string $value): array
7272
{
@@ -89,8 +89,8 @@ protected function parse(string $value): array
8989
* quoted above, the "MailFolder"-value is redundant, so the includes can be merged from
9090
* ["MailFolder", "MailFolder.MailAccount"] into ["MailFolder.MailAccount"].
9191
*
92-
* @param array $includes
93-
* @return array
92+
* @param array<int, string> $includes
93+
* @return array<int, string>
9494
*/
9595
protected function merge(array $includes): array
9696
{

src/JsonApi/Query/Validation/Parameter/PnFilterRule.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
use Conjoon\Data\Validation\ValidationError;
3232
use Conjoon\Data\Validation\ValidationErrors;
33-
use Conjoon\Http\Query\Parameter;
34-
use Conjoon\Http\Query\Validation\Parameter\JsonEncodedRule;
3533
use Conjoon\Math\Expression\Operator\FunctionalOperator;
3634
use Conjoon\Math\Expression\Operator\LogicalOperator;
3735
use Conjoon\Math\Expression\Operator\RelationalOperator;
36+
use Conjoon\Net\Uri\Component\Query\Parameter;
37+
use Conjoon\Web\Validation\Parameter\Rule\JsonEncodedRule;
3838

3939
/**
4040
* This parameter rule supports validation of filters provided as json encoded objects containing
@@ -53,15 +53,15 @@
5353
class PnFilterRule extends JsonEncodedRule
5454
{
5555
/**
56-
* @var array
56+
* @var array<int, string>
5757
*/
5858
protected array $attributes;
5959

6060

6161
/**
6262
* Constructor.
6363
*
64-
* @param array $attributes The list of valid attributes this rule considers.
64+
* @param array<int, string> $attributes The list of valid attributes this rule considers.
6565
*/
6666
public function __construct(array $attributes)
6767
{
@@ -99,11 +99,9 @@ protected function validate(Parameter $parameter, ValidationErrors $errors): boo
9999
}
100100

101101
//{"OR" : [{"==": ...}, {">=" : ...}}]
102-
if ($this->isLogicalOperator($operator)) {
103-
if (count($filter) <= 1) {
104-
return "Logical operator \"$operator\" " .
105-
"expects at least 2 operands, " . count($filter) . " given";
106-
}
102+
if (count($filter) <= 1) {
103+
return "Logical operator \"$operator\" " .
104+
"expects at least 2 operands, " . count($filter) . " given";
107105
}
108106

109107
foreach ($filter as $operand) {
@@ -196,7 +194,8 @@ public function getFunctions(): array
196194
/**
197195
* Returns all the attribute names this rule considers. The list of rules is dynamic and must be
198196
* specified with the constructor.
199-
* @return void
197+
*
198+
* @return array<int, string>
200199
*/
201200
public function getAttributes(): array
202201
{

src/JsonApi/Query/Validation/Query/QueryRule.php

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

2929
namespace Conjoon\JsonApi\Query\Validation\Query;
3030

31-
use Conjoon\Http\Query\Validation\Query\QueryRule as HttpQueryRule;
3231
use Conjoon\JsonApi\Query\Query;
32+
use Conjoon\Web\Validation\Query\QueryRule as HttpQueryRule;
3333

3434
/**
3535
* Rule specific for JsonApi.

src/JsonApi/Query/Validation/Validator.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929

3030
namespace Conjoon\JsonApi\Query\Validation;
3131

32-
use Conjoon\Http\Query\Exception\UnexpectedQueryParameterException;
33-
use Conjoon\Http\Query\Parameter;
34-
use Conjoon\Http\Query\Validation\Parameter\ParameterRuleList;
35-
use Conjoon\Http\Query\Validation\Query\OnlyParameterNamesRule;
36-
use Conjoon\Http\Query\Validation\Query\QueryRuleList;
37-
use Conjoon\Http\Query\Validation\Query\RequiredParameterNamesRule;
38-
use Conjoon\Http\Query\Validation\Validator as HttpQueryValidator;
39-
use Conjoon\Http\Query\Query as HttpQuery;
4032
use Conjoon\JsonApi\Query\Query;
4133
use Conjoon\JsonApi\Query\Validation\Parameter\FieldsetRule;
4234
use Conjoon\JsonApi\Query\Validation\Parameter\IncludeRule;
35+
use Conjoon\Net\Uri\Component\Query as HttpQuery;
36+
use Conjoon\Net\Uri\Component\Query\Parameter;
37+
use Conjoon\Web\Validation\Exception\UnexpectedQueryParameterException;
38+
use Conjoon\Web\Validation\Parameter\ParameterRuleList;
39+
use Conjoon\Web\Validation\Query\QueryRuleList;
40+
use Conjoon\Web\Validation\Query\Rule\OnlyParameterNamesRule;
41+
use Conjoon\Web\Validation\Query\Rule\RequiredParameterNamesRule;
42+
use Conjoon\Web\Validation\QueryValidator as HttpQueryValidator;
4343

4444
/**
4545
* Class for validating queries that target resource objects. Queries are checked for
@@ -105,7 +105,7 @@ public function getQueryRules(HttpQuery $query): QueryRuleList
105105
*
106106
* @param Query $query
107107
*
108-
* @return array
108+
* @return array<int, string>
109109
*/
110110
public function getAllowedParameterNames(HttpQuery $query): array
111111
{
@@ -123,6 +123,8 @@ public function getAllowedParameterNames(HttpQuery $query): array
123123

124124
/**
125125
* @inheritdoc
126+
*
127+
* @return array<int, string>
126128
*/
127129
public function getRequiredParameterNames(HttpQuery $query): array
128130
{
@@ -143,7 +145,7 @@ public function getRequiredParameterNames(HttpQuery $query): array
143145
*
144146
* @param Parameter $parameter
145147
*
146-
* @return array
148+
* @return array<int, string>
147149
*
148150
* @throws UnexpectedQueryParameterException
149151
*/
@@ -173,10 +175,10 @@ protected function unfoldInclude(Parameter $parameter): array
173175
* // $res: ["MailFolder", "MessageItem"]
174176
*
175177
*
176-
* @param $relationships
177-
* @return array
178+
* @param array<int, string> $relationships
179+
* @return array<int, string>
178180
*/
179-
protected function unfoldRelationships($relationships): array
181+
protected function unfoldRelationships(array $relationships): array
180182
{
181183
$res = [];
182184

0 commit comments

Comments
 (0)