8000 fix review · symfony/symfony@e3577ea · GitHub
[go: up one dir, main page]

Skip to content

Commit e3577ea

Browse files
committed
fix review
1 parent b80a2ae commit e3577ea

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

src/Symfony/Component/HttpFoundation/Cookie.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class Cookie
2323
const SAMESITE_STRICT = 'strict';
2424

2525
protected $name;
26-
protected $value = null;
27-
protected $domain = null;
28-
protected $expire = 0;
29-
protected $path = '/';
30-
protected $secure = null;
31-
protected $httpOnly = true;
26+
protected $value;
27+
protected $domain;
28+
protected $expire;
29+
protected $path;
30+
protected $secure;
31+
protected $httpOnly;
3232

3333
private $raw = false;
3434
private $sameSite;
@@ -92,8 +92,7 @@ public function __construct(string $name, string $value = null, $expire = 0, ?st
9292
{
9393
$this->raw = $raw;
9494

95-
$this->validateName($name);
96-
$this->name = $name;
95+
$this->name = $this->withName($name)->name;
9796
$this->value = $value;
9897
$this->expire = $this->normalizeExpiresTime($expire);
9998
$this->path = $this->normalizePath($path);
@@ -201,7 +200,7 @@ public function getValue()
201200
/**
202201
* Creates a cookie copy with a new value.
203202
*/
204-
public function withValue(string $value = null): self
203+
public function withValue(string $value): self
205204
{
206205
$cookie = clone $this;
207206
$cookie->value = $value;
@@ -222,7 +221,7 @@ public function getDomain()
222221
/**
223222
* Creates a cookie copy with a new domain that the cookie is available to.
224223
*/
225-
public function withDomain(string $domain = null): self
224+
public function withDomain(string $domain): self
226225
{
227226
$cookie = clone $this;
228227
$cookie->domain = $domain;
@@ -247,7 +246,7 @@ public function getExpiresTime()
247246
*
248247
* @throws \InvalidArgumentException
249248
*/
250-
public function withExpiresTime($expire = 0): self
249+
public function withExpires($expire = 0): self
251250
{
252251
$expire = $this->normalizeExpiresTime($expire);
253252

@@ -324,7 +323,7 @@ public function isSecure()
324323
/**
325324
* Creates a cookie copy that only be transmitted over a secure HTTPS connection from the client.
326325
*/
327-
public function withSecure(bool $secure = null): self
326+
public function withSecure(bool $secure = true): self
328327
{
329328
$cookie = clone $this;
330329
$cookie->secure = $secure;
@@ -376,7 +375,7 @@ public function isRaw()
376375
/**
377376
* Creates a cookie copy that uses url encoding.
378377
*/
379-
public function withRaw(bool $raw = false): self
378+
public function withRaw(bool $raw = true): self
380379
{
381380
$cookie = clone $this;
382381
$cookie->raw = $raw;
@@ -399,7 +398,7 @@ public function getSameSite()
399398
*
400399
* @throws \InvalidArgumentException
401400
*/
402-
public function withSameSite(?string $sameSite = 'lax'): self
401+
public function withSameSite(?string $sameSite): self
403402
{
404403
$sameSite = $this->normalizeSameSite($sameSite);
405404

src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function testNegativeExpirationIsNotPossible()
8888

8989
$this->assertSame(0, $cookie->getExpiresTime());
9090

91-
$cookie = Cookie::create('foo', 'bar')->withExpiresTime(-100);
91+
$cookie = Cookie::create('foo', 'bar')->withExpires(-100);
9292

9393
$this->assertSame(0, $cookie->getExpiresTime());
9494
}
@@ -118,7 +118,7 @@ public function testGetExpiresTime()
118118

119119
$this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
120120

121-
$cookie = Cookie::create('foo')->withExpiresTime($expire = time() + 3600);
121+
$cookie = Cookie::create('foo')->withExpires($expire = time() + 3600);
122122

123123
$this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
124124
}
@@ -129,7 +129,7 @@ public function testGetExpiresTimeIsCastToInt()
129129

130130
$this->assertSame(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date as an integer');
131131

132-
$cookie = Cookie::create('foo')->withExpiresTime(3600.6);
132+
$cookie = Cookie::create('foo')->withExpires(3600.6);
133133

134134
$this->assertSame(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date as an integer');
135135
}
@@ -141,7 +141,7 @@ public function testConstructorWithDateTime()
141141

142142
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
143143

144-
$cookie = Cookie::create('foo')->withExpiresTime($expire);
144+
$cookie = Cookie::create('foo')->withExpires($expire);
145145

146146
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
147147
}
@@ -153,7 +153,7 @@ public function testConstructorWithDateTimeImmutable()
153153

154154
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
155155

156-
$cookie = Cookie::create('foo')->withValue('bar')->withExpiresTime($expire);
156+
$cookie = Cookie::create('foo')->withValue('bar')->withExpires($expire);
157157

158158
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
159159
}
@@ -167,7 +167,7 @@ public function testGetExpiresTimeWithStringValue()
167167

168168
$this->assertEqualsWithDelta($expire, $cookie->getExpiresTime(), 1, '->getExpiresTime() returns the expire date');
169169

170-
$cookie = Cookie::create('foo')->withValue('bar')->withExpiresTime($value);
170+
$cookie = Cookie::create('foo')->withValue('bar')->withExpires($value);
171171

172172
$this->assertEqualsWithDelta($expire, $cookie->getExpiresTime(), 1, '->getExpiresTime() returns the expire date');
173173
}
@@ -211,7 +211,7 @@ public function testCookieIsNotCleared()
211211

212212
$this->assertFalse($cookie->isCleared(), '->isCleared() returns false if the cookie did not expire yet');
213213

214-
$cookie = Cookie::create('foo')->withExpiresTime(time() + 3600 * 24);
214+
$cookie = Cookie::create('foo')->withExpires(time() + 3600 * 24);
215215

216216
$this->assertFalse($cookie->isCleared(), '->isCleared() returns false if the cookie did not expire yet');
217217
}
@@ -222,7 +222,7 @@ public function testCookieIsCleared()
222222

223223
$this->assertTrue($cookie->isCleared(), '->isCleared() returns true if the cookie has expired');
224224

225-
$cookie = Cookie::create('foo')->withExpiresTime(time() - 20);
225+
$cookie = Cookie::create('foo')->withExpires(time() - 20);
226226

227227
$this->assertTrue($cookie->isCleared(), '->isCleared() returns true if the cookie has expired');
228228

@@ -238,7 +238,7 @@ public function testCookieIsCleared()
238238

239239
$this->assertFalse($cookie->isCleared());
240240

241-
$cookie = Cookie::create('foo')->withExpiresTime(-1);
241+
$cookie = Cookie::create('foo')->withExpires(-1);
242242

243243
$this->assertFalse($cookie->isCleared());
244244
}
@@ -251,7 +251,7 @@ public function testToString()
251251

252252
$cookie = Cookie::create('foo')
253253
->withValue('bar')
254-
->withExpiresTime(strtotime('Fri, 20-May-2011 15:25:52 GMT'))
254+
->withExpires(strtotime('Fri, 20-May-2011 15:25:52 GMT'))
255255
->withDomain('.myfoodomain.com')
256256
->withSecure(true)
257257
->withSameSite(null);
@@ -263,7 +263,7 @@ public function testToString()
263263

264264
$cookie = Cookie::create('foo')
265265
->withValue('bar with white spaces')
266-
->withExpiresTime(strtotime('Fri, 20-May-2011 15:25:52 GMT'))
266+
->withExpires(strtotime('Fri, 20-May-2011 15:25:52 GMT'))
267267
->withDomain('.myfoodomain.com')
268268
->withSecure(true)
269269
->withSameSite(null);
@@ -274,7 +274,7 @@ public function testToString()
274274
$this->assertEquals($expected, (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');
275275

276276
$cookie = Cookie::create('foo')
277-
->withExpiresTime(1)
277+
->withExpires(1)
278278
->withPath('/admin/')
279279
->withDomain('.myfoodomain.com')
280280
->withSameSite(null);

0 commit comments

Comments
 (0)
0