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

chore: add cs-fixer v3 #243

Merged
merged 3 commits into from
Aug 27, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
coverage: ['xdebug']
code-style: ['no']
code-style: ['yes']
code-analysis: ['no']
include:
- php-versions: '7.1'
code-style: 'yes'
code-analysis: 'yes'
- php-versions: '8.4'
code-style: 'no'
code-style: 'yes'
code-analysis: 'yes'
steps:
- name: Checkout
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:

- name: Code Analysis (PHP CS-Fixer)
if: matrix.code-style == 'yes'
run: php vendor/bin/php-cs-fixer fix --dry-run --diff
run: PHP_CS_FIXER_IGNORE_ENV=true php vendor/bin/php-cs-fixer fix --dry-run --diff

- name: Code Analysis (PHPStan)
if: matrix.code-analysis == 'yes'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ composer.lock
tests/cov/
.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__);

$config = new PhpCsFixer\Config();
$config->setRules([
'@PSR1' => true,
'@Symfony' => true,
'nullable_type_declaration' => [
'syntax' => 'question_mark',
],
'nullable_type_declaration_for_default_null_value' => true,
]);
$config->setFinder($finder);
return $config;
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"sabre/uri" : "^2.0"
},
"require-dev" : {
"friendsofphp/php-cs-fixer": "~2.17.1",
"friendsofphp/php-cs-fixer": "~2.17.1||3.60",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit" : "^7.5 || ^8.5 || ^9.6"
},
Expand Down Expand Up @@ -50,7 +50,7 @@
"phpstan analyse lib tests"
],
"cs-fixer": [
"php-cs-fixer fix"
"PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix"
],
"phpunit": [
"phpunit --configuration tests/phpunit.xml"
Expand Down
2 changes: 1 addition & 1 deletion examples/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$request = new Request('GET', 'http://localhost/');

$client = new Client();
//$client->addCurlSetting(CURLOPT_PROXY,'localhost:8888');
// $client->addCurlSetting(CURLOPT_PROXY,'localhost:8888');
$response = $client->send($request);

echo "Response:\n";
Expand Down
4 changes: 2 additions & 2 deletions examples/stringify.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$request->setHeaders([
'Host' => 'example.org',
'Content-Type' => 'application/json',
]);
]);

$request->setBody(json_encode(['foo' => 'bar']));

Expand All @@ -41,7 +41,7 @@
$response->setHeaders([
'Content-Type' => 'text/plain',
'Connection' => 'close',
]);
]);

$response->setBody('ABORT! ABORT!');

Expand Down
16 changes: 8 additions & 8 deletions lib/Auth/AWS.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
*
* @var string
*/
private $signature = null;
private $signature;

/**
* The accesskey supplied by the HTTP client.
*
* @var string
*/
private $accessKey = null;
private $accessKey;

/**
* An error code, if any.
Expand All @@ -40,11 +40,11 @@
*/
public $errorCode = 0;

const ERR_NOAWSHEADER = 1;
const ERR_MD5CHECKSUMWRONG = 2;
const ERR_INVALIDDATEFORMAT = 3;
const ERR_REQUESTTIMESKEWED = 4;
const ERR_INVALIDSIGNATURE = 5;
public const ERR_NOAWSHEADER = 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supported from PHP 7.1

public const ERR_MD5CHECKSUMWRONG = 2;
public const ERR_INVALIDDATEFORMAT = 3;
public const ERR_REQUESTTIMESKEWED = 4;
public const ERR_INVALIDSIGNATURE = 5;

/**
* Gathers all information from the headers.
Expand Down Expand Up @@ -212,7 +212,7 @@
}
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$opad = str_repeat(chr(0x5C), $blocksize);

Check warning on line 215 in lib/Auth/AWS.php

View check run for this annotation

Codecov / codecov/patch

lib/Auth/AWS.php#L215

Added line #L215 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codecov complaint is related to issue #193
I won't bother removing this code in the 5.1 release series, it can be removed in major version 6.

$hmac = pack('H*', sha1(($key ^ $opad).pack('H*', sha1(($key ^ $ipad).$message))));

return $hmac;
Expand Down
6 changes: 2 additions & 4 deletions lib/Auth/Digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Digest extends AbstractAuth
/**
* These constants are used in setQOP();.
*/
const QOP_AUTH = 1;
const QOP_AUTHINT = 2;
public const QOP_AUTH = 1;
public const QOP_AUTHINT = 2;

