Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove support for allowPhpstormGenerics #6705

Merged
merged 2 commits into from Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions config.xsd
Expand Up @@ -51,14 +51,6 @@
</xs:attribute>

<xs:attribute name="allowFileIncludes" type="xs:boolean" default="true" />
<xs:attribute name="allowPhpStormGenerics" type="xs:boolean" default="false">
<xs:annotation>
<!-- note: for PHPStorm to mark the attribute as deprecated the doc entry has to be *single line* and start with the word `deprecated` -->
<xs:documentation xml:lang="en">
Deprecated. PHPStorm now supports generics for the most part and @psalm- annotations can be used
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="allowStringToStandInForClass" type="xs:boolean" default="false" />
<xs:attribute name="checkForThrowsDocblock" type="xs:boolean" default="false" />
<xs:attribute name="checkForThrowsInGlobalScope" type="xs:boolean" default="false" />
Expand Down
11 changes: 0 additions & 11 deletions docs/running_psalm/configuration.md
Expand Up @@ -134,17 +134,6 @@ If true we force strict typing on numerical and string operations (see https://g
```
Setting this to `false` means that any function calls will cause Psalm to forget anything it knew about object properties within the scope of the function it's currently analysing. This duplicates functionality that Hack has. Defaults to `true`.

#### allowPhpStormGenerics

```xml
<psalm
allowPhpStormGenerics="[bool]"
>
```
Allows you to specify whether or not to use the typed iterator docblock format supported by PHP Storm e.g. `ArrayIterator|string[]`, which Psalm transforms to `ArrayIterator<string>`. Defaults to `false`.

This flag is deprecated and will be removed in Psalm 5

#### allowStringToStandInForClass

```xml
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Codebase.php
Expand Up @@ -384,7 +384,6 @@ public function __construct(
);

$this->populator = new Populator(
$config,
$providers->classlike_storage_provider,
$providers->file_storage_provider,
$this->classlikes,
Expand Down
6 changes: 0 additions & 6 deletions src/Psalm/Config.php
Expand Up @@ -315,11 +315,6 @@ class Config
/** @var bool */
public $use_igbinary = false;

/**
* @var bool
*/
public $allow_phpstorm_generics = false;

/**
* @var bool
*/
Expand Down Expand Up @@ -887,7 +882,6 @@ private static function fromXmlAndPaths(
'allowFileIncludes' => 'allow_includes',
'strictBinaryOperands' => 'strict_binary_operands',
'rememberPropertyAssignmentsAfterCall' => 'remember_property_assignments_after_call',
'allowPhpStormGenerics' => 'allow_phpstorm_generics',
'allowStringToStandInForClass' => 'allow_string_standin_for_class',
'usePhpDocMethodsWithoutMagicCall' => 'use_phpdoc_method_without_magic_or_parent',
'usePhpDocPropertiesWithoutMagicCall' => 'use_phpdoc_property_without_magic_or_parent',
Expand Down
108 changes: 0 additions & 108 deletions src/Psalm/Internal/Codebase/Populator.php
Expand Up @@ -3,7 +3,6 @@
namespace Psalm\Internal\Codebase;

use InvalidArgumentException;
use Psalm\Config;
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
use Psalm\Internal\MethodIdentifier;
use Psalm\Internal\Provider\ClassLikeStorageProvider;
Expand All @@ -14,11 +13,6 @@
use Psalm\Progress\Progress;
use Psalm\Storage\ClassLikeStorage;
use Psalm\Storage\FileStorage;
use Psalm\Type;
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TGenericObject;
use Psalm\Type\Atomic\TIterable;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Union;

Expand Down Expand Up @@ -65,18 +59,12 @@ class Populator
*/
private $classlikes;

/**
* @var Config
*/
private $config;

/**
* @var FileReferenceProvider
*/
private $file_reference_provider;

public function __construct(
Config $config,
ClassLikeStorageProvider $classlike_storage_provider,
FileStorageProvider $file_storage_provider,
ClassLikes $classlikes,
Expand All @@ -87,7 +75,6 @@ public function __construct(
$this->file_storage_provider = $file_storage_provider;
$this->classlikes = $classlikes;
$this->progress = $progress;
$this->config = $config;
$this->file_reference_provider = $file_reference_provider;
}

Expand All @@ -110,26 +97,6 @@ public function populateCodebase(): void
}

foreach ($this->classlike_storage_provider->getNew() as $class_storage) {
if ($this->config->allow_phpstorm_generics) {
foreach ($class_storage->properties as $property_storage) {
if ($property_storage->type) {
$this->convertPhpStormGenericToPsalmGeneric($property_storage->type, true);
}
}

foreach ($class_storage->methods as $method_storage) {
if ($method_storage->return_type) {
$this->convertPhpStormGenericToPsalmGeneric($method_storage->return_type);
}

foreach ($method_storage->params as $param_storage) {
if ($param_storage->type) {
$this->convertPhpStormGenericToPsalmGeneric($param_storage->type);
}
}
}
}

foreach ($class_storage->dependent_classlikes as $dependent_classlike_lc => $_) {
try {
$dependee_storage = $this->classlike_storage_provider->get($dependent_classlike_lc);
Expand All @@ -141,22 +108,6 @@ public function populateCodebase(): void
}
}

if ($this->config->allow_phpstorm_generics) {
foreach ($all_file_storage as $file_storage) {
foreach ($file_storage->functions as $function_storage) {
if ($function_storage->return_type) {
$this->convertPhpStormGenericToPsalmGeneric($function_storage->return_type);
}

foreach ($function_storage->params as $param_storage) {
if ($param_storage->type) {
$this->convertPhpStormGenericToPsalmGeneric($param_storage->type);
}
}
}
}
}

$this->progress->debug('FileStorage is populated' . "\n");

ClassLikeStorageProvider::populated();
Expand Down Expand Up @@ -991,65 +942,6 @@ private function populateFileStorage(FileStorage $storage, array $dependent_file
$storage->populated = true;
}

private function convertPhpStormGenericToPsalmGeneric(Union $candidate, bool $is_property = false): void
{
if (!$candidate->from_docblock) {
//never convert a type that comes from a signature
return;
}

$atomic_types = $candidate->getAtomicTypes();

if (isset($atomic_types['array']) && count($atomic_types) > 1 && !isset($atomic_types['null'])) {
$iterator_name = null;
$generic_params = null;
$iterator_key = null;

try {
foreach ($atomic_types as $type_key => $type) {
if ($type instanceof TIterable
|| ($type instanceof TNamedObject
&& (!$type->from_docblock || $is_property)
&& (
strtolower($type->value) === 'traversable'
|| $this->classlikes->interfaceExtends(
$type->value,
'Traversable'
)
|| $this->classlikes->classImplements(
$type->value,
'Traversable'
)
))
) {
$iterator_name = $type->value;
$iterator_key = $type_key;
} elseif ($type instanceof TArray) {
$generic_params = $type->type_params;
}
}
} catch (InvalidArgumentException $e) {
// ignore class-not-found issues
}

if ($iterator_name && $iterator_key && $generic_params) {
if ($iterator_name === 'iterable') {
$generic_iterator = new TIterable($generic_params);
} else {
if (strtolower($iterator_name) === 'generator') {
$generic_params[] = Type::getMixed();
$generic_params[] = Type::getMixed();
}
$generic_iterator = new TGenericObject($iterator_name, $generic_params);
}

$candidate->removeType('array');
$candidate->removeType($iterator_key);
$candidate->addType($generic_iterator);
}
}
}

protected function inheritMethodsFromParent(
ClassLikeStorage $storage,
ClassLikeStorage $parent_storage
Expand Down
3 changes: 1 addition & 2 deletions src/Psalm/Internal/Type/TypeCombiner.php
Expand Up @@ -180,8 +180,7 @@ public static function combine(
&& (isset($combination->named_object_types['Traversable'])
|| isset($combination->builtin_type_params['Traversable']))
&& (
($codebase && $codebase->config->allow_phpstorm_generics)
|| isset($combination->builtin_type_params['Traversable'])
isset($combination->builtin_type_params['Traversable'])
|| (isset($combination->named_object_types['Traversable'])
&& $combination->named_object_types['Traversable']->from_docblock)
)
Expand Down