Skip to content

Commit

Permalink
GH-2588: Do not generalize types for return and PHP version in status
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Mar 9, 2024
1 parent 5f08992 commit 720c32e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function transform(SourceCode $code): Promise
$classBuilder = $builder->class($method->class()->name()->short());
$methodBuilder = $classBuilder->method($method->name());
$replacement = $this->returnType($method);
$localReplacement = $replacement->toLocalType($method->scope())->generalize();
$localReplacement = $replacement->toLocalType($method->scope());
$notNullReplacement = $replacement->stripNullable();

foreach ($replacement->allTypes()->classLike() as $classType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Phpactor\CodeTransform\Tests\Adapter\TolerantParser\TolerantTestCase;
use Phpactor\TextDocument\TextEdits;

abstract class AbstractTolerantImportNameTest extends TolerantTestCase
abstract class AbstractTolerantImportNameCase extends TolerantTestCase
{
/**
* @dataProvider provideImportClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Phpactor\TextDocument\ByteOffset;
use Phpactor\TextDocument\TextEdits;

class TolerantImportNameOnlyTest extends AbstractTolerantImportNameTest
class TolerantImportNameOnlyTest extends AbstractTolerantImportNameCase
{
public function provideImportClass(): Generator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Phpactor\TextDocument\ByteOffset;
use Phpactor\TextDocument\TextEdits;

class TolerantImportNameTest extends AbstractTolerantImportNameTest
class TolerantImportNameTest extends AbstractTolerantImportNameCase
{
public function provideImportClass(): Generator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,74 @@ private function baz(): void
}
EOT
];
yield 'adds false type' => [
<<<'EOT'
<?php
class Foobar {
private function foo()
{
return $this->baz();
}
private function baz(): string|false
{
}
}
EOT
,
<<<'EOT'
<?php
class Foobar {
private function foo(): string|false
{
return $this->baz();
}
private function baz(): string|false
{
}
}
EOT
];
yield 'adds array shape type' => [
<<<'EOT'
<?php
class Foobar {
private function foo()
{
return $this->baz();
}
/**
* @return array{string,string}
*/
private function baz(): array
{
}
}
EOT
,
<<<'EOT'
<?php
class Foobar {
private function foo(): array
{
return $this->baz();
}
/**
* @return array{string,string}
*/
private function baz(): array
{
}
}
EOT
];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Extension/Php/Model/ConstantPhpVersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public function resolve(): ?string

public function name(): string
{
return 'constant (user configured)';
return 'user configured';
}
}
7 changes: 4 additions & 3 deletions lib/Extension/Php/Status/PhpStatusProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Phpactor\Extension\LanguageServer\Status\StatusProvider;
use Phpactor\Extension\Php\Model\ChainResolver;
use Phpactor\Extension\Php\Model\RuntimePhpVersionResolver;

class PhpStatusProvider implements StatusProvider
{
public function __construct(
private ChainResolver $chainResolver,
)
{
) {
}

public function title(): string
Expand All @@ -21,8 +21,9 @@ public function title(): string
public function provide(): array
{
return [
'version' => $this->chainResolver->resolve(),
'project' => $this->chainResolver->resolve(),
'source' => $this->chainResolver->source(),
'runtime' => phpversion(),
];
}
}
6 changes: 3 additions & 3 deletions lib/WorseReflection/Tests/Inference/type/false.test
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Foo;

wrAssertType('string|false', possiblyFalse());

function possiblyFalse(array $foo): string|false
{
}

wrAssertType('string|false', possiblyFalse());


/**
* @return string|false a formatted date string. If a non-numeric value is used for
*/
Expand Down

0 comments on commit 720c32e

Please sign in to comment.