Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to php 7.4 using rector #43

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.2, 7.3, 7.4, 8.0, 8.1]
php: [7.4, 8.0, 8.1]
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rector:
vendor/bin/rector process src

rector-dry:
vendor/bin/rector process src --dry-run
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": ">=7.2",
"php": ">=7.4",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.4|^7.0",
Expand All @@ -28,6 +28,7 @@
"require-dev": {
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^8.5.23",
"rector/rector": "^0.17.1",
"vimeo/psalm": "^4.0|^5.0"
},
"suggest": {
Expand Down
31 changes: 31 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Assign\NullCoalescingOperatorRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
]);

$rectorConfig->skip([
TypedPropertyFromAssignsRector::class,
NullCoalescingOperatorRector::class, // https://wiki.php.net/rfc/null_coalesce_equal_operator
ClosureToArrowFunctionRector::class, // https://wiki.php.net/rfc/arrow_functions_v2
]);
};
4 changes: 2 additions & 2 deletions src/Exception/SnelstartApiErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class SnelstartApiErrorException extends \RuntimeException
public static function handleError(array $body): self
{
if (isset($body["modelState"])) {
$errorMessages = [ sprintf("%d validation failures occurred.", \count($body["modelState"])) ];
$errorMessages = [ sprintf("%d validation failures occurred.", is_countable($body["modelState"]) ? \count($body["modelState"]) : 0) ];

foreach ($body["modelState"] as $field => $modelStateErrors) {
$errorMessages[] = $field . ": ";
Expand Down Expand Up @@ -39,6 +39,6 @@ public static function handleError(array $body): self
return new static($body["Message"] ?? $body["message"], 400);
}

throw new static("Unknown exception. Message body: " . \json_encode($body), 400);
throw new static("Unknown exception. Message body: " . \json_encode($body, JSON_THROW_ON_ERROR), 400);
}
}
6 changes: 2 additions & 4 deletions src/Request/ODataRequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ final class ODataRequestData implements ODataRequestDataInterface
/**
* @var int
*/
private $top;
private $top = Snelstart::MAX_RESULTS;

/**
* @var int
*/
private $skip;
private $skip = 0;

/**
* @var string
Expand All @@ -48,8 +48,6 @@ final class ODataRequestData implements ODataRequestDataInterface

public function __construct()
{
$this->top = Snelstart::MAX_RESULTS;
$this->skip = 0;
}

public function getFilter(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Secure/CachedAccessTokenConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public function getToken(?BearerTokenInterface $bearerToken = null): AccessToken

protected function getItemKey(): string
{
return self::CACHE_ITEM_PREFIX . \spl_object_hash($this) . mt_rand(0, 99);
return self::CACHE_ITEM_PREFIX . \spl_object_hash($this) . random_int(0, 99);
}
}