protected $nonce;
protected $opaque;
Expand Down Expand Up @@ -177,8 +177,6 @@ public function requireLogin()
* It should be compatible with mod_php format and other webservers.
*
* If the header could not be found, null will be returned
*
* @return mixed
*/
public function getDigest()
{
Expand Down
8 changes: 3 additions & 5 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ public function setThrowExceptions(bool $throwExceptions)
* Adds a CURL setting.
*
* These settings will be included in every HTTP request.
*
* @param mixed $value
*/
public function addCurlSetting(int $name, $value)
{
Expand Down Expand Up @@ -419,9 +417,9 @@ protected function createCurlSettingsArray(RequestInterface $request): array
return $settings;
}

const STATUS_SUCCESS = 0;
const STATUS_CURLERROR = 1;
const STATUS_HTTPERROR = 2;
public const STATUS_SUCCESS = 0;
public const STATUS_CURLERROR = 1;
public const STATUS_HTTPERROR = 2;

private function parseResponse(string $response, $curlHandle): array
{
Expand Down
1 change: 0 additions & 1 deletion lib/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Sabre\HTTP;

use LogicException;
use Sabre\Uri;

/**
Expand Down
1 change: 0 additions & 1 deletion lib/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class Response extends Message implements ResponseInterface
* Creates the response object.
*
* @param string|int $status
* @param array $headers
* @param resource $body
*/
public function __construct($status = 500, ?array $headers = null, $body = null)
Expand Down
18 changes: 8 additions & 10 deletions lib/Sapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Sabre\HTTP;

use InvalidArgumentException;

/**
* PHP SAPI.
*
Expand Down Expand Up @@ -168,29 +166,29 @@ public static function createFromServerArray(array $serverArray): Request
$url = $value;
break;

// These sometimes show up without a HTTP_ prefix
// These sometimes show up without a HTTP_ prefix
case 'CONTENT_TYPE':
$headers['Content-Type'] = $value;
break;
case 'CONTENT_LENGTH':
$headers['Content-Length'] = $value;
break;

// mod_php on apache will put credentials in these variables.
// (fast)cgi does not usually do this, however.
// mod_php on apache will put credentials in these variables.
// (fast)cgi does not usually do this, however.
case 'PHP_AUTH_USER':
if (isset($serverArray['PHP_AUTH_PW'])) {
$headers['Authorization'] = 'Basic '.base64_encode($value.':'.$serverArray['PHP_AUTH_PW']);
}
break;

// Similarly, mod_php may also screw around with digest auth.
// Similarly, mod_php may also screw around with digest auth.
case 'PHP_AUTH_DIGEST':
$headers['Authorization'] = 'Digest '.$value;
break;

// Apache may prefix the HTTP_AUTHORIZATION header with
// REDIRECT_, if mod_rewrite was used.
// Apache may prefix the HTTP_AUTHORIZATION header with
// REDIRECT_, if mod_rewrite was used.
case 'REDIRECT_HTTP_AUTHORIZATION':
$headers['Authorization'] = $value;
break;
Expand Down Expand Up @@ -226,11 +224,11 @@ public static function createFromServerArray(array $serverArray): Request
}

if (null === $url) {
throw new InvalidArgumentException('The _SERVER array must have a REQUEST_URI key');
throw new \InvalidArgumentException('The _SERVER array must have a REQUEST_URI key');
}

if (null === $method) {
throw new InvalidArgumentException('The _SERVER array must have a REQUEST_METHOD key');
throw new \InvalidArgumentException('The _SERVER array must have a REQUEST_METHOD key');
}
$r = new Request($method, $url, $headers);
$r->setHttpVersion($httpVersion);
Expand Down
2 changes: 1 addition & 1 deletion lib/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class Version
/**
* Full version number.
*/
const VERSION = '5.1.11';
public const VERSION = '5.1.11';
}
17 changes: 7 additions & 10 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Sabre\HTTP;

use DateTime;
use InvalidArgumentException;

/**
* A collection of useful helpers for parsing or generating various HTTP
* headers.
Expand All @@ -29,7 +26,7 @@
* See:
* http://tools.ietf.org/html/rfc7231#section-7.1.1.1
*
* @return bool|DateTime
* @return bool|\DateTime
*/
function parseDate(string $dateString)
{
Expand Down Expand Up @@ -65,7 +62,7 @@
}

try {
return new DateTime($dateString, new \DateTimeZone('UTC'));
return new \DateTime($dateString, new \DateTimeZone('UTC'));
} catch (\Exception $e) {
return false;
}
Expand All @@ -74,7 +71,7 @@
/**
* Transforms a DateTime object to a valid HTTP/1.1 Date header value.
*/
function toDate(DateTime $dateTime): string
function toDate(\DateTime $dateTime): string
{
// We need to clone it, as we don't want to affect the existing
// DateTime.
Expand Down Expand Up @@ -171,9 +168,9 @@

// Does this entry win?
if (
($proposal['quality'] > $lastQuality) ||
($proposal['quality'] === $lastQuality && $specificity > $lastSpecificity) ||
($proposal['quality'] === $lastQuality && $specificity === $lastSpecificity && $optionIndex < $lastOptionIndex)
($proposal['quality'] > $lastQuality)
|| ($proposal['quality'] === $lastQuality && $specificity > $lastSpecificity)
|| ($proposal['quality'] === $lastQuality && $specificity === $lastSpecificity && $optionIndex < $lastOptionIndex)
) {
$lastQuality = $proposal['quality'];
$lastSpecificity = $specificity;
Expand Down Expand Up @@ -331,7 +328,7 @@
if (2 !== count($mimeType)) {
// Illegal value
var_dump($mimeType);
exit();
exit;

Check warning on line 331 in lib/functions.php

View check run for this annotation

Codecov / codecov/patch

lib/functions.php#L331

Added line #L331 was not covered by tests
// throw new InvalidArgumentException('Not a valid mime-type: '.$str);
}
list($type, $subType) = $mimeType;
Expand Down
4 changes: 2 additions & 2 deletions tests/HTTP/Auth/AWSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AWSTest extends \PHPUnit\Framework\TestCase
*/
private $auth;

const REALM = 'SabreDAV unittest';
public const REALM = 'SabreDAV unittest';

public function setUp(): void
{
Expand Down Expand Up @@ -228,7 +228,7 @@ private function hmacsha1($key, $message)
}
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$opad = str_repeat(chr(0x5C), $blocksize);
$hmac = pack('H*', sha1(($key ^ $opad).pack('H*', sha1(($key ^ $ipad).$message))));

return $hmac;
Expand Down
19 changes: 11 additions & 8 deletions tests/HTTP/Auth/DigestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DigestTest extends \PHPUnit\Framework\TestCase
*/
private $auth;

const REALM = 'SabreDAV unittest';
public const REALM = 'SabreDAV unittest';

public function setUp(): void
{
Expand All @@ -50,7 +50,7 @@ public function testDigest()
$nc.':'.
$cnonce.':'.
'auth:'.
md5('GET'.':'.'/')
md5('GET:/')
);

$this->request->setMethod('GET');
Expand Down Expand Up @@ -79,7 +79,7 @@ public function testInvalidDigest()
$nc.':'.
$cnonce.':'.
'auth:'.
md5('GET'.':'.'/')
md5('GET:/')
);

$this->request->setMethod('GET');
Expand Down Expand Up @@ -115,7 +115,7 @@ public function testDigestAuthInt()
$nc.':'.
$cnonce.':'.
'auth-int:'.
md5('POST'.':'.'/'.':'.md5('body'))
md5('POST:/:'.md5('body'))
);

$this->request->setMethod('POST');
Expand Down Expand Up @@ -143,7 +143,7 @@ public function testDigestAuthBoth()
$nc.':'.
$cnonce.':'.
'auth-int:'.
md5('POST'.':'.'/'.':'.md5('body'))
md5('POST:/:'.md5('body'))
);

$this->request->setMethod('POST');
Expand All @@ -160,9 +160,12 @@ private function getServerTokens($qop = Digest::QOP_AUTH)
$this->auth->requireLogin();

switch ($qop) {
case Digest::QOP_AUTH: $qopstr = 'auth'; break;
case Digest::QOP_AUTHINT: $qopstr = 'auth-int'; break;
default: $qopstr = 'auth,auth-int'; break;
case Digest::QOP_AUTH: $qopstr = 'auth';
break;
case Digest::QOP_AUTHINT: $qopstr = 'auth-int';
break;
default: $qopstr = 'auth,auth-int';
break;
}

$test = preg_match('/Digest realm="'.self::REALM.'",qop="'.$qopstr.'",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/',
Expand Down
Loading
Loading