Skip to content

Commit 5ece935

Browse files
committed
fix it for interfaces too
1 parent 51e5828 commit 5ece935

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

src/Psalm/Internal/Codebase/Populator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,12 @@ private function populateInterfaceData(
603603
);
604604
$new_parent_interface_storage = $storage_provider->get($new_parent);
605605
} catch (InvalidArgumentException) {
606+
$this->progress->debug('Populator could not find dependency (' . __LINE__ . ")\n");
607+
608+
$storage->invalid_dependencies[$new_parent] = true;
609+
610+
$this->invalid_class_storages[$new_parent][] = $storage;
611+
606612
continue;
607613
}
608614

@@ -686,6 +692,9 @@ private function populateInterfaceDataFromParentInterface(
686692
$this->progress->debug('Populator could not find dependency (' . __LINE__ . ")\n");
687693

688694
$storage->invalid_dependencies[$parent_interface_lc] = true;
695+
696+
$this->invalid_class_storages[$parent_interface_lc][] = $storage;
697+
689698
return;
690699
}
691700

@@ -729,6 +738,9 @@ private function populateDataFromImplementedInterface(
729738
$this->progress->debug('Populator could not find dependency (' . __LINE__ . ")\n");
730739

731740
$storage->invalid_dependencies[$implemented_interface_lc] = true;
741+
742+
$this->invalid_class_storages[$implemented_interface_lc][] = $storage;
743+
732744
return;
733745
}
734746

tests/StubTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,49 @@ public function run(): float {
12021202
$this->analyzeFile($file_path, new Context());
12031203
}
12041204

1205+
public function testUseOnlyStubbedInterface(): void
1206+
{
1207+
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
1208+
TestConfig::loadFromXML(
1209+
dirname(__DIR__),
1210+
'<?xml version="1.0"?>
1211+
<psalm
1212+
errorLevel="1"
1213+
>
1214+
<projectFiles>
1215+
<directory name="src" />
1216+
</projectFiles>
1217+
1218+
<stubs>
1219+
<file name="tests/fixtures/stubs/interface.phpstub" />
1220+
</stubs>
1221+
</psalm>',
1222+
),
1223+
);
1224+
1225+
$file_path = (string) getcwd() . '/src/somefile.php';
1226+
1227+
$this->addFile(
1228+
$file_path,
1229+
'<?php
1230+
namespace Foo;
1231+
1232+
class A implements StubbedInterface {
1233+
/**
1234+
* @param int $x
1235+
*/
1236+
public function run_stubbed($x): float {
1237+
return $x . "";
1238+
}
1239+
}',
1240+
);
1241+
1242+
$this->expectExceptionMessage('InvalidReturnType');
1243+
$this->expectException(CodeException::class);
1244+
1245+
$this->analyzeFile($file_path, new Context());
1246+
}
1247+
12051248
public function testStubFileWithExtendedStubbedClass(): void
12061249
{
12071250
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace Foo;
3+
4+
interface StubbedInterface
5+
{
6+
/**
7+
* @param int $x
8+
*/
9+
public function run_stubbed($x): float;
10+
}

0 commit comments

Comments
 (0)