Skip to content

Commit f3d037f

Browse files
committed
Fix DateTime::format('u') return type II
1 parent a2c0946 commit f3d037f

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/Type/Php/DateFunctionReturnTypeHelper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ 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(), new AccessoryNumericStringType()])
79+
? new IntersectionType([new StringType(), new AccessoryNumericStringType()])
8080
: new ConstantStringType('000000');
8181
case 'v':
8282
return $useMicrosec
83-
? new IntersectionType([new StringType(), new AccessoryNonFalsyStringType(), new AccessoryNumericStringType()])
83+
? new IntersectionType([new StringType(), new AccessoryNumericStringType()])
8484
: new ConstantStringType('000');
8585
}
8686

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
use function PHPStan\Testing\assertType;
66

77
/**
8-
* @param non-falsy-string&numeric-string $str
8+
* @param numeric-string $str
99
*/
1010
function hasMicroseconds(\DateTimeInterface $value, string $str): bool
1111
{
12-
assertType('non-falsy-string&numeric-string', $str);
12+
assertType('numeric-string', $str);
1313
assertType('int', (int)$str);
1414
assertType('bool', (int)$str !== 0);
1515

16-
assertType('non-falsy-string&numeric-string', $value->format('u'));
16+
assertType('numeric-string', $value->format('u'));
1717
assertType('int', (int)$value->format('u'));
1818
assertType('bool', (int)$value->format('u') !== 0);
1919

20-
assertType('non-falsy-string&numeric-string', $value->format('v'));
20+
assertType('numeric-string', $value->format('v'));
2121
assertType('int', (int)$value->format('v'));
2222
assertType('bool', (int)$value->format('v') !== 0);
2323

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

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

77
function (\DateTime $dt) {
88
assertType("'000000'", date('u'));
9-
assertType('non-falsy-string&numeric-string', date_format($dt, 'u'));
10-
assertType('non-falsy-string&numeric-string', $dt->format('u'));
9+
assertType('numeric-string', date_format($dt, 'u'));
10+
assertType('numeric-string', $dt->format('u'));
1111

1212
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'));
13+
assertType('numeric-string', date_format($dt, 'v'));
14+
assertType('numeric-string', $dt->format('v'));
1515
};

0 commit comments

Comments
 (0)