Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run PHPStan as Github Action #2

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,30 @@ jobs:
uses: "ramsey/composer-install@v1"

- name: "Run PHPUnit"
run: "vendor/bin/simple-phpunit --coverage-text"
run: "vendor/bin/phpunit --coverage-text"

phpstan:
runs-on: "ubuntu-20.04"

strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"

steps:
- uses: actions/checkout@v2

- name: "Install PHP ${{ matrix.php-version }}"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Run PHPStan"
run: "vendor/bin/phpstan analyse src --level 5"
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
}
},
"require-dev": {
"symfony/phpunit-bridge": "^5.0"
"symfony/phpunit-bridge": "^5.0",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.4"
}
}
16 changes: 8 additions & 8 deletions src/Negotiation/AbstractNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class AbstractNegotiator
* @param string $header A string containing an `Accept|Accept-*` header.
* @param array $priorities A set of server priorities.
*
* @return AcceptHeader|null best matching type
* @return BaseAccept|null best matching type
*/
public function getBest($header, array $priorities, $strict = false)
{
Expand Down Expand Up @@ -100,18 +100,18 @@ public function getOrderedElements($header)
/**
* @param string $header accept header part or server priority
*
* @return AcceptHeader Parsed header object
* @return BaseAccept Parsed header object
*/
abstract protected function acceptFactory($header);

/**
* @param AcceptHeader $header
* @param AcceptHeader $priority
* @param BaseAccept $header
* @param BaseAccept $priority
* @param integer $index
*
* @return AcceptMatch|null Headers matched
*/
protected function match(AcceptHeader $header, AcceptHeader $priority, $index)
protected function match(BaseAccept $header, BaseAccept $priority, $index)
{
$ac = $header->getType();
$pc = $priority->getType();
Expand All @@ -130,7 +130,7 @@ protected function match(AcceptHeader $header, AcceptHeader $priority, $index)
/**
* @param string $header A string that contains an `Accept*` header.
*
* @return AcceptHeader[]
* @return string[]
*/
private function parseHeader($header)
{
Expand All @@ -144,8 +144,8 @@ private function parseHeader($header)
}

/**
* @param AcceptHeader[] $headerParts
* @param Priority[] $priorities Configured priorities
* @param BaseAccept[] $headerParts
* @param BaseAccept[] $priorities Configured priorities
*
* @return AcceptMatch[] Headers matched
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Negotiation/Accept.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Negotiation\Exception\InvalidMediaType;

final class Accept extends BaseAccept implements AcceptHeader
final class Accept extends BaseAccept
{
private $basePart;

Expand Down
2 changes: 1 addition & 1 deletion src/Negotiation/AcceptCharset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Negotiation;

final class AcceptCharset extends BaseAccept implements AcceptHeader
final class AcceptCharset extends BaseAccept
{
}
2 changes: 1 addition & 1 deletion src/Negotiation/AcceptEncoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Negotiation;

final class AcceptEncoding extends BaseAccept implements AcceptHeader
final class AcceptEncoding extends BaseAccept
{
}
12 changes: 10 additions & 2 deletions src/Negotiation/AcceptLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Negotiation\Exception\InvalidLanguage;

final class AcceptLanguage extends BaseAccept implements AcceptHeader
final class AcceptLanguage extends BaseAccept
{
private $language;
private $script;
Expand Down Expand Up @@ -32,7 +32,7 @@ public function __construct($value)
}

/**
* @return string
* @return null|string
*/
public function getSubPart()
{
Expand All @@ -46,4 +46,12 @@ public function getBasePart()
{
return $this->language;
}

/**
* @return null|string
*/
public function getScript()
{
return $this->script;
}
}
5 changes: 2 additions & 3 deletions src/Negotiation/BaseAccept.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Negotiation;

abstract class BaseAccept
abstract class BaseAccept implements AcceptHeader
{
/**
* @var float
Expand Down Expand Up @@ -140,14 +140,13 @@ private function parseParameters($acceptPart)
}

/**
* @param string $parameters
* @param array<string, string> $parameters
*
* @return string
*/
private function buildParametersString($parameters)
{
$parts = [];

ksort($parameters);
foreach ($parameters as $key => $val) {
$parts[] = sprintf('%s=%s', $key, $val);
Expand Down
2 changes: 1 addition & 1 deletion src/Negotiation/LanguageNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function acceptFactory($accept)
/**
* {@inheritdoc}
*/
protected function match(AcceptHeader $acceptLanguage, AcceptHeader $priority, $index)
protected function match(BaseAccept $acceptLanguage, BaseAccept $priority, $index)
{
if (!$acceptLanguage instanceof AcceptLanguage || !$priority instanceof AcceptLanguage) {
return null;
Expand Down
6 changes: 6 additions & 0 deletions tests/Negotiation/Tests/AcceptLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public function testGetValue($header, $expected)

}

public function testGetScript()
{
$accept = new AcceptLanguage("zh-Hans-CN;q=0.3");
$this->assertSame("hans", $accept->getScript());
}

public static function dataProviderForGetValue()
{
return array(
Expand Down