Skip to content

Commit

Permalink
Update static ci job (#432)
Browse files Browse the repository at this point in the history
* update static ci

* update baselines

* fix

* test h2push better
  • Loading branch information
Nyholm authored Sep 23, 2024
1 parent 6736f6b commit 94c65f6
Show file tree
Hide file tree
Showing 32 changed files with 638 additions and 545 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/[email protected]
with:
php-version: 7.4
php-version: 8.2
tools: flex

- name: Checkout code
Expand All @@ -122,7 +122,7 @@ jobs:
- name: Run tests
run: |
docker run --rm --net buzz-bridge -v "$PWD":/usr/src/myapp -w /usr/src/myapp -e BUZZ_TEST_SERVER=http://test-server/index.php php:7.4-cli php vendor/bin/phpunit
docker run --rm --net buzz-bridge -v "$PWD":/usr/src/myapp -w /usr/src/myapp -e BUZZ_TEST_SERVER=http://test-server/index.php php:8.2-cli php vendor/bin/phpunit
lowest:
name: Lowest deps
Expand Down
64 changes: 42 additions & 22 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,67 @@
on: [ pull_request ]
name: Static analysis

on: [push, pull_request]

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: apcu, redis
coverage: none
tools: phpstan:1.12, cs2pr

- name: Download dependencies
run: |
composer update --no-interaction --prefer-dist --optimize-autoloader
uses: ramsey/composer-install@v2

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
with:
entrypoint: /composer/vendor/bin/phpstan
args: analyze --no-progress
run: phpstan analyze --no-progress --error-format=checkstyle | cs2pr

php-cs-fixer:
name: PHP-CS-Fixer
psalm:
name: Psalm
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
args: --dry-run --diff-format udiff
php-version: 8.3
extensions: apcu, redis
coverage: none
tools: vimeo/psalm:5.26

psalm:
name: Psalm
- name: Download dependencies
uses: ramsey/composer-install@v2

- name: Psalm
run: psalm --no-progress --output-format=github

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Psalm
uses: docker://vimeo/psalm-github-actions
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
args: --no-progress --show-info=false --stats
php-version: 8.3
coverage: none
tools: php-cs-fixer:3.64, cs2pr

- name: Display PHP-CS-Fixer version
run: sleep 1 && php-cs-fixer --version

- name: PHP-CS-Fixer
run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.php_cs.cache
.php-cs-fixer.cache
bin
composer.lock
composer.phar
Expand Down
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__ . '/lib')
->in(__DIR__ . '/tests')
->exclude('vendor')
->name('*.php');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => array('syntax' => 'short'),
'protected_to_private' => false,
'declare_strict_types' => true,
'no_superfluous_phpdoc_tags' => true,
'nullable_type_declaration_for_default_null_value' => false,
'modernize_strpos' => false,
])
->setFinder($finder);
21 changes: 0 additions & 21 deletions .php_cs

This file was deleted.

9 changes: 0 additions & 9 deletions .scrutinizer.yml

This file was deleted.

