Skip to content

Commit

Permalink
Use symfony code style
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed May 21, 2023
1 parent 8444a2b commit 201f3e8
Show file tree
Hide file tree
Showing 45 changed files with 515 additions and 507 deletions.
78 changes: 9 additions & 69 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,17 @@
$config = (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['operators' => ['=>' => null]],
'blank_line_after_opening_tag' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@Symfony' => true,
'declare_strict_types' => false,
'dir_constant' => true,
'fully_qualified_strict_types' => true,
'function_to_constant' => true,
'function_typehint_space' => true,
'header_comment' => false,
'list_syntax' => ['syntax' => 'short'],
'lowercase_cast' => true,
'magic_method_casing' => true,
'modernize_types_casting' => true,
'multiline_comment_opening_closing' => true,
'native_constant_invocation' => true,
'no_alias_functions' => true,
'no_alternative_syntax' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_spaces_around_offset' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unset_cast' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'php_unit_dedicate_assert_internal_type' => ['target' => 'newest'],
'php_unit_expectation' => ['target' => 'newest'],
'php_unit_mock' => ['target' => 'newest'],
'php_unit_mock_short_will_return' => true,
'php_unit_no_expectation_annotation' => ['target' => 'newest'],
'php_unit_test_annotation' => ['style' => 'prefix'],
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_align' => ['align' => 'vertical'],
'phpdoc_line_span' => ['method' => 'multi', 'property' => 'multi'],
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'phpdoc_var_without_name' => true,
'return_assignment' => true,
'self_static_accessor' => true,
'short_scalar_cast' => true,
'single_trait_insert_per_statement' => true,
'standardize_not_equals' => true,
'static_lambda' => true,
'ternary_to_null_coalescing' => true,
'trim_array_spaces' => true,
'visibility_required' => true,
'global_namespace_import' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_summary' => false,
'phpdoc_to_comment' => false,
'single_line_throw' => false,
'void_return' => false,
'yoda_style' => false,
// 'native_function_invocation' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
34 changes: 18 additions & 16 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ public function sendAsync(RequestInterface $request, array $options = []): Promi
public function send(RequestInterface $request, array $options = []): ResponseInterface
{
$options[RequestOptions::SYNCHRONOUS] = true;

return $this->sendAsync($request, $options)->wait();
}

/**
* The HttpClient PSR (PSR-18) specify this method.
*
* @inheritDoc
* {@inheritDoc}
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
Expand Down Expand Up @@ -184,6 +185,7 @@ public function requestAsync(string $method, $uri = '', array $options = []): Pr
public function request(string $method, $uri = '', array $options = []): ResponseInterface
{
$options[RequestOptions::SYNCHRONOUS] = true;

return $this->requestAsync($method, $uri, $options)->wait();
}

Expand Down Expand Up @@ -228,11 +230,11 @@ private function configureDefaults(array $config): void
{
$defaults = [
'allow_redirects' => RedirectMiddleware::$defaultSettings,
'http_errors' => true,
'decode_content' => true,
'verify' => true,
'cookies' => false,
'idn_conversion' => false,
'http_errors' => true,
'decode_content' => true,
'verify' => true,
'cookies' => false,
'idn_conversion' => false,
];

// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.
Expand Down Expand Up @@ -354,10 +356,10 @@ private function applyOptions(RequestInterface $request, array &$options): Reque
if (isset($options['form_params'])) {
if (isset($options['multipart'])) {
throw new InvalidArgumentException('You cannot use '
. 'form_params and multipart at the same time. Use the '
. 'form_params option if you want to send application/'
. 'x-www-form-urlencoded requests, and the multipart '
. 'option to send multipart/form-data requests.');
.'form_params and multipart at the same time. Use the '
.'form_params option if you want to send application/'
.'x-www-form-urlencoded requests, and the multipart '
.'option to send multipart/form-data requests.');
}
$options['body'] = \http_build_query($options['form_params'], '', '&');
unset($options['form_params']);
Expand Down Expand Up @@ -403,7 +405,7 @@ private function applyOptions(RequestInterface $request, array &$options): Reque
// Ensure that we don't have the header in different case and set the new value.
$modify['set_headers'] = Psr7\Utils::caselessRemove(['Authorization'], $modify['set_headers']);
$modify['set_headers']['Authorization'] = 'Basic '
. \base64_encode("$value[0]:$value[1]");
.\base64_encode("$value[0]:$value[1]");
break;
case 'digest':
// @todo: Do not rely on curl
Expand Down Expand Up @@ -447,7 +449,7 @@ private function applyOptions(RequestInterface $request, array &$options): Reque
// Ensure that we don't have the header in different case and set the new value.
$options['_conditional'] = Psr7\Utils::caselessRemove(['Content-Type'], $options['_conditional']);
$options['_conditional']['Content-Type'] = 'multipart/form-data; boundary='
. $request->getBody()->getBoundary();
.$request->getBody()->getBoundary();
}

// Merge in conditional headers if they are not present.
Expand All @@ -473,9 +475,9 @@ private function applyOptions(RequestInterface $request, array &$options): Reque
private function invalidBody(): InvalidArgumentException
{
return new InvalidArgumentException('Passing in the "body" request '
. 'option as an array to send a request is not supported. '
. 'Please use the "form_params" request option to send a '
. 'application/x-www-form-urlencoded request, or the "multipart" '
. 'request option to send a multipart/form-data request.');
.'option as an array to send a request is not supported. '
.'Please use the "form_params" request option to send a '
.'application/x-www-form-urlencoded request, or the "multipart" '
.'request option to send a multipart/form-data request.');
}
}
26 changes: 14 additions & 12 deletions src/Cookie/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public static function fromArray(array $cookies, string $domain): self
$cookieJar = new self();
foreach ($cookies as $name => $value) {
$cookieJar->setCookie(new SetCookie([
'Domain' => $domain,
'Name' => $name,
'Value' => $value,
'Discard' => true
'Domain' => $domain,
'Name' => $name,
'Value' => $value,
'Discard' => true,
]));
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public function getCookieByName(string $name): ?SetCookie
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function toArray(): array
{
Expand All @@ -107,12 +107,13 @@ public function toArray(): array
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function clear(?string $domain = null, ?string $path = null, ?string $name = null): void
{
if (!$domain) {
$this->cookies = [];

return;
} elseif (!$path) {
$this->cookies = \array_filter(
Expand Down Expand Up @@ -142,7 +143,7 @@ static function (SetCookie $cookie) use ($path, $domain, $name) {
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function clearSessionCookies(): void
{
Expand All @@ -155,7 +156,7 @@ static function (SetCookie $cookie): bool {
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function setCookie(SetCookie $cookie): bool
{
Expand All @@ -170,9 +171,10 @@ public function setCookie(SetCookie $cookie): bool
$result = $cookie->validate();
if ($result !== true) {
if ($this->strictMode) {
throw new \RuntimeException('Invalid cookie: ' . $result);
throw new \RuntimeException('Invalid cookie: '.$result);
}
$this->removeCookieIfEmpty($cookie);

return false;
}

Expand Down Expand Up @@ -253,7 +255,7 @@ public function extractCookies(RequestInterface $request, ResponseInterface $res
/**
* Computes cookie path following RFC 6265 section 5.1.4
*
* @link https://tools.ietf.org/html/rfc6265#section-5.1.4
* @see https://tools.ietf.org/html/rfc6265#section-5.1.4
*/
private function getCookiePathFromRequest(RequestInterface $request): string
{
Expand Down Expand Up @@ -289,8 +291,8 @@ public function withCookieHeader(RequestInterface $request): RequestInterface
!$cookie->isExpired() &&
(!$cookie->getSecure() || $scheme === 'https')
) {
$values[] = $cookie->getName() . '='
. $cookie->getValue();
$values[] = $cookie->getName().'='
.$cookie->getValue();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cookie/CookieJarInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* necessary. Subclasses are also responsible for storing and retrieving
* cookies from a file, database, etc.
*
* @link https://docs.python.org/2/library/cookielib.html Inspiration
* @see https://docs.python.org/2/library/cookielib.html Inspiration
* @extends \IteratorAggregate<SetCookie>
*/
interface CookieJarInterface extends \Countable, \IteratorAggregate
Expand Down
2 changes: 1 addition & 1 deletion src/Cookie/SessionCookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function load(): void
$this->setCookie(new SetCookie($cookie));
}
} elseif (\strlen($data)) {
throw new \RuntimeException("Invalid cookie data");
throw new \RuntimeException('Invalid cookie data');
}
}
}
30 changes: 15 additions & 15 deletions src/Cookie/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class SetCookie
* @var array
*/
private static $defaults = [
'Name' => null,
'Value' => null,
'Domain' => null,
'Path' => '/',
'Max-Age' => null,
'Expires' => null,
'Secure' => false,
'Discard' => false,
'HttpOnly' => false
'Name' => null,
'Value' => null,
'Domain' => null,
'Path' => '/',
'Max-Age' => null,
'Expires' => null,
'Secure' => false,
'Discard' => false,
'HttpOnly' => false,
];

