Skip to content

Commit

Permalink
Merge pull request #8465 from kkmuffme/invalid-class-casing-for-nativ…
Browse files Browse the repository at this point in the history
…e-and-stubbed-classes

report invalidCasing when using a class that is not user defined too
  • Loading branch information
orklah committed Sep 8, 2022
2 parents 18f285f + d0984f4 commit 6374a96
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/Psalm/Config.php
Expand Up @@ -6,7 +6,7 @@
use Composer\Semver\Constraint\Constraint;
use Composer\Semver\VersionParser;
use DOMDocument;
use DomElement;
use DOMElement;
use InvalidArgumentException;
use LogicException;
use OutOfBoundsException;
Expand Down Expand Up @@ -752,7 +752,6 @@ private static function validateXmlConfig(string $base_dir, string $file_content

$psalm_nodes = $dom_document->getElementsByTagName('psalm');

/** @var DomElement|null */
$psalm_node = $psalm_nodes->item(0);

if (!$psalm_node) {
Expand Down
18 changes: 8 additions & 10 deletions src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
Expand Up @@ -361,16 +361,14 @@ public static function checkFullyQualifiedClassLikeName(
|| ($interface_exists && !$codebase->interfaceHasCorrectCasing($fq_class_name))
|| ($enum_exists && !$codebase->classlikes->enumHasCorrectCasing($fq_class_name))
) {
if ($codebase->classlikes->isUserDefined(strtolower($aliased_name))) {
IssueBuffer::maybeAdd(
new InvalidClass(
'Class, interface or enum ' . $fq_class_name . ' has wrong casing',
$code_location,
$fq_class_name
),
$suppressed_issues
);
}
IssueBuffer::maybeAdd(
new InvalidClass(
'Class, interface or enum ' . $fq_class_name . ' has wrong casing',
$code_location,
$fq_class_name
),
$suppressed_issues
);
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/Psalm/Internal/Codebase/ClassLikes.php
Expand Up @@ -784,14 +784,6 @@ public function traitHasCorrectCase(string $fq_trait_name): bool
return isset($this->existing_traits[$fq_trait_name]);
}

/**
* @param lowercase-string $fq_class_name
*/
public function isUserDefined(string $fq_class_name): bool
{
return $this->classlike_storage_provider->get($fq_class_name)->user_defined;
}

public function getTraitNode(string $fq_trait_name): PhpParser\Node\Stmt\Trait_
{
$fq_trait_name_lc = strtolower($fq_trait_name);
Expand Down
10 changes: 5 additions & 5 deletions src/Psalm/Internal/PluginManager/ConfigFile.php
Expand Up @@ -3,7 +3,7 @@
namespace Psalm\Internal\PluginManager;

use DOMDocument;
use DomElement;
use DOMElement;
use Psalm\Config;
use RuntimeException;

Expand Down Expand Up @@ -51,15 +51,15 @@ public function getConfig(): Config
public function removePlugin(string $plugin_class): void
{
$config_xml = $this->readXml();
/** @var DomElement */
/** @var DOMElement */
$psalm_root = $config_xml->getElementsByTagName('psalm')[0];
$plugins_elements = $psalm_root->getElementsByTagName('plugins');
if (!$plugins_elements->length) {
// no plugins, nothing to remove
return;
}

/** @var DomElement */
/** @var DOMElement */
$plugins_element = $plugins_elements->item(0);

$plugin_elements = $plugins_element->getElementsByTagName('pluginClass');
Expand All @@ -82,7 +82,7 @@ public function removePlugin(string $plugin_class): void
public function addPlugin(string $plugin_class): void
{
$config_xml = $this->readXml();
/** @var DomElement */
/** @var DOMElement */
$psalm_root = $config_xml->getElementsByTagName('psalm')->item(0);
$plugins_elements = $psalm_root->getElementsByTagName('plugins');
if (!$plugins_elements->length) {
Expand All @@ -91,7 +91,7 @@ public function addPlugin(string $plugin_class): void
$psalm_root->appendChild($plugins_element);
}
} else {
/** @var DomElement */
/** @var DOMElement */
$plugins_element = $plugins_elements->item(0);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/IntRangeTest.php
Expand Up @@ -687,7 +687,7 @@ function doAnalysis(): void
/** @var string $secret */
$length = strlen($secret);
if ($length > 16) {
throw new exception("");
throw new Exception("");
}
assert($length === 1);
Expand Down
2 changes: 1 addition & 1 deletion tests/MethodCallTest.php
Expand Up @@ -979,7 +979,7 @@ public static function new() : self {
class Datetime extends \DateTime
{
public static function createFromInterface(\DatetimeInterface $datetime): \DateTime
public static function createFromInterface(\DateTimeInterface $datetime): \DateTime
{
return parent::createFromInterface($datetime);
}
Expand Down

0 comments on commit 6374a96

Please sign in to comment.