Skip to content

Commit 6696f45

Browse files
authored
allow numeric-strings beeing returned for non-empty-string
1 parent 2b0ba44 commit 6696f45

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/Type/Accessory/AccessoryNumericStringType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public function isSubTypeOf(Type $otherType): TrinaryLogic
7878

7979
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
8080
{
81+
if ($acceptingType->isNonEmptyString()->yes()) {
82+
return TrinaryLogic::createYes();
83+
}
84+
8185
return $this->isSubTypeOf($acceptingType);
8286
}
8387

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,4 +695,9 @@ public function testConditionalTypes(): void
695695
]);
696696
}
697697

698+
public function testBug7265(): void
699+
{
700+
$this->analyse([__DIR__ . '/data/bug-7265.php'], []);
701+
}
702+
698703
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Bug7265;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param literal-string $assetPath e.g. css/cmsfasttrack.css or js/fasttrack.js
9+
* @return non-empty-string
10+
*/
11+
static public function assetId(string $assetPath)
12+
{
13+
if (strpos($assetPath, 'css/') !== 0 && strpos($assetPath, 'js/') !== 0 && strpos($assetPath, 'img/') !== 0) {
14+
throw new \RuntimeException('Invalid asset path "' . $assetPath . '"');
15+
}
16+
17+
$mtime = filemtime($assetPath);
18+
19+
if ($mtime === false) {
20+
throw new \RuntimeException('Unable to get filemtime for asset path "' . $assetPath . '"');
21+
}
22+
23+
return (string)$mtime;
24+
}
25+
}

0 commit comments

Comments
 (0)