Skip to content

Commit 3062413

Browse files
committed
Update HttpSetCookieTrait.php
1 parent f48552e commit 3062413

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/Traits/HttpSetCookieTrait.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
namespace Evas\Http\Traits;
88

9-
use \InvalidArgumentException;
109
use Evas\Base\Help\PhpHelp;
1110
use Evas\Http\Cookie;
1211
use Evas\Http\Traits\HttpCookiesTrait;
@@ -23,15 +22,15 @@ trait HttpSetCookieTrait
2322

2423
/**
2524
* Установка нового свойства cookie.
26-
* @param string|Cookie имя свойства или объект Сookie
27-
* @param mixed|null значение
25+
* @param string|Cookie имя cookie или объект Сookie
26+
* @param mixed|null значение cookie
2827
* @param int|null время жизни cookie
2928
* @param string|null путь
3029
* @param string|null хост
3130
* @param bool|null защищенное ли соединение
3231
* @param bool|null поддержка только http
3332
* @return self
34-
* @throws InvalidArgumentException
33+
* @throws \InvalidArgumentException
3534
*/
3635
public function setCookie($name, $value = null, int $expires = null, string $path = null, string $host = null, bool $secure = null, bool $httpOnly = null): object
3736
{
@@ -41,9 +40,9 @@ public function setCookie($name, $value = null, int $expires = null, string $pat
4140
} else if ($name instanceof Cookie) {
4241
$cookie = $name;
4342
} else {
44-
throw new InvalidArgumentException(sprintf(
45-
'Argument 1 $name must be type of string or instance of Cookie, %s given',
46-
PhpHelp::getType($name)
43+
throw new \InvalidArgumentException(sprintf(
44+
'Argument 1 passed to %s() must be string or instance of %s, %s given',
45+
__METHOD__, Cookie::class, PhpHelp::getType($name)
4746
));
4847
}
4948
$this->withCookie($cookie->name, $cookie);
@@ -52,18 +51,24 @@ public function setCookie($name, $value = null, int $expires = null, string $pat
5251

5352
/**
5453
* Запуск сборки свойства cookie.
55-
* @param string имя свойства
56-
* @param callable|array колбэек или массив данных свойства
54+
* @param string имя cookie
55+
* @param callable|array колбэек или массив свойств cookie
5756
* @return Cookie
57+
* @throws \InvalidArgumentException
5858
*/
5959
public function buildCookie(string $name, $props = null): Cookie
6060
{
6161
if (is_callable($props)) {
6262
$cookie = new Cookie($name);
6363
$props = $props->bindTo($cookie);
6464
$props();
65-
} else {
65+
} else if (PhpHelp::isAssoc($props)) {
6666
$cookie = new Cookie($name, $props);
67+
} else {
68+
throw new \InvalidArgumentException(sprintf(
69+
'Argument 2 passed to %s() must be array or closure, %s given',
70+
__METHOD__, PhpHelp::getType($props)
71+
));
6772
}
6873
$this->setCookie($cookie);
6974
return $cookie;

0 commit comments

Comments
 (0)