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

Add property typehints in Internal directory #8897

Merged
merged 9 commits into from Dec 15, 2022
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -41,6 +41,39 @@ jobs:

- run: |
git ls-files | grep \\\.php$ | grep -v ^dictionaries/scripts/* | ./vendor/bin/parallel-lint --stdin
php-cs-fixer:
name: php-cs-fixer
runs-on: ubuntu-latest
steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:v2
coverage: none

- uses: actions/checkout@v3

- name: Get Composer Cache Directories
id: composer-cache
run: |
echo "::set-output name=files_cache::$(composer config cache-files-dir)"
echo "::set-output name=vcs_cache::$(composer config cache-vcs-dir)"
- name: Cache composer cache
uses: actions/cache@v3
with:
path: |
${{ steps.composer-cache.outputs.files_cache }}
${{ steps.composer-cache.outputs.vcs_cache }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Run composer install
run: composer install -o
env:
COMPOSER_ROOT_VERSION: dev-master

- run: vendor/bin/php-cs-fixer fix --diff --verbose --dry-run
chunk-matrix:
permissions:
contents: none
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,6 +10,7 @@
/vendor-bin/*/composer.lock
/vendor-bin/*/vendor/
/tests/fixtures/symlinktest/*
/.php-cs-fixer.cache

.idea/
.vscode/
Expand Down
20 changes: 20 additions & 0 deletions .php-cs-fixer.dist.php
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use Symfony\Component\Finder\Finder;

$finder = (new Finder())
->files()
->name('/\.php$/')
->in(__DIR__ . '/src');

return (new PhpCsFixer\Config())
->setFinder($finder)
->setRiskyAllowed(true)
// https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/rules/index.rst
->setRules([
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_empty_phpdoc' => true,
'phpdoc_trim' => true,
jack-worman marked this conversation as resolved.
Show resolved Hide resolved
]);
5 changes: 5 additions & 0 deletions composer.json
Expand Up @@ -46,6 +46,7 @@
"ext-curl": "*",
"bamarni/composer-bin-plugin": "^1.4",
"brianium/paratest": "^6.0",
"friendsofphp/php-cs-fixer": "^3.13",
"mockery/mockery": "^1.5",
"nunomaduro/mock-final-classes": "^1.1",
"php-parallel-lint/php-parallel-lint": "^1.2",
Expand Down Expand Up @@ -108,6 +109,8 @@
"scripts": {
"cs": "phpcs -p",
"cs-fix": "phpcbf -p",
"php-cs-fixer-dry-run": "vendor/bin/php-cs-fixer fix --diff --verbose --dry-run",
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff --verbose",
"lint": "parallel-lint ./src ./tests",
"phpunit": "paratest --runner=WrapperRunner",
"phpunit-std": "phpunit",
Expand All @@ -123,6 +126,8 @@
"scripts-descriptions": {
"cs": "Checks that the code conforms to the coding standard.",
"cs-fix": "Automatically correct coding standard violations.",
"php-cs-fixer-dry-run": "Checks that the code conforms to the coding standard.",
"php-cs-fixer": "Automatically correct coding standard violations.",
"lint": "Runs unit tests.",
"phpunit": "Runs unit tests in parallel.",
"phpunit-std": "Runs unit tests.",
Expand Down
14 changes: 0 additions & 14 deletions src/Psalm/Codebase.php
Expand Up @@ -389,7 +389,6 @@ private function loadAnalyzer(): void

/**
* @param array<string> $candidate_files
*
*/
public function reloadFiles(ProjectAnalyzer $project_analyzer, array $candidate_files): void
{
Expand Down Expand Up @@ -465,7 +464,6 @@ public function collectLocations(): void

/**
* @param 'always'|'auto' $find_unused_code
*
*/
public function reportUnusedCode(string $find_unused_code = 'auto'): void
{
Expand All @@ -483,7 +481,6 @@ public function reportUnusedVariables(): void

/**
* @param array<string, string> $files_to_analyze
*
*/
public function addFilesToAnalyze(array $files_to_analyze): void
{
Expand All @@ -493,7 +490,6 @@ public function addFilesToAnalyze(array $files_to_analyze): void

/**
* Scans all files their related files
*
*/
public function scanFiles(int $threads = 1): void
{
Expand Down Expand Up @@ -848,7 +844,6 @@ public function getMethodParams($method_id): array

/**
* @param string|MethodIdentifier $method_id
*
*/
public function isVariadic($method_id): bool
{
Expand All @@ -858,7 +853,6 @@ public function isVariadic($method_id): bool
/**
* @param string|MethodIdentifier $method_id
* @param list<Arg> $call_args
*
*/
public function getMethodReturnType($method_id, ?string &$self_class, array $call_args = []): ?Union
{
Expand All @@ -872,7 +866,6 @@ public function getMethodReturnType($method_id, ?string &$self_class, array $cal

/**
* @param string|MethodIdentifier $method_id
*
*/
public function getMethodReturnsByRef($method_id): bool
{
Expand All @@ -881,8 +874,6 @@ public function getMethodReturnsByRef($method_id): bool

/**
* @param string|MethodIdentifier $method_id
* @param CodeLocation|null $defined_location
*
*/
public function getMethodReturnTypeLocation(
$method_id,
Expand All @@ -896,7 +887,6 @@ public function getMethodReturnTypeLocation(

/**
* @param string|MethodIdentifier $method_id
*
*/
public function getDeclaringMethodId($method_id): ?string
{
Expand All @@ -909,7 +899,6 @@ public function getDeclaringMethodId($method_id): ?string
* Get the class this method appears in (vs is declared in, which could give a trait)
*
* @param string|MethodIdentifier $method_id
*
*/
public function getAppearingMethodId($method_id): ?string
{
Expand All @@ -930,7 +919,6 @@ public function getOverriddenMethodIds($method_id): array

/**
* @param string|MethodIdentifier $method_id
*
*/
public function getCasedMethodId($method_id): string
{
Expand Down Expand Up @@ -986,8 +974,6 @@ public function getFunctionStorageForSymbol(string $file_path, string $symbol):
}

/**
* @param string $file_path
* @param string $symbol
* @return array{ type: string, description?: string|null}|null
*/
public function getSymbolInformation(string $file_path, string $symbol): ?array
Expand Down
3 changes: 0 additions & 3 deletions src/Psalm/Config.php
Expand Up @@ -647,7 +647,6 @@ protected function __construct()
* Searches up a folder hierarchy for the most immediate config.
*
* @throws ConfigException if a config path is not found
*
*/
public static function getConfigForPath(string $path, string $current_dir): Config
{
Expand All @@ -664,7 +663,6 @@ public static function getConfigForPath(string $path, string $current_dir): Conf
* Searches up a folder hierarchy for the most immediate config.
*
* @throws ConfigException
*
*/
public static function locateConfigFile(string $path): ?string
{
Expand Down Expand Up @@ -1361,7 +1359,6 @@ public function setCustomErrorLevel(string $issue_key, string $error_level): voi

/**
* @throws ConfigException if a Config file could not be found
*
*/
private function loadFileExtensions(SimpleXMLElement $extensions): void
{
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Context.php
Expand Up @@ -439,7 +439,6 @@ public function __destruct()
* @param bool $has_leaving_statements whether or not the parent scope is abandoned between
* $start_context and $end_context
* @param array<string, bool> $updated_vars
*
*/
public function update(
Context $start_context,
Expand Down
2 changes: 0 additions & 2 deletions src/Psalm/ErrorBaseline.php
Expand Up @@ -58,7 +58,6 @@ public static function countTotalIssues(array $existingIssues): int

/**
* @param array<string, list<IssueData>> $issues
*
*/
public static function create(
FileProvider $fileProvider,
Expand Down Expand Up @@ -237,7 +236,6 @@ static function (array $carry, IssueData $issue): array {

/**
* @param array<string,array<string,array{o:int, s:array<int, string>}>> $groupedIssues
*
*/
private static function writeToFile(
FileProvider $fileProvider,
Expand Down
12 changes: 6 additions & 6 deletions src/Psalm/Internal/Analyzer/CanAlias.php
Expand Up @@ -16,32 +16,32 @@ trait CanAlias
/**
* @var array<lowercase-string, string>
*/
private $aliased_classes = [];
private array $aliased_classes = [];
jack-worman marked this conversation as resolved.
Show resolved Hide resolved

/**
* @var array<lowercase-string, CodeLocation>
*/
private $aliased_class_locations = [];
private array $aliased_class_locations = [];

/**
* @var array<lowercase-string, string>
*/
private $aliased_classes_flipped = [];
private array $aliased_classes_flipped = [];

/**
* @var array<lowercase-string, string>
*/
private $aliased_classes_flipped_replaceable = [];
private array $aliased_classes_flipped_replaceable = [];

/**
* @var array<lowercase-string, non-empty-string>
*/
private $aliased_functions = [];
private array $aliased_functions = [];

/**
* @var array<string, string>
*/
private $aliased_constants = [];
private array $aliased_constants = [];

public function visitUse(PhpParser\Node\Stmt\Use_ $stmt): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Expand Up @@ -109,7 +109,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
/**
* @var array<string, Union>
*/
public $inferred_property_types = [];
public array $inferred_property_types = [];

/**
* @param PhpParser\Node\Stmt\Class_|PhpParser\Node\Stmt\Enum_ $class
Expand Down Expand Up @@ -517,7 +517,7 @@ public function analyze(
)
);
}

$const_id = strtolower($this->fq_class_name) . '::' . $const->name;

foreach ($codebase->class_constants_to_rename as $original_const_id => $new_const_name) {
Expand Down
25 changes: 6 additions & 19 deletions src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
Expand Up @@ -81,33 +81,23 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer
'unknown type' => true,
];

/**
* @var PhpParser\Node\Stmt\ClassLike
*/
protected $class;
protected PhpParser\Node\Stmt\ClassLike $class;

/** @var FileAnalyzer */
public $file_analyzer;
public FileAnalyzer $file_analyzer;

/**
* @var string
*/
protected $fq_class_name;
protected string $fq_class_name;

/**
* The parent class
*
* @var string|null
*/
protected $parent_fq_class_name;
protected ?string $parent_fq_class_name = null;

/**
* @var PhpParser\Node\Stmt[]
*/
protected $leftover_stmts = [];
protected array $leftover_stmts = [];

/** @var ClassLikeStorage */
protected $storage;
protected ClassLikeStorage $storage;

public function __construct(PhpParser\Node\Stmt\ClassLike $class, SourceAnalyzer $source, string $fq_class_name)
{
Expand Down Expand Up @@ -404,8 +394,6 @@ public static function checkFullyQualifiedClassLikeName(

/**
* Gets the fully-qualified class name from a Name object
*
*
*/
public static function getFQCLNFromNameObject(
PhpParser\Node\Name $class_name,
Expand Down Expand Up @@ -495,7 +483,6 @@ public function isStatic(): bool
* Gets the Psalm type from a particular value
*
* @param mixed $value
*
*/
public static function getTypeFromValue($value): Union
{
Expand Down
18 changes: 6 additions & 12 deletions src/Psalm/Internal/Analyzer/ClassLikeNameOptions.php
Expand Up @@ -7,23 +7,17 @@
*/
class ClassLikeNameOptions
{
/** @var bool */
public $inferred;
public bool $inferred;

/** @var bool */
public $allow_trait;
public bool $allow_trait;

/** @var bool */
public $allow_interface;
public bool $allow_interface;

/** @var bool */
public $allow_enum;
public bool $allow_enum;

/** @var bool */
public $from_docblock;
public bool $from_docblock;

/** @var bool */
public $from_attribute;
public bool $from_attribute;

public function __construct(
bool $inferred = false,
Expand Down