diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8616f1b..3933082 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 }} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..74ce439 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +rector: + vendor/bin/rector process src + +rector-dry: + vendor/bin/rector process src --dry-run \ No newline at end of file diff --git a/composer.json b/composer.json index 031e326..e4d3f8a 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": ">=7.2", + "php": ">=7.4", "ext-json": "*", "ext-mbstring": "*", "guzzlehttp/guzzle": "^6.4|^7.0", @@ -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": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..ce03657 --- /dev/null +++ b/rector.php @@ -0,0 +1,31 @@ +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 + ]); +}; diff --git a/src/Exception/SnelstartApiErrorException.php b/src/Exception/SnelstartApiErrorException.php index 5f997df..795dfa3 100644 --- a/src/Exception/SnelstartApiErrorException.php +++ b/src/Exception/SnelstartApiErrorException.php @@ -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 . ": "; @@ -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); } } \ No newline at end of file diff --git a/src/Request/ODataRequestData.php b/src/Request/ODataRequestData.php index 7228b0d..924cd2f 100644 --- a/src/Request/ODataRequestData.php +++ b/src/Request/ODataRequestData.php @@ -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 @@ -48,8 +48,6 @@ final class ODataRequestData implements ODataRequestDataInterface public function __construct() { - $this->top = Snelstart::MAX_RESULTS; - $this->skip = 0; } public function getFilter(): array diff --git a/src/Secure/CachedAccessTokenConnection.php b/src/Secure/CachedAccessTokenConnection.php index 174d623..56dc0fb 100644 --- a/src/Secure/CachedAccessTokenConnection.php +++ b/src/Secure/CachedAccessTokenConnection.php @@ -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); } } \ No newline at end of file