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

report invalidCasing when using a class that is not user defined too #8465

Merged
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
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