Skip to content

Commit

Permalink
Merge pull request #6536 from orklah/cleanup2
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
orklah committed Sep 26, 2021
2 parents afbda6d + ab6efe4 commit b29737f
Show file tree
Hide file tree
Showing 148 changed files with 369 additions and 695 deletions.
8 changes: 4 additions & 4 deletions src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Codebase
/**
* @var null|'always'|'auto'
*/
public $find_unused_code = null;
public $find_unused_code;

/**
* @var FileProvider
Expand Down Expand Up @@ -179,7 +179,7 @@ class Codebase
/**
* @var ?Internal\Codebase\TaintFlowGraph
*/
public $taint_flow_graph = null;
public $taint_flow_graph;

/**
* @var bool
Expand Down Expand Up @@ -614,7 +614,7 @@ public function addGlobalConstantType(string $const_id, Type\Union $type): void

public function getStubbedConstantType(string $const_id): ?Type\Union
{
return isset(self::$stubbed_constants[$const_id]) ? self::$stubbed_constants[$const_id] : null;
return self::$stubbed_constants[$const_id] ?? null;
}

/**
Expand Down Expand Up @@ -1614,7 +1614,7 @@ public function getCompletionItemsForPartialSymbol(
$insertion_text = Type::getStringFromFQCLN(
$fq_class_name,
$aliases && $aliases->namespace ? $aliases->namespace : null,
$aliases ? $aliases->uses_flipped : [],
$aliases->uses_flipped ?? [],
null
);

Expand Down
18 changes: 6 additions & 12 deletions src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
use function glob;
use function implode;
use function in_array;
use function intval;
use function is_a;
use function is_dir;
use function is_file;
Expand All @@ -80,7 +79,6 @@
use function strpos;
use function strrpos;
use function strtolower;
use function strtr;
use function substr;
use function substr_count;
use function sys_get_temp_dir;
Expand Down Expand Up @@ -182,7 +180,7 @@ class Config
*
* @var bool|null
*/
public $load_xdebug_stub = null;
public $load_xdebug_stub;

/**
* The directory to store PHP Parser (and other) caches
Expand Down Expand Up @@ -288,7 +286,7 @@ class Config
/**
* @var ?bool
*/
public $show_mixed_issues = null;
public $show_mixed_issues;

/** @var bool */
public $strict_binary_operands = false;
Expand Down Expand Up @@ -501,7 +499,7 @@ class Config
public $hash = '';

/** @var string|null */
public $error_baseline = null;
public $error_baseline;

/**
* @var bool
Expand Down Expand Up @@ -978,7 +976,7 @@ private static function fromXmlAndPaths(
}

if (isset($config_xml['maxStringLength'])) {
$attribute_text = intval($config_xml['maxStringLength']);
$attribute_text = (int)$config_xml['maxStringLength'];
$config->max_string_length = $attribute_text;
}

Expand Down Expand Up @@ -2115,7 +2113,7 @@ public function getPotentialComposerFilePathForClassLike(string $class): ?string
$psr4_prefixes = $this->composer_class_loader->getPrefixesPsr4();

// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php';
$logicalPathPsr4 = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';

$candidate_path = null;

Expand Down Expand Up @@ -2200,11 +2198,7 @@ public function addPreloadedStubFile(string $stub_file): void

public function getPhpVersion(): ?string
{
if (isset($this->configured_php_version)) {
return $this->configured_php_version;
}

return $this->getPHPVersionFromComposerJson();
return $this->configured_php_version ?? $this->getPHPVersionFromComposerJson();
}

private function setBooleanAttribute(string $name, bool $value): void
Expand Down
4 changes: 1 addition & 3 deletions src/Psalm/Config/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ public static function getContents(
);
}

$template = str_replace(
return str_replace(
'errorLevel="1"',
'errorLevel="' . $level . '"',
$template
);

return $template;
}

public static function createBareConfig(
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Config/ProjectFileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProjectFileFilter extends FileFilter
/**
* @var ProjectFileFilter|null
*/
private $file_filter = null;
private $file_filter;

/**
* @return static
Expand Down
16 changes: 8 additions & 8 deletions src/Psalm/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Context
/**
* @var null|CodeLocation
*/
public $include_location = null;
public $include_location;

/**
* @var string|null
Expand Down Expand Up @@ -194,7 +194,7 @@ class Context
*
* @var array<string, bool>|null
*/
public $initialized_methods = null;
public $initialized_methods;

/**
* @var array<string, Type\Union>
Expand Down Expand Up @@ -290,27 +290,27 @@ class Context
/**
* @var Internal\Scope\LoopScope|null
*/
public $loop_scope = null;
public $loop_scope;

/**
* @var Internal\Scope\CaseScope|null
*/
public $case_scope = null;
public $case_scope;

/**
* @var Internal\Scope\FinallyScope|null
*/
public $finally_scope = null;
public $finally_scope;

/**
* @var Context|null
*/
public $if_context = null;
public $if_context;

/**
* @var \Psalm\Internal\Scope\IfScope|null
*/
public $if_scope = null;
public $if_scope;

