Skip to content

Commit

Permalink
chore: add cs-fixer v3
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Jul 29, 2024
1 parent abb019d commit cff5f03
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
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 @@ class AWS extends AbstractAuth
*
* @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 @@ class AWS extends AbstractAuth
*/
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;
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 @@ private function hmacsha1(string $key, string $message): string
}
$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
$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/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';
}
14 changes: 7 additions & 7 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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 +65,7 @@ function parseDate(string $dateString)
}

try {
return new DateTime($dateString, new \DateTimeZone('UTC'));
return new \DateTime($dateString, new \DateTimeZone('UTC'));
} catch (\Exception $e) {
return false;
}
Expand All @@ -74,7 +74,7 @@ function parseDate(string $dateString)
/**
* 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 +171,9 @@ function negotiateContentType($acceptHeaderValue, array $availableOptions)

// 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 +331,7 @@ function parseMimeType(string $str): array
if (2 !== count($mimeType)) {
// Illegal value
var_dump($mimeType);
exit();
exit;

Check warning on line 334 in lib/functions.php

View check run for this annotation

Codecov / codecov/patch

lib/functions.php#L334

Added line #L334 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

0 comments on commit cff5f03

Please sign in to comment.