diff --git a/.github/workflows/WP_6_4.yaml b/.github/workflows/WP_6_4.yaml deleted file mode 100644 index b182778..0000000 --- a/.github/workflows/WP_6_4.yaml +++ /dev/null @@ -1,64 +0,0 @@ -name: WP6.4 [PHP7.4-8.2] Tests - -on: - push: - branches: [ master ] - pull_request: - branches: [ master, develop ] - -jobs: - build: - strategy: - matrix: - operating-system: [ubuntu-latest] - php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3'] - runs-on: ${{ matrix.operating-system }} - services: - # Setup MYSQL - mysql-service: - image: 'mysql:5.7' - env: - MYSQL_ROOT_PASSWORD: 'crab' - MYSQL_DATABASE: pc_core_tests - ports: - - 3306:3306 - options: >- - --health-cmd="mysqladmin ping" - --health-interval=10s - --health-timeout=5s - --health-retries=3 - - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: mbstring, intl, pcov - ini-values: post_max_size=256M, log_errors=1 - tools: pecl - - - name: Check PHP Version - run: php -v - - - name: Clear existing composer - run: > - sudo rm -rf vendor - && rm -rf composer.lock - - name: Validate composer.json and composer.lock - run: composer validate - - - name: Install dependencies - run: > - rm -rf composer.lock - && composer clearcache - && composer require php-stubs/wordpress-stubs:6.4.* --dev --no-update - && composer require roots/wordpress:6.4.* --dev --no-update - && composer require wp-phpunit/wp-phpunit:6.4.* --dev --no-update - && composer update --no-cache - - - name: Run Tests on Latest Version - WP6.4 - env: - environment_github: true - run: composer all diff --git a/.github/workflows/WP_6_5.yaml b/.github/workflows/WP_6_5.yaml deleted file mode 100644 index d68672f..0000000 --- a/.github/workflows/WP_6_5.yaml +++ /dev/null @@ -1,64 +0,0 @@ -name: WP6.5 [PHP7.4-8.3] Tests - -on: - push: - branches: [ master ] - pull_request: - branches: [ master, develop ] - -jobs: - build: - strategy: - matrix: - operating-system: [ubuntu-latest] - php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3'] - runs-on: ${{ matrix.operating-system }} - services: - # Setup MYSQL - mysql-service: - image: 'mysql:5.7' - env: - MYSQL_ROOT_PASSWORD: 'crab' - MYSQL_DATABASE: pc_core_tests - ports: - - 3306:3306 - options: >- - --health-cmd="mysqladmin ping" - --health-interval=10s - --health-timeout=5s - --health-retries=3 - - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: mbstring, intl, pcov - ini-values: post_max_size=256M, log_errors=1 - tools: pecl - - - name: Check PHP Version - run: php -v - - - name: Clear existing composer - run: > - sudo rm -rf vendor - && rm -rf composer.lock - - name: Validate composer.json and composer.lock - run: composer validate - - - name: Install dependencies - run: > - rm -rf composer.lock - && composer clearcache - && composer require php-stubs/wordpress-stubs:6.5.* --dev --no-update - && composer require roots/wordpress:6.5.* --dev --no-update - && composer require wp-phpunit/wp-phpunit:6.5.* --dev --no-update - && composer update --no-cache - - - name: Run Tests on Latest Version - WP6.5 - env: - environment_github: true - run: composer all diff --git a/.github/workflows/WP_6_6.yaml b/.github/workflows/WP_6_6.yaml index a55e127..a3c67d6 100644 --- a/.github/workflows/WP_6_6.yaml +++ b/.github/workflows/WP_6_6.yaml @@ -1,4 +1,4 @@ -name: WP6.6 [PHP7.4-8.4] Tests +name: WP 6.6 [PHP8.0-8.4] Tests on: push: @@ -11,23 +11,22 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] runs-on: ${{ matrix.operating-system }} services: - # Setup MYSQL mysql-service: - image: 'mysql:5.7' + image: mysql:8.4 env: MYSQL_ROOT_PASSWORD: 'crab' MYSQL_DATABASE: pc_core_tests ports: - 3306:3306 options: >- - --health-cmd="mysqladmin ping" + --health-cmd="healthcheck.sh --connect || mysqladmin ping -uroot -pcrab" --health-interval=10s - --health-timeout=5s - --health-retries=3 - + --health-timeout=10s + --health-retries=10 + steps: - name: Checkout uses: actions/checkout@v2 @@ -44,21 +43,21 @@ jobs: - name: Clear existing composer run: > - sudo rm -rf vendor - && rm -rf composer.lock + sudo rm -rf vendor + && rm -rf composer.lock - name: Validate composer.json and composer.lock run: composer validate - name: Install dependencies run: > - rm -rf composer.lock + rm -rf composer.lock && composer clearcache && composer require php-stubs/wordpress-stubs:6.6.* --dev --no-update && composer require roots/wordpress:6.6.* --dev --no-update && composer require wp-phpunit/wp-phpunit:6.6.* --dev --no-update && composer update --no-cache - - name: Run Tests on Latest Version - WP6.6 + - name: Run Tests on WP6.6 env: environment_github: true run: composer all diff --git a/.github/workflows/WP_6_7.yaml b/.github/workflows/WP_6_7.yaml index 931d566..3f6e96f 100644 --- a/.github/workflows/WP_6_7.yaml +++ b/.github/workflows/WP_6_7.yaml @@ -1,4 +1,4 @@ -name: WP6.7 [PHP7.4-8.4] Tests +name: WP 6.7 [PHP8.0-8.4] Tests on: push: @@ -11,23 +11,22 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] runs-on: ${{ matrix.operating-system }} services: - # Setup MYSQL mysql-service: - image: 'mysql:5.7' + image: mysql:8.4 env: MYSQL_ROOT_PASSWORD: 'crab' MYSQL_DATABASE: pc_core_tests ports: - 3306:3306 options: >- - --health-cmd="mysqladmin ping" + --health-cmd="healthcheck.sh --connect || mysqladmin ping -uroot -pcrab" --health-interval=10s - --health-timeout=5s - --health-retries=3 - + --health-timeout=10s + --health-retries=10 + steps: - name: Checkout uses: actions/checkout@v2 @@ -44,25 +43,21 @@ jobs: - name: Clear existing composer run: > - sudo rm -rf vendor - && rm -rf composer.lock + sudo rm -rf vendor + && rm -rf composer.lock - name: Validate composer.json and composer.lock run: composer validate - name: Install dependencies run: > - rm -rf composer.lock + rm -rf composer.lock && composer clearcache && composer require php-stubs/wordpress-stubs:6.7.* --dev --no-update && composer require roots/wordpress:6.7.* --dev --no-update && composer require wp-phpunit/wp-phpunit:6.7.* --dev --no-update && composer update --no-cache - - name: Run Tests on Latest Version - WP6.7 + - name: Run Tests on WP6.7 env: environment_github: true run: composer all - - - name: Codecov - run: bash <(curl -s https://codecov.io/bash) -t ${{ secrets.HTTP_CODCOV }} - \ No newline at end of file diff --git a/.github/workflows/WP_6_2.yaml b/.github/workflows/WP_6_8.yaml similarity index 66% rename from .github/workflows/WP_6_2.yaml rename to .github/workflows/WP_6_8.yaml index 9626d84..b8c310a 100644 --- a/.github/workflows/WP_6_2.yaml +++ b/.github/workflows/WP_6_8.yaml @@ -1,4 +1,4 @@ -name: WP6.2 [PHP7.4-8.3] Tests +name: WP 6.8 [PHP8.0-8.4] Tests on: push: @@ -11,23 +11,22 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3'] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] runs-on: ${{ matrix.operating-system }} services: - # Setup MYSQL mysql-service: - image: 'mysql:5.7' + image: mysql:8.4 env: MYSQL_ROOT_PASSWORD: 'crab' MYSQL_DATABASE: pc_core_tests ports: - 3306:3306 options: >- - --health-cmd="mysqladmin ping" + --health-cmd="healthcheck.sh --connect || mysqladmin ping -uroot -pcrab" --health-interval=10s - --health-timeout=5s - --health-retries=3 - + --health-timeout=10s + --health-retries=10 + steps: - name: Checkout uses: actions/checkout@v2 @@ -44,21 +43,21 @@ jobs: - name: Clear existing composer run: > - sudo rm -rf vendor - && rm -rf composer.lock + sudo rm -rf vendor + && rm -rf composer.lock - name: Validate composer.json and composer.lock run: composer validate - name: Install dependencies run: > - rm -rf composer.lock + rm -rf composer.lock && composer clearcache - && composer require php-stubs/wordpress-stubs:6.2.* --dev --no-update - && composer require roots/wordpress:6.2.* --dev --no-update - && composer require wp-phpunit/wp-phpunit:6.2.* --dev --no-update + && composer require php-stubs/wordpress-stubs:6.8.* --dev --no-update + && composer require roots/wordpress:6.8.* --dev --no-update + && composer require wp-phpunit/wp-phpunit:6.8.* --dev --no-update && composer update --no-cache - - name: Run Tests on Latest Version - WP6.2 + - name: Run Tests on WP6.8 env: environment_github: true run: composer all diff --git a/.github/workflows/WP_6_3.yaml b/.github/workflows/WP_6_9.yaml similarity index 60% rename from .github/workflows/WP_6_3.yaml rename to .github/workflows/WP_6_9.yaml index f512707..d04b9bb 100644 --- a/.github/workflows/WP_6_3.yaml +++ b/.github/workflows/WP_6_9.yaml @@ -1,4 +1,4 @@ -name: WP6.3 [PHP7.4-8.3] Tests +name: WP 6.9 [PHP8.0-8.4] Tests on: push: @@ -11,23 +11,22 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3'] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] runs-on: ${{ matrix.operating-system }} services: - # Setup MYSQL mysql-service: - image: 'mysql:5.7' + image: mysql:8.4 env: MYSQL_ROOT_PASSWORD: 'crab' MYSQL_DATABASE: pc_core_tests ports: - 3306:3306 options: >- - --health-cmd="mysqladmin ping" + --health-cmd="healthcheck.sh --connect || mysqladmin ping -uroot -pcrab" --health-interval=10s - --health-timeout=5s - --health-retries=3 - + --health-timeout=10s + --health-retries=10 + steps: - name: Checkout uses: actions/checkout@v2 @@ -44,21 +43,28 @@ jobs: - name: Clear existing composer run: > - sudo rm -rf vendor - && rm -rf composer.lock + sudo rm -rf vendor + && rm -rf composer.lock - name: Validate composer.json and composer.lock run: composer validate - name: Install dependencies run: > - rm -rf composer.lock + rm -rf composer.lock && composer clearcache - && composer require php-stubs/wordpress-stubs:6.3.* --dev --no-update - && composer require roots/wordpress:6.3.* --dev --no-update - && composer require wp-phpunit/wp-phpunit:6.3.* --dev --no-update + && composer require php-stubs/wordpress-stubs:6.9.* --dev --no-update + && composer require roots/wordpress:6.9.* --dev --no-update + && composer require wp-phpunit/wp-phpunit:6.9.* --dev --no-update && composer update --no-cache - - name: Run Tests on Latest Version - WP6.3 + - name: Run Tests on WP6.9 env: environment_github: true run: composer all + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.HTTP_CODCOV }} + files: ./clover.xml + fail_ci_if_error: false diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..f45b34a --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,85 @@ +checks: + php: + code_rating: true + duplication: true + fix_php_opening_tag: false + remove_php_closing_tag: false + one_class_per_file: false + side_effects_or_types: false + no_mixed_inline_html: false + require_braces_around_control_structures: false + php5_style_constructor: false + no_global_keyword: false + avoid_usage_of_logical_operators: false + psr2_class_declaration: false + no_underscore_prefix_in_properties: false + no_underscore_prefix_in_methods: false + blank_line_after_namespace_declaration: false + single_namespace_per_use: false + psr2_switch_declaration: false + psr2_control_structure_declaration: false + avoid_superglobals: false + security_vulnerabilities: false + no_exit: false + +build: + dependencies: + override: + - 'composer install --no-interaction --prefer-dist' + nodes: + analysis: + project_setup: + override: + - 'true' + tests: + override: + - php-scrutinizer-run + +tools: + php_analyzer: + enabled: true + filter: + excluded_paths: ['tests/*', 'docs/*', 'template/*', 'node_modules/*', 'vendor/*'] + config: + checkstyle: + enabled: true + naming: + isser_method_name: ^.*$ + utility_class_name: ^.*$ + doc_comment_fixes: + enabled: false + reflection_fixes: + enabled: false + use_statement_fixes: + enabled: false + simplify_boolean_return: + enabled: true + php_changetracking: true + php_cpd: true + php_cs_fixer: false + php_mess_detector: true + php_pdepend: true + sensiolabs_security_checker: true + +filter: + paths: + - 'src/*' + excluded_paths: + - 'tests/*' + - 'docs/*' + - 'docs-gen/*' + - 'node_modules/*' + - 'vendor/*' + - 'template/*' + +coding_style: + php: + indentation: + general: + use_tabs: true + size: 4 + spaces: + before_parentheses: + closure_definition: true + around_operators: + concatenation: true diff --git a/README.md b/README.md index 0cf8a68..b893e70 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,10 @@ Wrapper around Nyholm\Psr7 library with a few helper methods and a basic emitter ![GitHub contributors](https://img.shields.io/github/contributors/Pink-Crab/HTTP?label=Contributors) ![GitHub issues](https://img.shields.io/github/issues-raw/Pink-Crab/HTTP) -[![WordPress 6.7 Test Suite [PHP7.4-8.4]](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_7.yaml/badge.svg?branch=master)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_7.yaml) -[![WordPress 6.6 Test Suite [PHP7.4-8.4]](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_6.yaml/badge.svg?branch=master)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_6.yaml) -[![WordPress 6.5 Test Suite [PHP7.4-8.3]](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_5.yaml/badge.svg?branch=master)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_5.yaml) -[![WordPress 6.4 Test Suite [PHP7.4-8.3]](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_4.yaml/badge.svg?branch=master)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_4.yaml) -[![WordPress 6.3 Test Suite [PHP7.4-8.3]](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_3.yaml/badge.svg?branch=master)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_3.yaml) -[![WordPress 6.2 Test Suite [PHP7.4-8.3]](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_2.yaml/badge.svg?branch=master)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_2.yaml) +[![WP 6.6 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_6.yaml/badge.svg)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_6.yaml) +[![WP 6.7 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_7.yaml/badge.svg)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_7.yaml) +[![WP 6.8 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_8.yaml/badge.svg)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_8.yaml) +[![WP 6.9 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_9.yaml/badge.svg)](https://github.com/Pink-Crab/HTTP/actions/workflows/WP_6_9.yaml) [![codecov](https://codecov.io/gh/Pink-Crab/HTTP/branch/master/graph/badge.svg?token=ZP2DNBV3MT)](https://codecov.io/gh/Pink-Crab/HTTP) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Pink-Crab/HTTP/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Pink-Crab/HTTP/?branch=master) @@ -149,7 +147,13 @@ $stream = HTTP_Helper::stream_from_scalar($data); ### MIT License ### http://www.opensource.org/licenses/mit-license.html +## Tested Against ## +* PHP 8.0, 8.1, 8.2, 8.3 & 8.4 +* WP 6.6, 6.7, 6.8 & 6.9 +* MySQL 8.4 + ## Change Log ## +* 1.2.0 - Drop PHP 7.x, require PHP 8.0+. Bump dev deps: phpstan 2.x, phpstan-wordpress 2.x, phpunit 8|9, WP 6.6-6.9 test matrix. Retire the `WP_6_2` / `WP_6_3` / `WP_6_4` / `WP_6_5` workflows and add `WP_6_6` / `WP_6_7` / `WP_6_8` / `WP_6_9` (PHP 8.0-8.4, `mysql:8.4`). Standardise `.scrutinizer.yml`. Add curl-alternative and PSR12 file-header excludes to `phpcs.xml`. Suppress the WP 6.8 `wp_is_block_theme` early-call E_USER_NOTICE in `tests/wp-config.php` under PHPUnit's notice-to-exception conversion. Fill in descriptions on every bare `@param` / `@return` / `@throws` across `src/`. No public API changes. * 1.1.0 - Add nullable type hint to the reason phrase in the response and update dev dependencies * 1.0.0 - Removed HTTP::create_stream_with_json() * 0.2.6 - Readme changes diff --git a/composer.json b/composer.json index 326ef0b..397b3c1 100644 --- a/composer.json +++ b/composer.json @@ -23,36 +23,30 @@ } }, "require-dev": { - "phpunit/phpunit": "^8.5 || ^9.0", - "phpstan/phpstan": "1.*", - "szepeviktor/phpstan-wordpress": "<=1.3.2", - "php-stubs/wordpress-stubs": "6.7.*", - "roots/wordpress": "6.7.*", - "wp-phpunit/wp-phpunit": "6.7.*", - - "phpcompatibility/php-compatibility": "*", - "wp-coding-standards/wpcs": "^3", - "squizlabs/php_codesniffer": "3.*", + "phpunit/phpunit": "^8.0 || ^9.0", + "phpstan/phpstan": "^2.0", + "szepeviktor/phpstan-wordpress": "^2.0", + "php-stubs/wordpress-stubs": "6.9.*", + "roots/wordpress": "6.9.*", + "wp-phpunit/wp-phpunit": "6.9.*", "dealerdirect/phpcodesniffer-composer-installer": "*", - + "wp-coding-standards/wpcs": "*", "yoast/phpunit-polyfills": "^1.0.0 || ^2.0.0", - "roave/security-advisories": "dev-latest", - "symfony/var-dumper": "*", "gin0115/wpunit-helpers": "~1", "vlucas/phpdotenv": "^5.4" }, "require": { - "php": ">=7.4.0", + "php": ">=8.0.0", "nyholm/psr7": "^1.3", "nyholm/psr7-server": "^1.0" }, "scripts": { - "test": "phpunit --coverage-clover clover.xml --testdox --colors=always", - "coverage": "phpunit --coverage-html coverage-report --testdox --colors=always --exclude skip", - "analyse": "./vendor/bin/phpstan analyse src -l8", + "test": "vendor/bin/phpunit --colors=always --testdox --coverage-clover clover.xml", + "coverage": "vendor/bin/phpunit --colors=always --testdox --coverage-html coverage-report", + "analyse": "vendor/bin/phpstan analyse src -l8", "sniff": "./vendor/bin/phpcs src/ -v", - "all": "composer test && composer analyse && composer sniff" + "all": "composer coverage && composer analyse && composer sniff" }, "config": { "allow-plugins": { @@ -60,4 +54,4 @@ "dealerdirect/phpcodesniffer-composer-installer": true } } -} \ No newline at end of file +} diff --git a/phpcs.xml b/phpcs.xml index 7b6f220..515cc1e 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -12,6 +12,12 @@ + + + + + + diff --git a/src/HTTP.php b/src/HTTP.php index c8f3dc3..46e96d5 100644 --- a/src/HTTP.php +++ b/src/HTTP.php @@ -48,7 +48,7 @@ class HTTP { * @uses Psr17Factory::class * @uses ServerRequestCreator::class * - * @return ServerRequestInterface + * @return ServerRequestInterface Server request built from PHP superglobals, with $_POST re-encoded as a JSON body stream. */ public function request_from_globals(): ServerRequestInterface { @@ -73,7 +73,7 @@ public function request_from_globals(): ServerRequestInterface { * @param string|resource|StreamInterface|null $body Request body * @param string $version Protocol version * - * @return RequestInterface + * @return RequestInterface A Nyholm PSR-7 Request constructed from the given arguments. */ public function psr7_request( string $method, @@ -94,7 +94,7 @@ public function psr7_request( * @param string $version The response version. * @param string|null $reason The response reason. * - * @return ResponseInterface + * @return ResponseInterface A Nyholm PSR-7 Response; array/object bodies are JSON encoded before being set. */ public function psr7_response( $body = null, @@ -119,7 +119,7 @@ public function psr7_response( * @param integer $status The response status. * @param array $headers The response headers. * - * @return WP_HTTP_Response + * @return WP_HTTP_Response A WordPress HTTP response object holding the given data, status and headers. */ public function wp_response( $data = null, @@ -134,7 +134,7 @@ public function wp_response( * * @param ResponseInterface|WP_HTTP_Response|object $response The response to emit. * - * @return void + * @return void Sends headers and body to the output buffer; no value is returned. * * @throws InvalidArgumentException If response is not a valid type. */ @@ -157,8 +157,8 @@ public function emit_response( $response ): void { /** * Emits a PSR7 response. * - * @param ResponseInterface $response - * @return void + * @param ResponseInterface $response PSR-7 response whose status line, headers and body are written to output. + * @return void Writes directly to the output buffer; no value is returned. */ public function emit_psr7_response( ResponseInterface $response ): void { @@ -193,8 +193,8 @@ public function emit_psr7_response( ResponseInterface $response ): void { /** * Emits a WP_HTTP Response. * - * @param WP_HTTP_Response $response - * @return void + * @param WP_HTTP_Response $response WordPress HTTP response whose headers are sent and whose data is printed (JSON encoded if non-string). + * @return void Writes directly to the output buffer; no value is returned. */ public function emit_wp_response( WP_HTTP_Response $response ): void { @@ -221,8 +221,8 @@ public function emit_wp_response( WP_HTTP_Response $response ): void { /** * Adds the JSON content type header if no header set. * - * @param array $headers - * @return array + * @param array $headers Existing header map, keyed by header name. + * @return array The same map with a Content-Type of application/json (using the blog charset) added when absent. */ public function headers_with_json( array $headers = array() ): array { if ( ! array_key_exists( 'Content-Type', $headers ) ) { @@ -234,8 +234,8 @@ public function headers_with_json( array $headers = array() ): array { /** * Throws RunTime error if headers sent. * - * @return void - * @throws RuntimeException + * @return void Returns nothing when headers have not yet been sent. + * @throws RuntimeException If PHP reports that response headers have already been dispatched. */ protected function headers_sent(): void { if ( headers_sent() ) { @@ -246,8 +246,8 @@ protected function headers_sent(): void { /** * Wraps any value which can be json encoded in a StreamInterface * - * @param string|integer|float|object|array $data - * @return \Psr\Http\Message\StreamInterface + * @param string|integer|float|object|array $data Value to serialise into the stream; falsy json_encode results fall back to an empty string. + * @return \Psr\Http\Message\StreamInterface PSR-7 stream containing the JSON representation of the value. */ public function stream_from_scalar( $data ): StreamInterface { return Stream::create( json_encode( $data ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode diff --git a/src/HTTP_Helper.php b/src/HTTP_Helper.php index 1608a59..cafb9f1 100644 --- a/src/HTTP_Helper.php +++ b/src/HTTP_Helper.php @@ -47,7 +47,7 @@ class HTTP_Helper { * Returns the current HTTP instance. * Creates if doesnt exist. * - * @return HTTP + * @return HTTP The lazily-instantiated shared HTTP wrapper used by every helper method on this class. */ public static function get_http(): HTTP { if ( ! static::$http ) { @@ -59,7 +59,7 @@ public static function get_http(): HTTP { /** * Returns a ServerRequest with current globals. * - * @return ServerRequestInterface + * @return ServerRequestInterface Server request built from PHP superglobals, delegated to HTTP::request_from_globals(). */ public static function global_server_request(): ServerRequestInterface { return static::get_http() @@ -76,7 +76,7 @@ public static function global_server_request(): ServerRequestInterface { * @param string|resource|StreamInterface|null $body Request body * @param string $version Protocol version * - * @return RequestInterface + * @return RequestInterface PSR-7 Request built via HTTP::psr7_request(). */ public static function request( string $method, @@ -92,13 +92,13 @@ public static function request( /** * Returns a PS7 Response object. * - * @param integer $status - * @param array $headers - * @param array|string|resource|StreamInterface|null $body - * @param string $version - * @param string|null $reason + * @param integer $status HTTP status code sent with the response. + * @param array $headers Response headers keyed by header name. + * @param array|string|resource|StreamInterface|null $body Response body; arrays/objects are JSON encoded downstream. + * @param string $version HTTP protocol version string (e.g. "1.1"). + * @param string|null $reason Optional reason phrase; null lets the response pick the standard phrase for the status. * - * @return ResponseInterface + * @return ResponseInterface PSR-7 Response built via HTTP::psr7_response(). */ public static function response( $body = null, @@ -114,10 +114,10 @@ public static function response( /** * Returns a WP_Rest_Response * - * @param integer $status - * @param array $headers - * @param mixed $data - * @return WP_HTTP_Response + * @param integer $status HTTP status code sent with the response. + * @param array $headers Response headers keyed by header name. + * @param mixed $data Payload passed straight to WP_HTTP_Response; may be array, object, string or null. + * @return WP_HTTP_Response WordPress HTTP response built via HTTP::wp_response(). */ public static function wp_response( $data = null, @@ -131,8 +131,8 @@ public static function wp_response( /** * Wraps any value which can be json encoded in a StreamInterface * - * @param string|integer|float|object|array $value - * @return StreamInterface + * @param string|integer|float|object|array $value Value to serialise into the stream; falsy json_encode results fall back to an empty string. + * @return StreamInterface PSR-7 stream containing the JSON representation of the value. */ public static function stream_from_scalar( $value ): StreamInterface { return Stream::create( json_encode( $value ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode diff --git a/tests/wp-config.php b/tests/wp-config.php index 928abbe..55380d0 100644 --- a/tests/wp-config.php +++ b/tests/wp-config.php @@ -22,6 +22,18 @@ // Test with WordPress debug mode (default). define( 'WP_DEBUG', true ); +// Custom error handler to suppress known WP 6.8 notice about wp_is_block_theme being called too early. +// @see https://core.trac.wordpress.org/ticket/63086 +set_error_handler( + function ( $errno, $errstr ) { + if ( $errno === E_USER_NOTICE && strpos( $errstr, 'wp_is_block_theme' ) !== false ) { + return true; + } + return false; + }, + E_USER_NOTICE +); + // ** MySQL settings ** // // This configuration file will be used by the copy of WordPress being tested. @@ -31,7 +43,7 @@ // These tests will DROP ALL TABLES in the database with the prefix named below. // DO NOT use a production database or one that is shared with something else. if ( getenv( 'environment_github' ) ) { - define( 'DB_NAME', 'bp_events' ); + define( 'DB_NAME', 'pc_core_tests' ); define( 'DB_USER', 'root' ); define( 'DB_PASSWORD', 'crab' ); define( 'DB_HOST', '0.0.0.0' );