Skip to content

Commit 3143833

Browse files
committed
Support for Stringable (PHP 8)
1 parent 38fe693 commit 3143833

5 files changed

Lines changed: 76 additions & 8 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nette/utils": "^3.1.3",
2424
"nikic/php-parser": "4.10.2",
2525
"ondram/ci-detector": "^3.4.0",
26-
"ondrejmirtes/better-reflection": "4.3.39",
26+
"ondrejmirtes/better-reflection": "4.3.40",
2727
"phpdocumentor/reflection-docblock": "4.3.4",
2828
"phpstan/php-8-stubs": "^0.1.6",
2929
"phpstan/phpdoc-parser": "^0.4.9",

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DependencyInjection/ContainerFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Broker\Broker;
88
use PHPStan\Command\CommandHelper;
99
use PHPStan\File\FileHelper;
10+
use PHPStan\Php\PhpVersion;
1011
use Roave\BetterReflection\BetterReflection;
1112
use Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber;
1213
use function sys_get_temp_dir;
@@ -101,6 +102,8 @@ public function create(
101102

102103
$container = $configurator->createContainer();
103104

105+
BetterReflection::$phpVersion = $container->getByType(PhpVersion::class)->getVersionId();
106+
104107
// @phpstan-ignore-next-line
105108
BetterReflection::populate(
106109
$container->getService('betterReflectionSourceLocator'),

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,4 +1502,16 @@ public function testBug3683(): void
15021502
]);
15031503
}
15041504

1505+
public function testStringable(): void
1506+
{
1507+
if (PHP_VERSION_ID < 80000) {
1508+
$this->markTestSkipped('Test requires PHP 8.0.');
1509+
}
1510+
1511+
$this->checkThisOnly = false;
1512+
$this->checkNullables = true;
1513+
$this->checkUnionTypes = true;
1514+
$this->analyse([__DIR__ . '/data/stringable.php'], []);
1515+
}
1516+
15051517
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace TestStringables;
4+
5+
use Stringable;
6+
7+
class Foo
8+
{
9+
10+
public function __toString(): string
11+
{
12+
return 'foo';
13+
}
14+
15+
}
16+
17+
class Bar implements Stringable
18+
{
19+
20+
public function __toString(): string
21+
{
22+
return 'foo';
23+
}
24+
25+
}
26+
27+
interface Lorem extends Stringable
28+
{
29+
30+
}
31+
32+
class Baz
33+
{
34+
35+
public function doFoo(Stringable $s): void
36+
{
37+
38+
}
39+
40+
public function doBar(Lorem $l): void
41+
{
42+
$this->doFoo(new Foo());
43+
$this->doFoo(new Bar());
44+
$this->doFoo($l);
45+
$this->doBaz($l);
46+
}
47+
48+
public function doBaz(string $s): void
49+
{
50+
51+
}
52+
53+
}

0 commit comments

Comments
 (0)