Skip to content

Commit b28ab38

Browse files
authored
Merge branch refs/heads/1.12.x into 2.1.x
2 parents c6159ef + 50ef61e commit b28ab38

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/Type/Php/DateFunctionReturnTypeHelper.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ public function buildReturnTypeFromFormat(string $formatString, bool $useMicrose
7676
return $this->buildNumericRangeType(0, 1, false);
7777
case 'u':
7878
return $useMicrosec
79-
? new IntersectionType([new StringType(), new AccessoryNonFalsyStringType()])
79+
? new IntersectionType([new StringType(), new AccessoryNonFalsyStringType(), new AccessoryNumericStringType()])
8080
: new ConstantStringType('000000');
81+
case 'v':
82+
return $useMicrosec
83+
? new IntersectionType([new StringType(), new AccessoryNonFalsyStringType(), new AccessoryNumericStringType()])
84+
: new ConstantStringType('000');
8185
}
8286

8387
$date = date($formatString);

tests/PHPStan/Analyser/nsrt/bug-10893.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@
55
use function PHPStan\Testing\assertType;
66

77
/**
8-
* @param non-falsy-string $nonfalsy
8+
* @param non-falsy-string&numeric-string $str
99
*/
10-
function hasMicroseconds(\DateTimeInterface $value, string $nonfalsy): bool
10+
function hasMicroseconds(\DateTimeInterface $value, string $str): bool
1111
{
12-
assertType('non-falsy-string', $value->format('u'));
12+
assertType('non-falsy-string&numeric-string', $str);
13+
assertType('int', (int)$str);
14+
assertType('bool', (int)$str !== 0);
15+
16+
assertType('non-falsy-string&numeric-string', $value->format('u'));
1317
assertType('int', (int)$value->format('u'));
1418
assertType('bool', (int)$value->format('u') !== 0);
15-
assertType('non-falsy-string', $nonfalsy);
16-
assertType('int', (int)$nonfalsy);
17-
assertType('bool', (int)$nonfalsy !== 0);
19+
20+
assertType('non-falsy-string&numeric-string', $value->format('v'));
21+
assertType('int', (int)$value->format('v'));
22+
assertType('bool', (int)$value->format('v') !== 0);
23+
24+
assertType('float', $value->format('u') * 1e-6);
25+
assertType('float', $value->format('v') * 1e-3);
1826

1927
return (int) $value->format('u') !== 0;
2028
}

tests/PHPStan/Analyser/nsrt/bug-6613.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
function (\DateTime $dt) {
88
assertType("'000000'", date('u'));
9-
assertType('non-falsy-string', date_format($dt, 'u'));
10-
assertType('non-falsy-string', $dt->format('u'));
9+
assertType('non-falsy-string&numeric-string', date_format($dt, 'u'));
10+
assertType('non-falsy-string&numeric-string', $dt->format('u'));
11+
12+
assertType("'000'", date('v'));
13+
assertType('non-falsy-string&numeric-string', date_format($dt, 'v'));
14+
assertType('non-falsy-string&numeric-string', $dt->format('v'));
1115
};

0 commit comments

Comments
 (0)