diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index e02e209..cb5e2d0 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -2,13 +2,40 @@ name: Static Analysis on: push: - branches: [ master ] + branches: [ main ] pull_request: jobs: + codesniffer: + name: PHP CodeSniffer + runs-on: ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: composer:v2 + coverage: none + env: + update: true + + - name: Install Dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --no-interaction --no-progress + + - name: Execute PHP CodeSniffer + run: vendor/bin/phpcs -n -q --standard=PSR12 ./src ./tests + psalm: name: Psalm - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout code @@ -17,9 +44,11 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '7.4' tools: composer:v2 coverage: none + env: + update: true - name: Install Dependencies uses: nick-invision/retry@v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eaa353a..38b1a4e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,17 +2,17 @@ name: Tests on: push: - branches: [ master ] + branches: [ main ] pull_request: jobs: tests: name: PHP ${{ matrix.php }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: matrix: - php: ['7.4', '8.0', '8.1'] + php: ['7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout Code @@ -24,6 +24,8 @@ jobs: php-version: ${{ matrix.php }} tools: composer:v2 coverage: none + env: + update: true - name: Setup Problem Matchers run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" diff --git a/README.md b/README.md index 86734de..35fae23 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This SDK currently supports the following versions of CloudEvents: -- [v1.0](https://github.com/cloudevents/spec/blob/v1.0.1/spec.md) +- [v1.0](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md) ## Installation @@ -109,11 +109,11 @@ scripts: Each SDK may have its own unique processes, tooling and guidelines, common governance related material can be found in the -[CloudEvents `community`](https://github.com/cloudevents/spec/tree/master/community) +[CloudEvents `community`](https://github.com/cloudevents/spec#community-and-docs) directory. In particular, in there you will find information concerning how SDK projects are -[managed](https://github.com/cloudevents/spec/blob/master/community/SDK-GOVERNANCE.md), -[guidelines](https://github.com/cloudevents/spec/blob/master/community/SDK-maintainer-guidelines.md) +[managed](https://github.com/cloudevents/spec/blob/main/docs/SDK-GOVERNANCE.md), +[guidelines](https://github.com/cloudevents/spec/blob/main/docs/SDK-maintainer-guidelines.md) for how PR reviews and approval, and our -[Code of Conduct](https://github.com/cloudevents/spec/blob/master/community/GOVERNANCE.md#additional-information) +[Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md) information. diff --git a/composer.json b/composer.json index 5e22f18..dbcd84b 100644 --- a/composer.json +++ b/composer.json @@ -18,19 +18,19 @@ } }, "require": { - "php": "^7.4 || ^8.0", + "php": "^7.4.15 || ^8.0.2", "ext-json": "*", "ext-pcre": "*", - "symfony/polyfill-php80": "^1.17" + "symfony/polyfill-php80": "^1.26" }, "require-dev": { - "guzzlehttp/psr7": "^2.0", - "php-http/discovery": "^1.14", - "phpunit/phpunit": "^9.5 || ^10.0", - "psalm/phar": "4.15.0", + "guzzlehttp/psr7": "^2.4.3", + "php-http/discovery": "^1.15.2", + "phpunit/phpunit": "^9.6.3 || ^10.0.12", + "psalm/phar": "5.7.6", "psr/http-factory": "^1.0.1", "psr/http-message": "^1.0.1", - "squizlabs/php_codesniffer": "3.6.0" + "squizlabs/php_codesniffer": "3.7.2" }, "suggest": { "php-http/discovery": "Required for automatic discovery of HTTP message factories in the HTTP Marshaller.", @@ -40,19 +40,21 @@ "psr/http-message-implementation": "Required for use of the HTTP Marshaller and Unmarshaller." }, "scripts": { - "lint": "./vendor/bin/phpcs --standard=PSR12 ./src ./tests", - "lint-fix": "./vendor/bin/phpcbf --standard=PSR12 ./src ./tests", + "lint": "./vendor/bin/phpcs -n --standard=PSR12 ./src ./tests", + "lint-fix": "./vendor/bin/phpcbf -n --standard=PSR12 ./src ./tests", "tests": "./vendor/bin/phpunit", "sa": "./vendor/bin/psalm.phar", "tests-build": [ "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:7.4-tests -f hack/7.4.Dockerfile hack", "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:8.0-tests -f hack/8.0.Dockerfile hack", - "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:8.1-tests -f hack/8.1.Dockerfile hack" + "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:8.1-tests -f hack/8.1.Dockerfile hack", + "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:8.2-tests -f hack/8.1.Dockerfile hack" ], "tests-docker": [ "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:7.4-tests --coverage-html=coverage", "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:8.0-tests", - "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:8.1-tests" + "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:8.1-tests", + "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:8.2-tests" ] }, "scripts-descriptions": { @@ -65,11 +67,14 @@ }, "config": { "preferred-install": "dist", - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": true + } }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-main": "1.0-dev" } }, "minimum-stability": "dev", diff --git a/hack/7.4.Dockerfile b/hack/7.4.Dockerfile index 56e0ad3..87941f9 100644 --- a/hack/7.4.Dockerfile +++ b/hack/7.4.Dockerfile @@ -1,7 +1,7 @@ FROM php:7.4-alpine -LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/master/hack/7.4.Dockerfile" \ - org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/master/hack/README.md" \ +LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/main/hack/7.4.Dockerfile" \ + org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/main/hack/README.md" \ org.opencontainers.image.source="https://github.com/cloudevents/sdk-php" \ org.opencontainers.image.vendor="CloudEvent" \ org.opencontainers.image.title="PHP 7.4" \ diff --git a/hack/8.0.Dockerfile b/hack/8.0.Dockerfile index 8285996..8e7e0d1 100644 --- a/hack/8.0.Dockerfile +++ b/hack/8.0.Dockerfile @@ -1,7 +1,7 @@ FROM php:8.0-alpine -LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/master/hack/8.0.Dockerfile" \ - org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/master/hack/README.md" \ +LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/main/hack/8.0.Dockerfile" \ + org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/main/hack/README.md" \ org.opencontainers.image.source="https://github.com/cloudevents/sdk-php" \ org.opencontainers.image.vendor="CloudEvent" \ org.opencontainers.image.title="PHP 8.0" \ diff --git a/hack/8.1.Dockerfile b/hack/8.1.Dockerfile index a9f6b0f..3913014 100644 --- a/hack/8.1.Dockerfile +++ b/hack/8.1.Dockerfile @@ -1,7 +1,7 @@ -FROM php:8.1.0beta1-alpine +FROM php:8.1-alpine -LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/master/hack/8.1.Dockerfile" \ - org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/master/hack/README.md" \ +LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/main/hack/8.1.Dockerfile" \ + org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/main/hack/README.md" \ org.opencontainers.image.source="https://github.com/cloudevents/sdk-php" \ org.opencontainers.image.vendor="CloudEvent" \ org.opencontainers.image.title="PHP 8.1" \ diff --git a/hack/8.2.Dockerfile b/hack/8.2.Dockerfile new file mode 100644 index 0000000..22027fb --- /dev/null +++ b/hack/8.2.Dockerfile @@ -0,0 +1,22 @@ +FROM php:8.2-alpine + +LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/main/hack/8.2.Dockerfile" \ + org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/main/hack/README.md" \ + org.opencontainers.image.source="https://github.com/cloudevents/sdk-php" \ + org.opencontainers.image.vendor="CloudEvent" \ + org.opencontainers.image.title="PHP 8.2" \ + org.opencontainers.image.description="PHP 8.2 test environment for cloudevents/sdk-php" + +COPY --chown=www-data:www-data install-composer /usr/local/bin/install-composer +RUN chmod +x /usr/local/bin/install-composer \ + && /usr/local/bin/install-composer \ + && rm /usr/local/bin/install-composer + +RUN apk update \ + && apk --no-cache upgrade \ + && apk add --no-cache bash ca-certificates git libzip-dev \ + && rm -rf /var/www/html /tmp/pear \ + && chown -R www-data:www-data /var/www + +WORKDIR /var/www +ENTRYPOINT ["/var/www/vendor/bin/phpunit"] diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c5f8f8e..39df3df 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,13 @@ - - - - tests/Unit - - - - - src - - + + + + tests/Unit + + + + + src + + diff --git a/src/Http/Unmarshaller.php b/src/Http/Unmarshaller.php index 89e2977..95c4885 100644 --- a/src/Http/Unmarshaller.php +++ b/src/Http/Unmarshaller.php @@ -92,18 +92,21 @@ private static function unmarshalBinary( MessageInterface $message, DeserializerInterface $deserializer ): array { + /** @var array> */ + $headers = $message->getHeaders(); + /** @psalm-suppress MixedArgumentTypeCoercion */ $cloudEvent = $deserializer->deserializeBinary( (string) $message->getBody(), implode(', ', $message->getHeader('Content-Type')), - self::decodeAttributes($message->getHeaders()) + self::decodeAttributes($headers) ); return [$cloudEvent]; } /** - * @param array> $headers + * @param array> $headers * * @return array */ @@ -112,6 +115,7 @@ private static function decodeAttributes(array $headers): array $attributes = []; foreach ($headers as $key => $values) { + $key = (string) $key; /** @psalm-suppress UndefinedFunction */ if (\str_starts_with($key, 'ce-')) { $attributes[substr($key, 3)] = implode(', ', $values); diff --git a/src/Utilities/TimeFormatter.php b/src/Utilities/TimeFormatter.php index 0bee483..b166608 100644 --- a/src/Utilities/TimeFormatter.php +++ b/src/Utilities/TimeFormatter.php @@ -34,6 +34,7 @@ public static function decode(?string $time): ?DateTimeImmutable return null; } + /** @psalm-suppress UndefinedFunction */ $decoded = DateTimeImmutable::createFromFormat( \str_contains($time, '.') ? self::RFC3339_EXTENDED_FORMAT : self::RFC3339_FORMAT, \strtoupper($time), diff --git a/src/V1/CloudEventTrait.php b/src/V1/CloudEventTrait.php index 23d11cd..b2fb3b4 100644 --- a/src/V1/CloudEventTrait.php +++ b/src/V1/CloudEventTrait.php @@ -273,10 +273,12 @@ private function setExtension(string $attribute, $value): self ); } + /** @psalm-suppress UndefinedFunction */ $type = \get_debug_type($value); $types = ['bool', 'int', 'string', 'null']; if (!in_array($type, $types, true)) { + /** @psalm-suppress MixedArgument */ throw new TypeError( \sprintf('%s(): Argument #2 ($value) must be of type %s, %s given', __METHOD__, implode('|', $types), $type) );