Skip to content

Commit

Permalink
PHPStan - update on v.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pekral committed Feb 16, 2022
1 parent 9bf3002 commit 4265854
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 219 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"phing/phing": "^2.16",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.3",
"phpstan/phpstan-deprecation-rules": "^0.12.2",
"phpstan/phpstan-phpunit": "^0.12.8",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.0",
"slevomat/coding-standard": "^6.0 || ^7.0"
},
Expand Down
35 changes: 28 additions & 7 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@
<properties>
<property name="enableNativeTypeHint" value="false"/>
</properties>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<properties>
<property name="enableObjectTypeHint" value="false"/>
</properties>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation"/>
Expand Down Expand Up @@ -94,6 +100,7 @@
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/>
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceDeclaration"/>
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
Expand Down Expand Up @@ -133,13 +140,13 @@
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeControlStructure"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator">
<properties>
<property name="lineLengthLimit" value="75"/>
<property name="lineLengthLimit" value="120"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing"/>
<rule ref="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature">
<properties>
<property name="maxLineLength" value="150"/>
<property name="maxLineLength" value="189"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
Expand All @@ -157,20 +164,34 @@
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
<rule ref="SlevomatCodingStandard.Functions.RequireMultiLineCall">
<properties>
<property name="minLineLength" value="125"/>
<property name="minLineLength" value="190"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Functions.RequireSingleLineCall">
<properties>
<property name="maxLineLength" value="124"/>
<property name="maxLineLength" value="189"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireMultiLineCondition">
<properties>
<property name="minLineLength" value="125"/>
<property name="minLineLength" value="170"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousErrorNaming"/>
<rule ref="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration"/>
<rule ref="SlevomatCodingStandard.Classes.ForbiddenPublicProperty"/>

<!-- PHP 8 -->
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion"/>
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat"/>
<rule ref="SlevomatCodingStandard.Functions.FunctionLength">
<properties>
<property name="maxLinesLength" value="7120"/>
</properties>
</rule>

<!-- Enable after refactoring -->
<exclude name="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration"/>

</ruleset>
23 changes: 7 additions & 16 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,10 @@ public function __construct(
string $evidence,
bool $verifySSLCertificate,
?string $authSessionId = null,
?string $logFilePath = null
?string $logFilePath = null,
)
{
$this->config = new Config(
$url,
$company,
$user,
$password,
$evidence,
$verifySSLCertificate,
$authSessionId,
$logFilePath,
);
$this->config = new Config($url, $company, $user, $password, $evidence, $verifySSLCertificate, $authSessionId, $logFilePath);
$this->queryBuilder = new UrlBuilder($this->config);
$this->responseHydrator = new ResponseHydrator($this->config);
$this->httpClient = new HttpClient();
Expand Down Expand Up @@ -155,7 +146,7 @@ public function getAuthAndRefreshToken(): Response
$this->config,
);
}

public function deleteById(int $id, bool $dryRun = false): Response
{
$uriParameters = $dryRun ? ['dry-run' => 'true'] : [];
Expand All @@ -169,7 +160,7 @@ public function deleteById(int $id, bool $dryRun = false): Response
$this->config,
);
}

public function deleteByCode(string $id, bool $dryRun = false): void
{
$uriParameters = $dryRun ? ['dry-run' => 'true'] : [];
Expand All @@ -184,7 +175,7 @@ public function deleteByCode(string $id, bool $dryRun = false): void
}

