diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a89bffc..b85c50d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,7 +49,7 @@ jobs: - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: 8.2 ini-values: session.save_handler=redis, session.save_path="tcp://127.0.0.1:6379" extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql coverage: pcov @@ -159,7 +159,7 @@ jobs: - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: 8.2 extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql - name: Install dependencies @@ -171,4 +171,7 @@ jobs: run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php -v --dry-run --using-cache=no --show-progress=dots --diff $(git diff -- '*.php' --name-only --diff-filter=ACMRTUXB "HEAD~..HEAD") - name: Run PHPSTAN tests - run: composer phpstan \ No newline at end of file + run: composer phpstan + + - name: Run Rector tests + run: vendor/bin/rector process --dry-run \ No newline at end of file diff --git a/README.md b/README.md index 6eabaa1..540afc1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # Using the Mautic API Library ## Requirements -* PHP 8.0 or newer +* PHP 8.2 or newer ## Installing the API Library You can install the API Library with the following command: diff --git a/composer.json b/composer.json index 783515b..e02ab38 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } }, "require": { - "php": ">=8.0", + "php": ">=8.2", "ext-json": "*", "psr/log": "~1.0 || ~2.0 || ~3.0", "psr/http-client": "^1.0", @@ -24,17 +24,18 @@ }, "require-dev": { "kint-php/kint": "^4.1", - "friendsofphp/php-cs-fixer": "^3.73", + "friendsofphp/php-cs-fixer": "^3.93", "phpunit/phpunit": "~9.5.0", "guzzlehttp/guzzle": "^7.5", - "phpstan/phpstan": "^1.11" + "phpstan/phpstan": "^2.1", + "rector/rector": "^2.3" }, "suggest": { "guzzlehttp/guzzle": "A popular HTTP client that implements psr/http-client-implementation." }, "scripts": { "test": "vendor/bin/phpunit", - "phpstan": "vendor/bin/phpstan analyse" + "phpstan": "php -d memory_limit=1G vendor/bin/phpstan analyse" }, "config": { "allow-plugins": { diff --git a/lib/Api/Api.php b/lib/Api/Api.php index ed351c5..46df3be 100644 --- a/lib/Api/Api.php +++ b/lib/Api/Api.php @@ -111,7 +111,7 @@ public function __construct(AuthInterface $auth, $baseUrl = '') public function getLogger() { // If a logger hasn't been set, use NullLogger - if (!($this->logger instanceof LoggerInterface)) { + if (!$this->logger instanceof LoggerInterface) { $this->logger = new NullLogger(); } diff --git a/lib/Auth/OAuth.php b/lib/Auth/OAuth.php index 36d3089..e2c0d3c 100755 --- a/lib/Auth/OAuth.php +++ b/lib/Auth/OAuth.php @@ -471,9 +471,8 @@ protected function authorize(array $scope = [], $scope_separator = ',', $attach if (!$this->_do_not_redirect) { header('Location: '.$authUrl); exit; - } else { - throw new AuthorizationRequiredException($authUrl); } + throw new AuthorizationRequiredException($authUrl); } /** diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..6c35c4b --- /dev/null +++ b/rector.php @@ -0,0 +1,16 @@ +withPaths([ + __DIR__ . '/lib', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/tests/Api/CampaignsTest.php b/tests/Api/CampaignsTest.php index 263d4f5..a17ee92 100644 --- a/tests/Api/CampaignsTest.php +++ b/tests/Api/CampaignsTest.php @@ -308,7 +308,7 @@ public function testAddAndRemove() public function testBatchEndpoints() { - $this->standardTestBatchEndpoints(null, function ($response, &$batch, $action) { + $this->standardTestBatchEndpoints(null, function ($response, &$batch, $action): void { switch ($action) { case 'create': foreach ($batch as &$item) { diff --git a/tests/Api/ContactsTest.php b/tests/Api/ContactsTest.php index b526d0b..09d6934 100644 --- a/tests/Api/ContactsTest.php +++ b/tests/Api/ContactsTest.php @@ -52,7 +52,7 @@ protected function assertEventResponse($response, $expectedEvents = null) $this->assertTrue(isset($response['filters'])); if ($expectedEvents) { - foreach ($expectedEvents as $key => $eventName) { + foreach ($expectedEvents as $eventName) { $actual = 'oops Missing'; foreach ($response['events'] as $event) { if ($eventName == $event['event']) { diff --git a/tests/Api/FormsTest.php b/tests/Api/FormsTest.php index 536e0f1..ae509cf 100644 --- a/tests/Api/FormsTest.php +++ b/tests/Api/FormsTest.php @@ -196,7 +196,7 @@ public function testFieldAndActionDeleteViaPut() public function testBatchEndpoints() { - $this->standardTestBatchEndpoints(null, function ($response, &$batch, $action) { + $this->standardTestBatchEndpoints(null, function ($response, &$batch, $action): void { switch ($action) { case 'create': foreach ($batch as &$item) { diff --git a/tests/Api/PointTriggersTest.php b/tests/Api/PointTriggersTest.php index a05cf46..36f8226 100644 --- a/tests/Api/PointTriggersTest.php +++ b/tests/Api/PointTriggersTest.php @@ -146,7 +146,7 @@ public function testGetEventTypes() public function testBatchEndpoints() { - $this->standardTestBatchEndpoints(null, function ($response, &$batch, $action) { + $this->standardTestBatchEndpoints(null, function ($response, &$batch, $action): void { switch ($action) { case 'create': foreach ($batch as &$item) { diff --git a/tests/Api/SegmentsTest.php b/tests/Api/SegmentsTest.php index 7bdb6cb..c68d2a3 100644 --- a/tests/Api/SegmentsTest.php +++ b/tests/Api/SegmentsTest.php @@ -161,7 +161,7 @@ public function testAddAndRemove() public function testBatchEndpoints() { - $this->standardTestBatchEndpoints(null, function ($response, &$batch, $action) { + $this->standardTestBatchEndpoints(null, function ($response, &$batch, $action): void { switch ($action) { // Add extra values to the batch after create, as the API returns them in the response. // This is probably related to https://github.com/mautic/mautic/pull/8649