diff --git a/.github/main.workflow b/.github/main.workflow deleted file mode 100644 index 1b1d8cc..0000000 --- a/.github/main.workflow +++ /dev/null @@ -1,16 +0,0 @@ -workflow "Main" { - on = "push" - resolves = ["Roave BC Check", "PHPStan"] -} - -action "Roave BC Check" { - uses = "docker://nyholm/roave-bc-check-ga" - secrets = ["GITHUB_TOKEN"] - args = "" -} - -action "PHPStan" { - uses = "docker://oskarstark/phpstan-ga" - secrets = ["GITHUB_TOKEN"] - args = "analyse" -} diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 9f45e20..618034d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,50 +1,54 @@ -name: PHP Composer +name: Tests on: - push: - branches: [ 'master', '2.x' ] - pull_request: - branches: [ 'master', '2.x' ] + push: ~ + pull_request: ~ jobs: - build: - + php: strategy: matrix: - # https://github.com/marketplace/actions/setup-php-action#github-hosted-runners - operating-system: [ 'ubuntu-latest' ] php-versions: [ '7.3', '7.4', '8.0' ] - runs-on: ${{ matrix.operating-system }} + runs-on: 'ubuntu-latest' steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - name: Validate composer.json and composer.lock - run: composer validate + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: none - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - tools: phpunit, phpstan + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest - - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-suggest + - name: PHP Unit Tests + run: vendor/bin/phpunit - - name: PHP Unit Tests - run: composer test + lowest: + name: Lowest deps + runs-on: ubuntu-latest + steps: + - name: Set up PHP + uses: shivammathur/setup-php@2.9.0 + with: + php-version: 7.4 + coverage: pcov - - name: PHP Stan - if: matrix.php-versions == '7.3' - run: | - phpstan --version - phpstan analyse + - name: Checkout code + uses: actions/checkout@v2 - - name: Scrunitizer CI - if: matrix.php-versions == '7.3' - run: | - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml + - name: Download dependencies + run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable --prefer-lowest + + - name: Run tests + run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml + + - name: Scrunitizer CI + run: | + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover coverage.xml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..c6e6bf5 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,88 @@ +name: Static analysis + +on: + pull_request: ~ + push: + branches: + - master + +jobs: + phpstan: + name: PHPStan + runs-on: Ubuntu-20.04 + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@2.9.0 + with: + php-version: '7.4' + coverage: none + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Download dependencies + run: composer update --no-interaction --prefer-dist + + - name: PHPStan + uses: docker://oskarstark/phpstan-ga:0.12.70 + with: + entrypoint: /composer/vendor/bin/phpstan + args: analyze --no-progress + + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: Ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga:2.18.2 + with: + args: --dry-run --diff-format udiff + + psalm: + name: Psalm + runs-on: Ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Psalm + uses: docker://vimeo/psalm-github-actions:4.4.1 + with: + args: --no-progress --show-info=false --stats + + roave-bc-check: + name: Roave BC Check + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga + + composer-normalize: + name: Composer Normalize + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@2.9.0 + with: + php-version: 7.4 + coverage: none + tools: composer-normalize + + - name: Validate composer.json + run: composer validate + + - name: Normalize composer.json + run: composer-normalize --dry-run diff --git a/.gitignore b/.gitignore index 27b106d..39060e0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ phpunit.phar phpunit.xml modd.conf .phpunit.result.cache +.php_cs.cache +.phpunit.result.cache diff --git a/composer.json b/composer.json index b4d80d2..5254148 100644 --- a/composer.json +++ b/composer.json @@ -1,19 +1,35 @@ { "name": "mailgun/mailgun-php", "description": "The Mailgun SDK provides methods for all API functions.", + "license": "MIT", + "authors": [ + { + "name": "Travis Swientek", + "email": "travis@mailgunhq.com" + } + ], "require": { "php": "^7.3 || ^8.0", - "psr/http-client": "^1.0.1", - "php-http/multipart-stream-builder": "^1.1.2", "php-http/client-common": "^2.2.1", "php-http/discovery": "^1.9.1", + "php-http/multipart-stream-builder": "^1.1.2", + "psr/http-client": "^1.0.1", "webmozart/assert": "^1.9.1" }, "require-dev": { - "phpunit/phpunit": "^9.3", - "php-http/guzzle7-adapter": "^0.1.1", + "nyholm/nsa": "^1.2.1", "nyholm/psr7": "^1.3.1", - "nyholm/nsa": "^1.2.1" + "php-http/guzzle7-adapter": "^0.1.1", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "guzzlehttp/psr7": "PSR-7 message implementation that also provides common utility methods", + "php-http/curl-client": "cURL client for PHP-HTTP" + }, + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } }, "autoload": { "psr-4": { @@ -24,25 +40,5 @@ "psr-4": { "Mailgun\\Tests\\": "tests/" } - }, - "suggest": { - "php-http/curl-client": "cURL client for PHP-HTTP", - "guzzlehttp/psr7": "PSR-7 message implementation that also provides common utility methods" - }, - "license": "MIT", - "authors": [ - { - "name": "Travis Swientek", - "email": "travis@mailgunhq.com" - } - ], - "scripts": { - "test": "vendor/bin/phpunit", - "test-coverage": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" - }, - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } } } diff --git a/psalm.baseline.xml b/psalm.baseline.xml new file mode 100644 index 0000000..31b4be3 --- /dev/null +++ b/psalm.baseline.xml @@ -0,0 +1,88 @@ + + + + + $params + + + boolean + boolean + nullOrString + stringNotEmpty + stringNotEmpty + + + nullOrString + + + + + $class + + + + + boolean + + + + + $this->hydrator + + + isArray + + + + + isArray + isArray + + + + + nullOrIsArray + string + string + + + nullOrIsArray + + + + + $response->getFirstUrl() + $response->getLastUrl() + $response->getNextUrl() + $response->getPreviousUrl() + + + + + isArray + + + + + $params + + + + + protected static function reportInvalidArgument($message) + + + + + + + + $this->apiKey + + + + + getId + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..d70acfe --- /dev/null +++ b/psalm.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/Api/HttpApi.php b/src/Api/HttpApi.php index e6d8b91..4e71506 100644 --- a/src/Api/HttpApi.php +++ b/src/Api/HttpApi.php @@ -92,7 +92,7 @@ abstract class HttpApi case 402: throw HttpClientException::requestFailed($response); case 403: - throw HttpClientException::forbidden($response); + throw HttpClientException::forbidden($response); case 404: throw HttpClientException::notFound($response); case 413: diff --git a/tests/Model/Suppression/Unsubscribe/UnsubscribeTest.php b/tests/Model/Suppression/Unsubscribe/UnsubscribeTest.php index ca70612..1d5e6fe 100644 --- a/tests/Model/Suppression/Unsubscribe/UnsubscribeTest.php +++ b/tests/Model/Suppression/Unsubscribe/UnsubscribeTest.php @@ -19,7 +19,7 @@ class UnsubscribeTest extends BaseModelTest /** * @test */ - public function it_gets_empty_list_of_tags_by_default() + public function itGetsEmptyListOfTagsByDefault() { $unsubscribe = Unsubscribe::create(['address' => 'dummy@mailgun.net']); $this->assertEquals([], $unsubscribe->getTags()); @@ -28,7 +28,7 @@ class UnsubscribeTest extends BaseModelTest /** * @test */ - public function it_gets_tags() + public function itGetsTags() { $tags = ['tag1', 'tag2']; $unsubscribe = Unsubscribe::create(['address' => 'dummy@mailgun.net', 'tags' => $tags]);