1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-01-17 13:28:13 +01:00

Be more strict with types (#2914)

* Be more strict with types

Make sure getMaxAge() always returns null or int. Also trigger deprecations if wrong types are passed to SetCookie

* fix

* Update baseline

* Require version 2.2
This commit is contained in:
Tobias Nyholm 2021-07-17 15:34:19 -07:00 committed by GitHub
parent a2b8dd1ad7
commit 1482295aa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 2 deletions

View File

@ -32,7 +32,8 @@
"ext-json": "*",
"guzzlehttp/promises": "^1.4",
"guzzlehttp/psr7": "^1.7 || ^2.0",
"psr/http-client": "^1.0"
"psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2"
},
"provide": {
"psr/http-client-implementation": "1.0"

View File

@ -110,3 +110,7 @@ parameters:
count: 2
path: src/Middleware.php
-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/Cookie/SetCookie.php

View File

@ -128,6 +128,10 @@ class SetCookie
*/
public function setName($name): void
{
if (!is_string($name)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['Name'] = $name;
}
@ -148,6 +152,10 @@ class SetCookie
*/
public function setValue($value): void
{
if (!is_string($value)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['Value'] = $value;
}
@ -168,6 +176,10 @@ class SetCookie
*/
public function setDomain($domain): void
{
if (!is_string($domain)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['Domain'] = $domain;
}
@ -188,6 +200,10 @@ class SetCookie
*/
public function setPath($path): void
{
if (!is_string($path)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['Path'] = $path;
}
@ -198,7 +214,7 @@ class SetCookie
*/
public function getMaxAge()
{
return $this->data['Max-Age'];
return null === $this->data['Max-Age'] ? null : (int) $this->data['Max-Age'];
}
/**
@ -208,6 +224,10 @@ class SetCookie
*/
public function setMaxAge($maxAge): void
{
if (!is_int($maxAge)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an int to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['Max-Age'] = $maxAge;
}
@ -228,6 +248,10 @@ class SetCookie
*/
public function setExpires($timestamp): void
{
if (!is_int($timestamp) && !is_string($timestamp)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an int or string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['Expires'] = \is_numeric($timestamp)
? (int) $timestamp
: \strtotime($timestamp);
@ -250,6 +274,10 @@ class SetCookie
*/
public function setSecure($secure): void
{
if (!is_bool($secure)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a boolean to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['Secure'] = $secure;
}
@ -270,6 +298,10 @@ class SetCookie
*/
public function setDiscard($discard): void
{
if (!is_bool($discard)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a boolean to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['Discard'] = $discard;
}
@ -290,6 +322,10 @@ class SetCookie
*/
public function setHttpOnly($httpOnly): void
{
if (!is_bool($httpOnly)) {
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a boolean to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
}
$this->data['HttpOnly'] = $httpOnly;
}