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

[8.0] Convert static property to constant #2463

Open
wants to merge 4 commits into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 1 addition & 11 deletions phpstan-baseline.neon
Expand Up @@ -146,12 +146,7 @@ parameters:
path: src/Cookie/CookieJarInterface.php

-
message: "#^Parameter \\#1 \\$string of function strlen expects string, bool\\|float\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Cookie/FileCookieJar.php

-
message: "#^Property GuzzleHttp\\\\Cookie\\\\SetCookie\\:\\:\\$defaults type has no value type specified in iterable type array\\.$#"
message: "#^Property GuzzleHttp\\\\Cookie\\\\SetCookie\\:\\:\\$data type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Cookie/SetCookie.php

Expand Down Expand Up @@ -760,11 +755,6 @@ parameters:
count: 1
path: src/PrepareBodyMiddleware.php

-
message: "#^Property GuzzleHttp\\\\RedirectMiddleware\\:\\:\\$defaultSettings has no typehint specified\\.$#"
count: 1
path: src/RedirectMiddleware.php

-
message: "#^Method GuzzleHttp\\\\RedirectMiddleware\\:\\:__invoke\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Expand Up @@ -263,7 +263,7 @@ private function buildUri($uri, array $config): UriInterface
private function configureDefaults(array $config): void
{
$defaults = [
'allow_redirects' => RedirectMiddleware::$defaultSettings,
'allow_redirects' => RedirectMiddleware::DEFAULT_SETTINGS,
'http_errors' => true,
'decode_content' => true,
'verify' => true,
Expand Down
8 changes: 4 additions & 4 deletions src/Cookie/SetCookie.php
Expand Up @@ -7,7 +7,7 @@
class SetCookie
{
/** @var array */
private static $defaults = [
private const DEFAULTS = [
'Name' => null,
'Value' => null,
'Domain' => null,
Expand All @@ -30,7 +30,7 @@ class SetCookie
public static function fromString(string $cookie): self
{
// Create the default return array
$data = self::$defaults;
$data = self::DEFAULTS;
Copy link

Choose a reason for hiding this comment

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

what was the reason changing this?

// Explode the cookie string using a series of semicolons
$pieces = \array_filter(\array_map('trim', \explode(';', $cookie)));
// The name of the cookie (first kvp) must exist and include an equal sign.
Expand All @@ -51,7 +51,7 @@ public static function fromString(string $cookie): self
$data['Name'] = $key;
$data['Value'] = $value;
} else {
foreach (\array_keys(self::$defaults) as $search) {
foreach (\array_keys(self::DEFAULTS) as $search) {
if (!\strcasecmp($search, $key)) {
$data[$search] = $value;
continue 2;
Expand All @@ -69,7 +69,7 @@ public static function fromString(string $cookie): self
*/
public function __construct(array $data = [])
{
$replaced = \array_replace(self::$defaults, $data);
$replaced = \array_replace(self::DEFAULTS, $data);
if ($replaced === null) {
throw new \InvalidArgumentException('Unable to replace the default values for the Cookie.');
}
Expand Down
9 changes: 6 additions & 3 deletions src/RedirectMiddleware.php
Expand Up @@ -20,7 +20,10 @@ class RedirectMiddleware

const STATUS_HISTORY_HEADER = 'X-Guzzle-Redirect-Status-History';

public static $defaultSettings = [
/**
* @var array
*/
public const DEFAULT_SETTINGS = [
'max' => 5,
'protocols' => ['http', 'https'],
'strict' => false,
Expand Down Expand Up @@ -48,12 +51,12 @@ public function __invoke(RequestInterface $request, array $options): PromiseInte
}

if ($options['allow_redirects'] === true) {
$options['allow_redirects'] = self::$defaultSettings;
$options['allow_redirects'] = self::DEFAULT_SETTINGS;
} elseif (!\is_array($options['allow_redirects'])) {
throw new \InvalidArgumentException('allow_redirects must be true, false, or array');
} else {
// Merge the default settings with the provided settings
$options['allow_redirects'] += self::$defaultSettings;
$options['allow_redirects'] += self::DEFAULT_SETTINGS;
}

if (empty($options['allow_redirects']['max'])) {
Expand Down