Skip to content

Commit

Permalink
chore(deps): drop support to php < 8.1 and sf < 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Dec 6, 2023
1 parent fd1afbe commit ace4170
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 75 deletions.
23 changes: 4 additions & 19 deletions .github/workflows/cscheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,21 @@ jobs:
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 10
fetch-depth: 0

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "7.4"
php-version: "8.1"
tools: cs2pr

- name: Cache dependencies installed with composer
uses: actions/cache@v1
with:
path: "~/.composer/cache"
key: php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-locked-

- name: Install dependencies with composer
run: composer update --no-interaction --no-progress --no-suggest
run: composer install

- if: ${{ github.base_ref == '' }}
run: composer cscheck

- name: Install git-phpcs
if: ${{ github.base_ref != '' }}
run: wget https://github.com/diff-sniffer/diff-sniffer/releases/download/0.5.1/diff-sniffer.phar

- name: Fetch head branch
if: ${{ github.base_ref != '' }}
run: git remote set-branches --add origin $GITHUB_BASE_REF && git fetch origin $GITHUB_BASE_REF

- name: Run diff-sniffer
if: ${{ github.base_ref != '' }}
run: php diff-sniffer.phar origin/$GITHUB_BASE_REF...$GITHUB_SHA --report=checkstyle --standard=Solido src/ | cs2pr
run: composer cscheck -- --report=checkstyle | cs2pr
10 changes: 5 additions & 5 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ jobs:
runs-on: ubuntu-latest
name: Static analysis
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "8.0"
php-version: "8.2"
tools: cs2pr

- name: Cache dependencies installed with composer
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: "~/.composer/cache"
key: php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-locked-

- name: Install dependencies with composer
run: composer update --no-progress --no-suggest --no-interaction --prefer-dist
run: composer install

- if: ${{ github.base_ref == '' }}
run: composer phpstan

- name: Run a static analysis with phpstan/phpstan
if: ${{ github.base_ref != '' }}
run: composer phpstan --error-format=checkstyle | cs2pr
run: composer phpstan -- --error-format=checkstyle | cs2pr
23 changes: 14 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,42 @@ jobs:
strategy:
matrix:
php_version:
- '7.4'
- '8.0'
- '8.1'
- '8.2'

name: PHP ${{ matrix.php_version }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP with pecl extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: :opcache
tools: infection
ini-values: zend.assertions=1,assert.exception=1,assert.active=1
coverage: pcov

- run: composer install
- run: vendor/bin/phpunit --coverage-clover phpunit/phpunit.coverage.xml --log-junit phpunit/junit.xml
- run: vendor/bin/phpunit --coverage-clover phpunit/phpunit.coverage.xml --coverage-xml phpunit/coverage-xml --log-junit phpunit/junit.xml
- run: infection --threads=4 --logger-github --coverage=phpunit
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

- name: Set repository name
id: repository-name
run: >
echo ::set-output name=REPOSITORY_NAME::$(echo $GITHUB_REPOSITORY | tr '/' '_') ;
echo ::set-output name=REPOSITORY_OWNER::$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
run: |
echo "REPOSITORY_NAME=$(echo $GITHUB_REPOSITORY | tr '/' '_')" >> $GITHUB_OUTPUT
echo "REPOSITORY_OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)" >> $GITHUB_OUTPUT
- name: fix code coverage paths
working-directory: ./phpunit
run: |
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' phpunit.coverage.xml
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' junit.xml
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v1.5
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
"csfix": "vendor/bin/phpcbf --standard=Solido src/"
},
"require": {
"php": "^7.4 || ^8.0",
"solido/common": "^0.2 || ^0.3"
"php": "^8.1",
"solido/common": "^0.4"
},
"require-dev": {
"nyholm/psr7": "^1.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.4",
"roave/security-advisories": "dev-master",
"solido/php-coding-standards": "dev-master",
"symfony/http-foundation": "^4.4 || ^5.0 || ^6.0",
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
"willdurand/negotiation": "^2.3 || ^3.0"
},
"autoload": {
Expand All @@ -49,11 +49,11 @@
}
},
"archive": {
"exclude": [ ".gitignore", ".travis.yml", "tests" ]
"exclude": [ ".gitignore", ".github", "tests" ]
},
"extra": {
"branch-alias": {
"dev-master": "0.3.x-dev"
"dev-master": "0.4.x-dev"
}
}
}
12 changes: 5 additions & 7 deletions src/AcceptHeaderVersionGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ class AcceptHeaderVersionGuesser implements VersionGuesserInterface
private array $priorities;
private AdapterFactoryInterface $adapterFactory;

