Skip to content

Commit

Permalink
fixed PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Jan 10, 2022
1 parent 92d58db commit d98356d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ parameters:
count: 1
path: src/bundle/Serializer/Normalizer/UserCollectionNormalizer.php

-
message: "#^Parameter \\#2 \\$array of function array_map expects array, array\\|ArrayObject\\|bool\\|float\\|int\\|string\\|null given\\.$#"
count: 1
path: src/bundle/Serializer/Normalizer/UserCollectionNormalizer.php

-
message: "#^Method EzSystems\\\\EzRecommendationClientBundle\\\\Serializer\\\\Normalizer\\\\UserNormalizer\\:\\:getNormalizedAttributes\\(\\) has parameter \\$attributes with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -215,11 +210,6 @@ parameters:
count: 1
path: src/bundle/Serializer/Normalizer/UserNormalizer.php

-
message: "#^Parameter \\#2 \\$array of function array_map expects array, array\\|ArrayObject\\|bool\\|float\\|int\\|string\\|null given\\.$#"
count: 1
path: src/bundle/Serializer/Normalizer/UserNormalizer.php

-
message: "#^Cannot call method get\\(\\) on Symfony\\\\Component\\\\HttpFoundation\\\\Request\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -280,11 +270,6 @@ parameters:
count: 2
path: src/lib/Authentication/ExportAuthenticator.php

-
message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|null given\\.$#"
count: 1
path: src/lib/Authentication/ExportAuthenticator.php

-
message: "#^Cannot call method getCustomerId\\(\\) on EzSystems\\\\EzRecommendationClient\\\\Value\\\\Config\\\\Credentials\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -615,11 +600,6 @@ parameters:
count: 1
path: src/lib/Factory/ExportParametersFactoryInterface.php

-
message: "#^Parameter \\#1 \\$string of function strtolower expects string, string\\|null given\\.$#"
count: 1
path: src/lib/Factory/EzRecommendationClientAPIFactory.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\TokenFactory\\:\\:createAnonymousToken\\(\\) has parameter \\$roles with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function getNormalizedUsers(UserCollection $object): array
$normalizedUsers = [];
$normalizedUsers[self::ATTR_NAME] = array_map(static function ($item) {
return $item[self::ATTR_NAME];
}, $users);
}, (array)$users);

return $normalizedUsers;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Serializer/Normalizer/UserNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function getNormalizedAttributes(array $attributes): array
$normalizedAttributes = [];
$normalizedAttributes['attribute'] = array_map(static function ($item) {
return $item['attribute'];
}, $attributes);
}, (array)$attributes);

return $normalizedAttributes;
}
Expand Down
9 changes: 7 additions & 2 deletions src/lib/Authentication/ExportAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function authenticate(): bool
*/
public function authenticateByFile(string $filePath): bool
{
$auth = [];
$server = $this->requestStack->getCurrentRequest()->server;

$user = $server->get(self::PHP_AUTH_USER);
Expand All @@ -77,8 +78,12 @@ public function authenticateByFile(string $filePath): bool

$fileContent = $this->fileManager->load($passFile);

list($auth['user'], $auth['pass']) = explode(':', trim($fileContent));
if (!$fileContent) {
return false;
}

[$auth['user'], $auth['pass']] = explode(':', trim($fileContent));

return $user == $auth['user'] && $pass == $auth['pass'];
return $user === $auth['user'] && $pass === $auth['pass'];
}
}
17 changes: 17 additions & 0 deletions src/lib/Exception/BadAPIEndpointParameterException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzRecommendationClient\Exception;

class BadAPIEndpointParameterException extends APIException
{
public function __construct(?\Throwable $previous = null)
{
parent::__construct('Bad API endpoint parameter given.', 0, $previous);
}
}
12 changes: 11 additions & 1 deletion src/lib/Factory/EzRecommendationClientAPIFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use EzSystems\EzRecommendationClient\API\AllowedAPI;
use EzSystems\EzRecommendationClient\Client\EzRecommendationClientInterface;
use EzSystems\EzRecommendationClient\Exception\BadAPICallException;
use EzSystems\EzRecommendationClient\Exception\BadAPIEndpointParameterException;
use EzSystems\EzRecommendationClient\Exception\InvalidArgumentException;
use EzSystems\EzRecommendationClient\Value\Parameters;

Expand Down Expand Up @@ -63,8 +64,17 @@ private function getApiEndPoint(string $apiName): string
);
}

/**
* @throws BadAPIEndpointParameterException
*/
private function getApiEndPointParameterName(string $apiName): string
{
return ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $apiName)), '_');
$sanitizedApiName = preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $apiName);

if (!$sanitizedApiName) {
throw new BadAPIEndpointParameterException();
}

return strtolower(ltrim($sanitizedApiName, '_'));
}
}

0 comments on commit d98356d

Please sign in to comment.