Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions 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 @@ -27,7 +27,8 @@
},
"require-dev": {
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^8.5.23",
"phpunit/phpunit": "^8.5|^9.6",
"rector/rector": "^0.17.1",
"vimeo/psalm": "^4.0|^5.0"
},
"suggest": {
Expand Down
33 changes: 33 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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\PHPUnit\Set\PHPUnitSetList;
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,
PHPUnitSetList::PHPUNIT_91,
]);

$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);
}
}
4 changes: 2 additions & 2 deletions src/Request/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Money\Money;
use Ramsey\Uuid\UuidInterface;
use RuntimeException;
use SnelstartPHP\Model\BaseObject;
use SnelstartPHP\Model\SnelstartObject;
use SnelstartPHP\Serializer\RequestSerializerInterface;
Expand Down Expand Up @@ -53,8 +54,7 @@ public function prepareAddOrEditRequestForSerialization(BaseObject $object, stri
}

if (!$methodExists) {
\trigger_error(sprintf("There is no method (get or is) on object %s for property %s", get_class($object), $editableAttributeName), \E_USER_NOTICE);
continue;
throw new RuntimeException(sprintf("There is no method (get or is) on object %s for property %s", get_class($object), $editableAttributeName));
}

$value = $object->{$methodName}();
Expand Down
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);
}
}
4 changes: 3 additions & 1 deletion tests/Request/BaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use RuntimeException;
use SnelstartPHP\Model\BaseObject;
use SnelstartPHP\Model\SnelstartObject;
use SnelstartPHP\Serializer\RequestSerializerInterface;
Expand Down Expand Up @@ -45,7 +46,8 @@ public function testEditableArgumentsCallForNotExistingMethod(): void

$object::$editableAttributes = [ "notExistingProperty" ];

$this->expectNotice();
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('There is no method (get or is) on object SnelstartPHP\\Tests\\stubs\\SimpleRequestObjectStub for property notExistingProperty');
$this->assertEmpty($request->prepareAddOrEditRequestForSerialization($object));
}

Expand Down