/**
* @param string[] $priorities
*/
public function __construct(array $priorities = ['*/*'], ?AdapterFactoryInterface $adapterFactory = null)
/** @param string[] $priorities */
public function __construct(array $priorities = ['*/*'], AdapterFactoryInterface|null $adapterFactory = null)
{
$this->priorities = (static fn (string ...$v) => $v)(...$priorities);
$this->adapterFactory = $adapterFactory ?? new AdapterFactory();

Check warning on line 23 in src/AcceptHeaderVersionGuesser.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ public function __construct(array $priorities = ['*/*'], AdapterFactoryInterface|null $adapterFactory = null) { $this->priorities = (static fn(string ...$v) => $v)(...$priorities); - $this->adapterFactory = $adapterFactory ?? new AdapterFactory(); + $this->adapterFactory = new AdapterFactory() ?? $adapterFactory; } public function guess(object $request, string|null $default) : string|null {

Check warning on line 23 in src/AcceptHeaderVersionGuesser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ public function __construct(array $priorities = ['*/*'], AdapterFactoryInterface|null $adapterFactory = null) { $this->priorities = (static fn(string ...$v) => $v)(...$priorities); - $this->adapterFactory = $adapterFactory ?? new AdapterFactory(); + $this->adapterFactory = new AdapterFactory() ?? $adapterFactory; } public function guess(object $request, string|null $default) : string|null {

Check warning on line 23 in src/AcceptHeaderVersionGuesser.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ public function __construct(array $priorities = ['*/*'], AdapterFactoryInterface|null $adapterFactory = null) { $this->priorities = (static fn(string ...$v) => $v)(...$priorities); - $this->adapterFactory = $adapterFactory ?? new AdapterFactory(); + $this->adapterFactory = new AdapterFactory() ?? $adapterFactory; } public function guess(object $request, string|null $default) : string|null {
}

public function guess(object $request, ?string $default): ?string
public function guess(object $request, string|null $default): string|null
{
try {
$adapter = $this->adapterFactory->createRequestAdapter($request);
} catch (UnsupportedRequestObjectException $e) {
} catch (UnsupportedRequestObjectException) {
return $default;
}

Expand All @@ -41,7 +39,7 @@ public function guess(object $request, ?string $default): ?string
$negotiator = new VersionAwareNegotiator();
try {
$header = $negotiator->getBest($acceptHeader, $this->priorities);
} catch (InvalidMediaType $exception) {
} catch (InvalidMediaType) {
return $default;
}

Expand Down
8 changes: 3 additions & 5 deletions src/CustomHeaderVersionGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@

class CustomHeaderVersionGuesser implements VersionGuesserInterface
{
private string $headerName;
private AdapterFactoryInterface $adapterFactory;

public function __construct(string $headerName = 'X-API-Version', ?AdapterFactoryInterface $adapterFactory = null)
public function __construct(private string $headerName = 'X-API-Version', AdapterFactoryInterface|null $adapterFactory = null)
{
$this->headerName = $headerName;
$this->adapterFactory = $adapterFactory ?? new AdapterFactory();

Check warning on line 17 in src/CustomHeaderVersionGuesser.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ private AdapterFactoryInterface $adapterFactory; public function __construct(private string $headerName = 'X-API-Version', AdapterFactoryInterface|null $adapterFactory = null) { - $this->adapterFactory = $adapterFactory ?? new AdapterFactory(); + $this->adapterFactory = new AdapterFactory() ?? $adapterFactory; } public function guess(object $request, string|null $default) : string|null {

Check warning on line 17 in src/CustomHeaderVersionGuesser.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ private AdapterFactoryInterface $adapterFactory; public function __construct(private string $headerName = 'X-API-Version', AdapterFactoryInterface|null $adapterFactory = null) { - $this->adapterFactory = $adapterFactory ?? new AdapterFactory(); + $this->adapterFactory = new AdapterFactory() ?? $adapterFactory; } public function guess(object $request, string|null $default) : string|null {

Check warning on line 17 in src/CustomHeaderVersionGuesser.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ private AdapterFactoryInterface $adapterFactory; public function __construct(private string $headerName = 'X-API-Version', AdapterFactoryInterface|null $adapterFactory = null) { - $this->adapterFactory = $adapterFactory ?? new AdapterFactory(); + $this->adapterFactory = new AdapterFactory() ?? $adapterFactory; } public function guess(object $request, string|null $default) : string|null {
}

public function guess(object $request, ?string $default): ?string
public function guess(object $request, string|null $default): string|null
{
try {
$adapter = $this->adapterFactory->createRequestAdapter($request);
} catch (UnsupportedRequestObjectException $e) {
} catch (UnsupportedRequestObjectException) {
return $default;
}

Expand Down
17 changes: 2 additions & 15 deletions src/Negotiation/AcceptMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,10 @@

final class AcceptMatch
{
public float $quality;
public int $score;
public string|int|null $headerIndex = null;

/** @var string|int */
public $index;

/** @var string|int */
public $headerIndex = null;

/**
* @param string|int $index
*/
public function __construct(float $quality, int $score, $index)
public function __construct(public float $quality, public int $score, public string|int $index)
{
$this->quality = $quality;
$this->score = $score;
$this->index = $index;
}

public static function compare(AcceptMatch $a, AcceptMatch $b): int
Expand Down
7 changes: 4 additions & 3 deletions src/Negotiation/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class Priority extends BaseAccept implements AcceptHeader
{
private string $basePart;
private string $subPart;
private ?string $version;
private string|null $version;

public function __construct(string $value)
{
parent::__construct($value);

$parts = explode('/', $this->type);

if (count($parts) !== 2 || ! $parts[0] || ! $parts[1]) {
Expand All @@ -40,12 +41,12 @@ public function getSubPart(): string
return $this->subPart;
}

public function setVersion(?string $version): void
public function setVersion(string|null $version): void
{
$this->version = $version;
}

public function getVersion(): ?string
public function getVersion(): string|null
{
return $this->version;
}
Expand Down
8 changes: 2 additions & 6 deletions src/Negotiation/VersionAwareNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function priorityFactory(string $priority): Priority
*
* @return Priority|null best matching type
*/
public function getBest(string $header, array $priorities): ?Priority
public function getBest(string $header, array $priorities): Priority|null
{
if (empty($priorities)) {
throw new InvalidArgument('A set of server priorities should be given.');
Expand Down Expand Up @@ -84,11 +84,7 @@ public function getBest(string $header, array $priorities): ?Priority
return $priority;
}

/**
* @param string|int $index
* @param string|int $headerIndex
*/
protected function match(Accept $accept, Priority $priority, $index, $headerIndex): ?AcceptMatch
protected function match(Accept $accept, Priority $priority, string|int $index, string|int $headerIndex): AcceptMatch|null
{
$ab = $accept->getBasePart();
$pb = $priority->getBasePart();
Expand Down
2 changes: 1 addition & 1 deletion src/VersionGuesserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface VersionGuesserInterface
/**
* Guess the api version from the given request.
*/
public function guess(object $request, ?string $default): ?string;
public function guess(object $request, string|null $default): string|null;
}

0 comments on commit ace4170

Please sign in to comment.