/**
* @param array<mixed> $uriParameters
* @param array $uriParameters
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization
Expand Down Expand Up @@ -384,7 +375,7 @@ public function countInEvidence(): int
$this->config,
);

return $response->getRowCount() ?? 0;
return $response->getRowCount();
}

/**
Expand Down Expand Up @@ -471,7 +462,7 @@ public function searchInEvidencePaginated(string $query, array $uriParameters):
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail
*/
public function callRequest(Method $httpMethod, mixed $queryFilterOrId, array $uriParameters, array $postFields, array $headers): array
public function callRequest(Method $httpMethod, int|string|null $queryFilterOrId, array $uriParameters, array $postFields, array $headers): array
{
$response = $this->httpClient->request(
$this->queryBuilder->createUri($queryFilterOrId, $uriParameters),
Expand Down
33 changes: 8 additions & 25 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,17 @@
final class Config
{

private string $url;
private string $company;
private string $user;
private string $password;
private string $evidence;
private bool $verifySSLCertificate;
private ?string $authSessionId;
private ?string $logFilePath;

public function __construct(
string $url,
string $company,
string $user,
string $password,
string $evidence,
bool $verifySSLCertificate,
?string $authSessionId = null,
?string $logFilePath = null
private string $url,
private string $company,
private string $user,
private string $password,
private string $evidence,
private bool $verifySSLCertificate,
private ?string $authSessionId = null,
private ?string $logFilePath = null,
)
{
$this->url = $url;
$this->company = $company;
$this->user = $user;
$this->password = $password;
$this->evidence = $evidence;
$this->verifySSLCertificate = $verifySSLCertificate;
$this->authSessionId = $authSessionId;
$this->logFilePath = $logFilePath;
}

public function getUrl(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/SearchQueryOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SearchQueryOperator extends Enum
public static function convertOperatorsInQuery(string $query): string
{
$query = urldecode($query);
/** @var array<mixed> $queryExploded */
/** @var array<string> $queryExploded */
$queryExploded = preg_split('/\s+/', $query);

foreach($queryExploded as &$part) {
Expand Down
35 changes: 15 additions & 20 deletions src/Http/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,19 @@ public function __construct() {
$this->httpCurlBuilder = new HttpCurlBuilder();
}

/**
* @param array<mixed> $postFields
* @param array<string> $queryParameters
* @param array<string> $headers
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail
*/
public function request(
string $url,
Method $httpMethod,
array $postFields,
array $queryParameters,
array $headers,
Config $config
): FlexibeeResponse
/**
* @param array $postFields
* @param array $queryParameters
* @param array $headers
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest
* @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail
* @throws \League\Flysystem\FilesystemException
*/
public function request(string $url, Method $httpMethod, array $postFields, array $queryParameters, array $headers, Config $config): FlexibeeResponse
{

$ch = $this->httpCurlBuilder->build($url, $httpMethod, $postFields, $queryParameters, $headers, $config);
Expand All @@ -63,6 +57,7 @@ public function request(
$errorMessage = mb_strlen(trim(curl_error($ch))) === 0
? null
: curl_error($ch);
/** @var int $statusCode */
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($config->getLogFilePath() !== null) {
Expand All @@ -81,7 +76,7 @@ public function request(
$logContent = sprintf(
'%s METHOD: %s URL:%s TIME:%s STATUS:%s HEADERS: %s',
date('Y-m-d H:i:s'),
$httpMethod->getValue(),
$httpMethod,
$url,
number_format($responseTime, 2),
$statusCode,
Expand Down
8 changes: 7 additions & 1 deletion src/Http/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ final class Method extends Enum
public const DELETE = 'DELETE';
public const PUT = 'PUT';

}
public function __toString(): string
{
/** @phpstan-ignore-next-line */
return $this->getValue();
}

}
41 changes: 1 addition & 40 deletions src/Http/Response/FlexibeeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,14 @@
class FlexibeeResponse implements Response
{

private ?float $version = null;

private bool $success;

private ?string $message = null;

private int $statusCode;

/**
* @var array<mixed>
*/
private array $data;

/**
* @var array<string>
*/
private array $statistics = [];

private int $rowCount = 0;

private ?int $globalVersion = null;

/**
* FlexibeeResponse constructor.
*
* @param array<mixed> $data
* @param array<string> $statistics
*/
public function __construct(
int $statusCode,
?float $version,
bool $success,
?string $message,
int $rowCount,
?int $globalVersion,
array $data = [],
array $statistics = []
)
public function __construct(private int $statusCode, private ?float $version, private bool $success, private ?string $message = null, private int $rowCount = 0, private ?int $globalVersion = null, private array $data = [], private array $statistics = [])
{
$this->version = $version;
$this->success = $success;
$this->message = $message;
$this->statusCode = $statusCode;
$this->data = $data;
$this->statistics = $statistics;
$this->rowCount = $rowCount;
$this->globalVersion = $globalVersion;
}

public function getVersion(): ?float
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function isSuccess(): bool;
public function getStatusCode(): int;

/**
* @return array<mixed>
* @return array
*/
public function getData(): array;

Expand Down
Loading

0 comments on commit 4265854

Please sign in to comment.