Skip to content

Commit

Permalink
Merge pull request #9920 from robchett/CoreGenericAttributes
Browse files Browse the repository at this point in the history
Add a stub file for Attributes defined by PHP
  • Loading branch information
orklah committed Jun 17, 2023
2 parents c2c5b25 + 4600d2b commit b515951
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
23 changes: 11 additions & 12 deletions src/Psalm/Config.php
Expand Up @@ -2226,28 +2226,27 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null):
$codebase->register_stub_files = true;

$dir_lvl_2 = dirname(__DIR__, 2);
$stubsDir = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR;
$this->internal_stubs = [
$dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreGenericFunctions.phpstub',
$dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreGenericClasses.phpstub',
$dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreGenericIterators.phpstub',
$dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreImmutableClasses.phpstub',
$dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Reflection.phpstub',
$dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'SPL.phpstub',
$stubsDir . 'CoreGenericFunctions.phpstub',
$stubsDir . 'CoreGenericClasses.phpstub',
$stubsDir . 'CoreGenericIterators.phpstub',
$stubsDir . 'CoreImmutableClasses.phpstub',
$stubsDir . 'Reflection.phpstub',
$stubsDir . 'SPL.phpstub',
];

if ($codebase->analysis_php_version_id >= 8_00_00) {
$stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Php80.phpstub';
$this->internal_stubs[] = $stringable_path;
$this->internal_stubs[] = $stubsDir . 'CoreGenericAttributes.phpstub';
$this->internal_stubs[] = $stubsDir . 'Php80.phpstub';
}

if ($codebase->analysis_php_version_id >= 8_01_00) {
$stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Php81.phpstub';
$this->internal_stubs[] = $stringable_path;
$this->internal_stubs[] = $stubsDir . 'Php81.phpstub';
}

if ($codebase->analysis_php_version_id >= 8_02_00) {
$stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Php82.phpstub';
$this->internal_stubs[] = $stringable_path;
$this->internal_stubs[] = $stubsDir . 'Php82.phpstub';
$this->php_extensions['random'] = true; // random is a part of the PHP core starting from PHP 8.2
}

Expand Down
13 changes: 13 additions & 0 deletions stubs/CoreGenericAttributes.phpstub
@@ -0,0 +1,13 @@
<?php

#[Attribute(Attribute::TARGET_CLASS)]
final class AllowDynamicProperties
{
public function __construct() {}
}

#[Attribute(Attribute::TARGET_PARAMETER)]
final class SensitiveParameter
{
public function __construct() {}
}
12 changes: 0 additions & 12 deletions stubs/Php82.phpstub
Expand Up @@ -34,18 +34,6 @@ namespace {
public function getIterator(): Iterator {}
}

#[Attribute(Attribute::TARGET_PARAMETER)]
final class SensitiveParameter
{
public function __construct() {}
}

#[Attribute(Attribute::TARGET_CLASS)]
final class AllowDynamicProperties
{
public function __construct() {}
}

/**
* @psalm-pure
* @param positive-int $length
Expand Down

0 comments on commit b515951

Please sign in to comment.