From d2c0916c4bb159c20da0f5ea680ef34aea4ff8b2 Mon Sep 17 00:00:00 2001 From: Beno!t POLASZEK Date: Thu, 5 Dec 2024 16:45:56 +0100 Subject: [PATCH] Feat: PHP8.4 compatibility (#5) --- .github/workflows/ci-workflow.yml | 66 +++++++++++++++++++++++++++++++ .scrutinizer.yml | 32 --------------- .travis.yml | 51 ------------------------ src/Helper/functions.php | 4 +- src/UriFactory.php | 4 +- 5 files changed, 70 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/ci-workflow.yml delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml new file mode 100644 index 0000000..0bc2cc3 --- /dev/null +++ b/.github/workflows/ci-workflow.yml @@ -0,0 +1,66 @@ +name: CI Workflow + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + code-style: + name: Code Style & Static Analysis + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.4 + extensions: mbstring, pcntl + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Check code style + run: vendor/bin/phpcs --standard=psr2 -n src/ + + + tests: + name: Test Suite + runs-on: ubuntu-latest + strategy: + max-parallel: 10 + matrix: + php: + - 8.0 + - 8.1 + - 8.2 + - 8.3 + - 8.4 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, curl, zip + coverage: xdebug + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Run tests + run: vendor/bin/phpunit --coverage-clover=coverage.xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 5f9e672..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,32 +0,0 @@ -filter: - excluded_paths: [tests/*] -checks: - php: - code_rating: true - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true -tools: - php_analyzer: true - php_code_coverage: false - php_code_sniffer: - config: - standard: PSR2 - filter: - paths: ['src'] - php_loc: - enabled: true - excluded_dirs: [vendor, tests] - php_cpd: - enabled: true - excluded_dirs: [vendor, tests] diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 54982b6..0000000 --- a/.travis.yml +++ /dev/null @@ -1,51 +0,0 @@ -dist: xenial - -language: php - -php: - - '8.0' - - '8.1' - - '8.2' - - 'nightly' - - -matrix: - allow_failures: - - php: 'nightly' - - -before_script: - - travis_retry composer self-update - - travis_retry composer global require hirak/prestissimo - - travis_retry composer install --no-interaction --prefer-dist --dev - -script: - - # PSR-2 - - ./vendor/bin/phpcs --standard=psr2 -n src/ - - # PhpUnit - whole project - - mkdir -p build/logs && ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml - - # League/Uri isolated factory test - - composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 ringcentral/psr7 - - composer req --dev --prefer-dist league/uri:^5.0 - - ./vendor/bin/phpunit tests/UriFactoryTest.php - - # Guzzle PSR-7 isolated ffactory test - - composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 ringcentral/psr7 - - composer req --dev --prefer-dist guzzlehttp/psr7 - - ./vendor/bin/phpunit tests/UriFactoryTest.php - - # Nyholm PSR-7 isolated ffactory test - - composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 ringcentral/psr7 - - composer req --dev --prefer-dist nyholm/psr7 - - ./vendor/bin/phpunit tests/UriFactoryTest.php - - # Nyholm PSR-7 isolated ffactory test - - composer rem --dev league/uri nyholm/psr7 guzzlehttp/psr7 ringcentral/psr7 - - composer req --dev --prefer-dist ringcentral/psr7 - - ./vendor/bin/phpunit tests/UriFactoryTest.php - -after_script: - - php vendor/bin/php-coveralls -v diff --git a/src/Helper/functions.php b/src/Helper/functions.php index 925c96e..c16107d 100644 --- a/src/Helper/functions.php +++ b/src/Helper/functions.php @@ -12,7 +12,7 @@ * @param UriFactoryInterface|null $factory * @return UriInterface */ -function uri(string $uri, UriFactoryInterface $factory = null): UriInterface +function uri(string $uri, ?UriFactoryInterface $factory = null): UriInterface { return UriFactory::factory()->createUri($uri, $factory); } @@ -22,7 +22,7 @@ function uri(string $uri, UriFactoryInterface $factory = null): UriInterface * @return UriInterface * @throws \RuntimeException */ -function current_location(UriFactoryInterface $factory = null): UriInterface +function current_location(?UriFactoryInterface $factory = null): UriInterface { return UriFactory::factory()->createUriFromCurrentLocation($factory); } diff --git a/src/UriFactory.php b/src/UriFactory.php index 17d104a..ef6b7eb 100644 --- a/src/UriFactory.php +++ b/src/UriFactory.php @@ -43,7 +43,7 @@ private function getDefaultAdapters() * @param UriFactoryInterface|null $factory * @return UriInterface */ - public function createUri(string $uri = '', UriFactoryInterface $factory = null): UriInterface + public function createUri(string $uri = '', ?UriFactoryInterface $factory = null): UriInterface { if (null !== $factory) { return $factory->createUri($uri); @@ -64,7 +64,7 @@ public function createUri(string $uri = '', UriFactoryInterface $factory = null) * @param UriFactoryInterface|null $factory * @return UriInterface */ - public function createUriFromCurrentLocation(UriFactoryInterface $factory = null): UriInterface + public function createUriFromCurrentLocation(?UriFactoryInterface $factory = null): UriInterface { if (!isset($_SERVER['HTTP_HOST'])) { throw new \RuntimeException('$_SERVER[\'HTTP_HOST\'] has not been set.');