8 changes: 4 additions & 4 deletions lib/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Browser implements BuzzClientInterface
public function __construct(BuzzClientInterface $client, $requestFactory)
{
if (!$requestFactory instanceof RequestFactoryInterface && !$requestFactory instanceof RequestFactory) {
throw new InvalidArgumentException(sprintf('Second argument of %s must be an instance of %s or %s.', __CLASS__, RequestFactoryInterface::class, RequestFactory::class));
throw new InvalidArgumentException(\sprintf('Second argument of %s must be an instance of %s or %s.', __CLASS__, RequestFactoryInterface::class, RequestFactory::class));
}

$this->client = $client;
Expand Down Expand Up @@ -222,9 +222,9 @@ private function prepareMultipart(string $name, string $content, string $boundar
$fileHeaders = [];

// Set a default content-disposition header
$fileHeaders['Content-Disposition'] = sprintf('form-data; name="%s"', $name);
$fileHeaders['Content-Disposition'] = \sprintf('form-data; name="%s"', $name);
if (isset($data['filename'])) {
$fileHeaders['Content-Disposition'] .= sprintf('; filename="%s"', $data['filename']);
$fileHeaders['Content-Disposition'] .= \sprintf('; filename="%s"', $data['filename']);
}

// Set a default content-length header
Expand All @@ -239,7 +239,7 @@ private function prepareMultipart(string $name, string $content, string $boundar
// Add start
$output .= "--$boundary\r\n";
foreach ($fileHeaders as $key => $value) {
$output .= sprintf("%s: %s\r\n", $key, $value);
$output .= \sprintf("%s: %s\r\n", $key, $value);
}
$output .= "\r\n";
$output .= $content;
Expand Down
2 changes: 1 addition & 1 deletion lib/Client/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class AbstractClient
public function __construct($responseFactory, array $options = [])
{
if (!$responseFactory instanceof ResponseFactoryInterface && !$responseFactory instanceof ResponseFactory) {
throw new InvalidArgumentException(sprintf('First argument of %s must be an instance of %s or %s.', __CLASS__, ResponseFactoryInterface::class, ResponseFactory::class));
throw new InvalidArgumentException(\sprintf('First argument of %s must be an instance of %s or %s.', __CLASS__, ResponseFactoryInterface::class, ResponseFactory::class));
}

$this->options = new ParameterBag();
Expand Down
78 changes: 39 additions & 39 deletions lib/Client/AbstractCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ protected function releaseHandle($curl): void
// and are not cleaned up by curl_reset. Using curl_setopt_array
// does not work for some reason, so removing each one
// individually.
curl_setopt($curl, CURLOPT_HEADERFUNCTION, null);
curl_setopt($curl, CURLOPT_READFUNCTION, null);
curl_setopt($curl, CURLOPT_WRITEFUNCTION, null);
curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, null);
curl_setopt($curl, \CURLOPT_HEADERFUNCTION, null);
curl_setopt($curl, \CURLOPT_READFUNCTION, null);
curl_setopt($curl, \CURLOPT_WRITEFUNCTION, null);
curl_setopt($curl, \CURLOPT_PROGRESSFUNCTION, null);
curl_reset($curl);

if (!\in_array($curl, $this->handles)) {
Expand All @@ -84,19 +84,19 @@ protected function releaseHandle($curl): void
protected function prepare($curl, RequestInterface $request, ParameterBag $options): ResponseBuilder
{
if (\defined('CURLOPT_PROTOCOLS')) {
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_setopt($curl, \CURLOPT_PROTOCOLS, \CURLPROTO_HTTP | \CURLPROTO_HTTPS);
curl_setopt($curl, \CURLOPT_REDIR_PROTOCOLS, \CURLPROTO_HTTP | \CURLPROTO_HTTPS);
}

curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, \CURLOPT_HEADER, false);
curl_setopt($curl, \CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, \CURLOPT_FAILONERROR, false);

$this->setOptionsFromParameterBag($curl, $options);
$this->setOptionsFromRequest($curl, $request);

$responseBuilder = new ResponseBuilder($this->responseFactory);
curl_setopt($curl, CURLOPT_HEADERFUNCTION, function ($ch, $data) use ($responseBuilder) {
curl_setopt($curl, \CURLOPT_HEADERFUNCTION, function ($ch, $data) use ($responseBuilder) {
$str = trim($data);
if ('' !== $str) {
if (0 === strpos(strtolower($str), 'http/')) {
Expand All @@ -109,7 +109,7 @@ protected function prepare($curl, RequestInterface $request, ParameterBag $optio
return \strlen($data);
});

curl_setopt($curl, CURLOPT_WRITEFUNCTION, function ($ch, $data) use ($responseBuilder) {
curl_setopt($curl, \CURLOPT_WRITEFUNCTION, function ($ch, $data) use ($responseBuilder) {
return $responseBuilder->writeBody($data);
});

Expand All @@ -128,27 +128,27 @@ protected function prepare($curl, RequestInterface $request, ParameterBag $optio
private function setOptionsFromRequest($curl, RequestInterface $request): void
{
$options = [
CURLOPT_CUSTOMREQUEST => $request->getMethod(),
CURLOPT_URL => $request->getUri()->__toString(),
CURLOPT_HTTPHEADER => HeaderConverter::toBuzzHeaders($request->getHeaders()),
\CURLOPT_CUSTOMREQUEST => $request->getMethod(),
\CURLOPT_URL => $request->getUri()->__toString(),
\CURLOPT_HTTPHEADER => HeaderConverter::toBuzzHeaders($request->getHeaders()),
];

if (0 !== $version = $this->getProtocolVersion($request)) {
$options[CURLOPT_HTTP_VERSION] = $version;
$options[\CURLOPT_HTTP_VERSION] = $version;
}

if ($request->getUri()->getUserInfo()) {
$options[CURLOPT_USERPWD] = $request->getUri()->getUserInfo();
$options[\CURLOPT_USERPWD] = $request->getUri()->getUserInfo();
}

switch (strtoupper($request->getMethod())) {
case 'HEAD':
$options[CURLOPT_NOBODY] = true;
$options[\CURLOPT_NOBODY] = true;

break;

case 'GET':
$options[CURLOPT_HTTPGET] = true;
$options[\CURLOPT_HTTPGET] = true;

break;

Expand All @@ -167,16 +167,16 @@ private function setOptionsFromRequest($curl, RequestInterface $request): void
// Message has non empty body.
if (null === $bodySize || $bodySize > 1024 * 1024) {
// Avoid full loading large or unknown size body into memory
$options[CURLOPT_UPLOAD] = true;
$options[\CURLOPT_UPLOAD] = true;
if (null !== $bodySize) {
$options[CURLOPT_INFILESIZE] = $bodySize;
$options[\CURLOPT_INFILESIZE] = $bodySize;
}
$options[CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) {
$options[\CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) {
return $body->read($length);
};
} else {
// Small body can be loaded into memory
$options[CURLOPT_POSTFIELDS] = (string) $body;
$options[\CURLOPT_POSTFIELDS] = (string) $body;
}
}
}
Expand All @@ -190,16 +190,16 @@ private function setOptionsFromRequest($curl, RequestInterface $request): void
private function setOptionsFromParameterBag($curl, ParameterBag $options): void
{
if (null !== $proxy = $options->get('proxy')) {
curl_setopt($curl, CURLOPT_PROXY, $proxy);
curl_setopt($curl, \CURLOPT_PROXY, $proxy);
}

$canFollow = !ini_get('safe_mode') && !ini_get('open_basedir') && $options->get('allow_redirects');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, $canFollow);
curl_setopt($curl, CURLOPT_MAXREDIRS, $canFollow ? $options->get('max_redirects') : 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $options->get('verify') ? 1 : 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $options->get('verify') ? 2 : 0);
$canFollow = !\ini_get('safe_mode') && !\ini_get('open_basedir') && $options->get('allow_redirects');
curl_setopt($curl, \CURLOPT_FOLLOWLOCATION, $canFollow);
curl_setopt($curl, \CURLOPT_MAXREDIRS, $canFollow ? $options->get('max_redirects') : 0);
curl_setopt($curl, \CURLOPT_SSL_VERIFYPEER, $options->get('verify') ? 1 : 0);
curl_setopt($curl, \CURLOPT_SSL_VERIFYHOST, $options->get('verify') ? 2 : 0);
if (0 < $options->get('timeout')) {
curl_setopt($curl, CURLOPT_TIMEOUT, $options->get('timeout'));
curl_setopt($curl, \CURLOPT_TIMEOUT, $options->get('timeout'));
}
}

Expand All @@ -213,16 +213,16 @@ private function setOptionsFromParameterBag($curl, ParameterBag $options): void
protected function parseError(RequestInterface $request, int $errno, $curl): void
{
switch ($errno) {
case CURLE_OK:
case \CURLE_OK:
// All OK, create a response object
break;
case CURLE_COULDNT_RESOLVE_PROXY:
case CURLE_COULDNT_RESOLVE_HOST:
case CURLE_COULDNT_CONNECT:
case CURLE_OPERATION_TIMEOUTED:
case CURLE_SSL_CONNECT_ERROR:
case \CURLE_COULDNT_RESOLVE_PROXY:
case \CURLE_COULDNT_RESOLVE_HOST:
case \CURLE_COULDNT_CONNECT:
case \CURLE_OPERATION_TIMEOUTED:
case \CURLE_SSL_CONNECT_ERROR:
throw new NetworkException($request, curl_error($curl), $errno);
case CURLE_ABORTED_BY_CALLBACK:
case \CURLE_ABORTED_BY_CALLBACK:
throw new CallbackException($request, curl_error($curl), $errno);
default:
throw new RequestException($request, curl_error($curl), $errno);
Expand All @@ -233,12 +233,12 @@ private function getProtocolVersion(RequestInterface $request): int
{
switch ($request->getProtocolVersion()) {
case '1.0':
return CURL_HTTP_VERSION_1_0;
return \CURL_HTTP_VERSION_1_0;
case '1.1':
return CURL_HTTP_VERSION_1_1;
return \CURL_HTTP_VERSION_1_1;
case '2.0':
if (\defined('CURL_HTTP_VERSION_2_0')) {
return CURL_HTTP_VERSION_2_0;
return \CURL_HTTP_VERSION_2_0;
}

throw new \UnexpectedValueException('libcurl 7.33 needed for HTTP 2.0 support');
Expand Down
Loading

0 comments on commit 94c65f6

Please sign in to comment.