/**
* @var bool
Expand Down Expand Up @@ -418,7 +418,7 @@ public function update(
? $end_context->vars_in_scope[$var_id]
: null;

$existing_type = isset($this->vars_in_scope[$var_id]) ? $this->vars_in_scope[$var_id] : null;
$existing_type = $this->vars_in_scope[$var_id] ?? null;

if (!$existing_type) {
if ($new_type) {
Expand Down
5 changes: 3 additions & 2 deletions src/Psalm/DocComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function str_repeat;
use function str_replace;
use function strlen;
use function strpos;
use function strspn;
use function substr;
use function trim;
Expand Down Expand Up @@ -156,7 +157,7 @@ public static function parse(string $docblock, ?int $line_number = null, bool $p
$docblock = preg_replace('/^\s*\n/', '', $docblock);

foreach ($special as $special_key => $_) {
if (substr($special_key, 0, 6) === 'psalm-') {
if (strpos($special_key, 'psalm-') === 0) {
$special_key = substr($special_key, 6);

if (!in_array(
Expand Down Expand Up @@ -186,7 +187,7 @@ public static function parsePreservingLength(\PhpParser\Comment\Doc $docblock) :
);

foreach ($parsed_docblock->tags as $special_key => $_) {
if (substr($special_key, 0, 6) === 'psalm-') {
if (strpos($special_key, 'psalm-') === 0) {
$special_key = substr($special_key, 6);

if (!in_array(
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/FileManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function transform(string $existing_contents) : string
$indentation = substr($existing_contents, $newline_pos, $this->start - $newline_pos);

if (trim($indentation) === '') {
$this->insertion_text = $this->insertion_text . $indentation;
$this->insertion_text .= $indentation;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/CanAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function visitUse(PhpParser\Node\Stmt\Use_ $stmt): void

foreach ($stmt->uses as $use) {
$use_path = implode('\\', $use->name->parts);
$use_alias = $use->alias ? $use->alias->name : $use->name->getLast();
$use_alias = $use->alias->name ?? $use->name->getLast();

switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $stmt->type) {
case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION:
Expand Down Expand Up @@ -107,7 +107,7 @@ public function visitGroupUse(PhpParser\Node\Stmt\GroupUse $stmt): void

foreach ($stmt->uses as $use) {
$use_path = $use_prefix . '\\' . implode('\\', $use->name->parts);
$use_alias = $use->alias ? $use->alias->name : $use->name->getLast();
$use_alias = $use->alias->name ?? $use->name->getLast();

switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $stmt->type) {
case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION:
Expand Down
14 changes: 6 additions & 8 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function analyze(
$this->fq_class_name . ', defined abstract in ' . $declaring_class_name,
new CodeLocation(
$this,
$class->name ? $class->name : $class,
$class->name ?? $class,
$class_context->include_location,
true
)
Expand Down Expand Up @@ -984,7 +984,7 @@ private function checkPropertyInitialization(
return;
}

$fq_class_name = $class_context->self ? $class_context->self : $this->fq_class_name;
$fq_class_name = $class_context->self ?: $this->fq_class_name;
$fq_class_name_lc = strtolower($fq_class_name);

$included_file_path = $this->getFilePath();
Expand Down Expand Up @@ -1913,9 +1913,7 @@ public static function analyzeClassMethodReturnType(
);
}

$overridden_method_ids = isset($class_storage->overridden_method_ids[strtolower($stmt->name->name)])
? $class_storage->overridden_method_ids[strtolower($stmt->name->name)]
: [];
$overridden_method_ids = $class_storage->overridden_method_ids[strtolower($stmt->name->name)] ?? [];

if (!$return_type
&& !$class_storage->is_interface
Expand Down Expand Up @@ -2276,7 +2274,7 @@ private function checkImplementedInterfaces(

$code_location = new CodeLocation(
$this,
$class->name ? $class->name : $class,
$class->name ?? $class,
$class_context->include_location,
true
);
Expand Down Expand Up @@ -2488,7 +2486,7 @@ private function checkParentClass(
$code_location = new CodeLocation(
$this,
$extended_class,
$class_context ? $class_context->include_location : null,
$class_context->include_location ?? null,
true
);

Expand Down Expand Up @@ -2592,7 +2590,7 @@ private function checkParentClass(
$code_location = new CodeLocation(
$this,
$class->name ?: $class,
$class_context ? $class_context->include_location : null,
$class_context->include_location ?? null,
true
);

Expand Down
25 changes: 10 additions & 15 deletions src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public function getFQCLN(): string

public function getClassName(): ?string
{
return $this->class->name ? $this->class->name->name : null;
return $this->class->name->name ?? null;
}

/**
Expand Down Expand Up @@ -580,22 +580,17 @@ public static function checkPropertyVisibility(
return $emit_issues ? null : true;

case self::VISIBILITY_PRIVATE:
if (!$context->self || $appearing_property_class !== $context->self) {
if ($emit_issues && IssueBuffer::accepts(
new InaccessibleProperty(
'Cannot access private property ' . $property_id . ' from context ' . $context->self,
$code_location
),
$suppressed_issues
)) {
// fall through
}

return null;
if ($emit_issues && IssueBuffer::accepts(
new InaccessibleProperty(
'Cannot access private property ' . $property_id . ' from context ' . $context->self,
$code_location
),
$suppressed_issues
)) {
// fall through
}

return $emit_issues ? null : true;

return null;
case self::VISIBILITY_PROTECTED:
if (!$context->self) {
if ($emit_issues && IssueBuffer::accepts(
Expand Down

0 comments on commit b29737f

Please sign in to comment.