/**
Expand Down Expand Up @@ -134,13 +134,13 @@ public function __construct(array $data = [])

public function __toString()
{
$str = $this->data['Name'] . '=' . ($this->data['Value'] ?? '') . '; ';
$str = $this->data['Name'].'='.($this->data['Value'] ?? '').'; ';
foreach ($this->data as $k => $v) {
if ($k !== 'Name' && $k !== 'Value' && $v !== null && $v !== false) {
if ($k === 'Expires') {
$str .= 'Expires=' . \gmdate('D, d M Y H:i:s \G\M\T', $v) . '; ';
$str .= 'Expires='.\gmdate('D, d M Y H:i:s \G\M\T', $v).'; ';
} else {
$str .= ($v === true ? $k : "{$k}={$v}") . '; ';
$str .= ($v === true ? $k : "{$k}={$v}").'; ';
}
}
}
Expand Down Expand Up @@ -436,7 +436,7 @@ public function matchesDomain(string $domain): bool
return false;
}

return (bool) \preg_match('/\.' . \preg_quote($cookieDomain, '/') . '$/', $domain);
return (bool) \preg_match('/\.'.\preg_quote($cookieDomain, '/').'$/', $domain);
}

/**
Expand Down Expand Up @@ -465,8 +465,8 @@ public function validate()
$name
)) {
return 'Cookie name must not contain invalid characters: ASCII '
. 'Control characters (0-31;127), space, tab and the '
. 'following characters: ()<>@,;:\"/?={}';
.'Control characters (0-31;127), space, tab and the '
.'following characters: ()<>@,;:\"/?={}';
}

// Value must not be null. 0 and empty string are valid. Empty strings
Expand Down

0 comments on commit 201f3e8

Please sign in to comment.