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

Dropped THtmlEscapedString #7285

Merged
merged 2 commits into from Jan 3, 2022
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
4 changes: 3 additions & 1 deletion UPGRADING.md
Expand Up @@ -36,7 +36,6 @@
- `Psalm\Type\Atomic\TEnumCase`
- `Psalm\Type\Atomic\TFalse`
- `Psalm\Type\Atomic\TGenericObject`
- `Psalm\Type\Atomic\THtmlEscapedString`
- `Psalm\Type\Atomic\TIntMask`
- `Psalm\Type\Atomic\TIntMaskOf`
- `Psalm\Type\Atomic\TIntRange`
Expand Down Expand Up @@ -156,3 +155,6 @@
- [BC] Method `Psalm\Issue\CodeIssue::getFileName()` was removed
- [BC] Method `Psalm\Issue\CodeIssue::getMessage()` was removed
- [BC] Method `Psalm\DocComment::parse()` was removed
- [BC] Class `Psalm\Type\Atomic\THtmlEscapedString` has been removed


2 changes: 1 addition & 1 deletion docs/running_psalm/plugins/plugins_type_system.md
Expand Up @@ -139,7 +139,7 @@ if (true === $first) {

`TCallableString` - denotes the `callable-string` type, used to represent an unknown string that is also `callable`.

`THtmlEscapedString`, `TSqlSelectString` - these are special types, specifically for consumption by plugins.
`TSqlSelectString` - this is a special type, specifically for consumption by plugins.

`TLowercaseString` - denotes a string where every character is lowercased. (which can also result from a `strtolower` call).

Expand Down
11 changes: 5 additions & 6 deletions examples/plugins/composer-based/echo-checker/EchoChecker.php
@@ -1,16 +1,15 @@
<?php

namespace Psalm\Example\Plugin\ComposerBased;

use PhpParser;
use Psalm\CodeLocation;
use Psalm\FileManipulation;
use Psalm\IssueBuffer;
use Psalm\Issue\ArgumentTypeCoercion;
use Psalm\IssueBuffer;
use Psalm\Plugin\EventHandler\AfterStatementAnalysisInterface;
use Psalm\Plugin\EventHandler\Event\AfterStatementAnalysisEvent;
use Psalm\Type\Atomic\TString;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\THtmlEscapedString;
use Psalm\Type\Atomic\TString;

class EchoChecker implements AfterStatementAnalysisInterface
{
Expand All @@ -19,7 +18,8 @@ class EchoChecker implements AfterStatementAnalysisInterface
*
* @return null|false
*/
public static function afterStatementAnalysis(AfterStatementAnalysisEvent $event): ?bool {
public static function afterStatementAnalysis(AfterStatementAnalysisEvent $event): ?bool
{
$stmt = $event->getStmt();
$statements_source = $event->getStatementsSource();
if ($stmt instanceof PhpParser\Node\Stmt\Echo_) {
Expand All @@ -46,7 +46,6 @@ public static function afterStatementAnalysis(AfterStatementAnalysisEvent $event
foreach ($types as $type) {
if ($type instanceof TString
&& !$type instanceof TLiteralString
&& !$type instanceof THtmlEscapedString
) {
if (IssueBuffer::accepts(
new ArgumentTypeCoercion(
Expand Down
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Expand Up @@ -353,9 +353,6 @@
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Type/Atomic.php">
<DeprecatedClass occurrences="2">
<code>new THtmlEscapedString()</code>
</DeprecatedClass>
<PossiblyUndefinedIntArrayOffset occurrences="1">
<code>array_keys($template_type_map[$value])[0]</code>
</PossiblyUndefinedIntArrayOffset>
Expand Down
7 changes: 2 additions & 5 deletions src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php
Expand Up @@ -16,7 +16,6 @@
use Psalm\Type\Atomic\TDependentListKey;
use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TFloat;
use Psalm\Type\Atomic\THtmlEscapedString;
use Psalm\Type\Atomic\TInt;
use Psalm\Type\Atomic\TIntRange;
use Psalm\Type\Atomic\TLiteralClassString;
Expand Down Expand Up @@ -536,8 +535,7 @@ public static function isContainedBy(
}

if ($container_type_part instanceof TString
&& ($input_type_part instanceof TNumericString
|| $input_type_part instanceof THtmlEscapedString)
&& $input_type_part instanceof TNumericString
) {
if ($container_type_part instanceof TLiteralString) {
if (is_numeric($container_type_part->value) && $atomic_comparison_result) {
Expand All @@ -551,8 +549,7 @@ public static function isContainedBy(
}

if ($input_type_part instanceof TString
&& ($container_type_part instanceof TNumericString
|| $container_type_part instanceof THtmlEscapedString)
&& $container_type_part instanceof TNumericString
) {
if ($input_type_part instanceof TLiteralString) {
return is_numeric($input_type_part->value);
Expand Down
3 changes: 1 addition & 2 deletions src/Psalm/Internal/Type/TypeTokenizer.php
Expand Up @@ -54,8 +54,7 @@ class TypeTokenizer
'stringable-object' => true,
'pure-callable' => true,
'pure-Closure' => true,
'mysql-escaped-string' => true, // deprecated
'html-escaped-string' => true, // deprecated
'mysql-escaped-string' => true, // deprecated, should be removed in Psalm 5
'literal-string' => true,
'non-empty-literal-string' => true,
'lowercase-string' => true,
Expand Down
4 changes: 0 additions & 4 deletions src/Psalm/Type/Atomic.php
Expand Up @@ -32,7 +32,6 @@
use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TFloat;
use Psalm\Type\Atomic\TGenericObject;
use Psalm\Type\Atomic\THtmlEscapedString;
use Psalm\Type\Atomic\TInt;
use Psalm\Type\Atomic\TIntRange;
use Psalm\Type\Atomic\TIterable;
Expand Down Expand Up @@ -269,9 +268,6 @@ public static function create(
case 'numeric-string':
return new TNumericString();

case 'html-escaped-string':
return new THtmlEscapedString();

case 'literal-string':
return new TNonspecificLiteralString();

Expand Down
25 changes: 0 additions & 25 deletions src/Psalm/Type/Atomic/THtmlEscapedString.php

This file was deleted.

49 changes: 0 additions & 49 deletions tests/Config/PluginTest.php
Expand Up @@ -293,55 +293,6 @@ public function testEchoAnalyzerPluginWithUnescapedString(): void
$this->analyzeFile($file_path, new Context());
}

public function testEchoAnalyzerPluginWithEscapedString(): void
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
TestConfig::loadFromXML(
dirname(__DIR__, 2) . DIRECTORY_SEPARATOR,
'<?xml version="1.0"?>
<psalm
errorLevel="1"
>
<projectFiles>
<directory name="src" />
</projectFiles>
<plugins>
<plugin filename="examples/plugins/composer-based/echo-checker/EchoChecker.php" />
</plugins>
<issueHandlers>
<UndefinedGlobalVariable errorLevel="suppress" />
<MixedArgument errorLevel="suppress" />
</issueHandlers>
</psalm>'
)
);

$this->project_analyzer->getCodebase()->config->initializePlugins($this->project_analyzer);

$file_path = getcwd() . '/src/somefile.php';

$this->addFile(
$file_path,
'<?php
/**
* @param mixed $s
* @return html-escaped-string
*/
function escapeHtml($s) : string {
if (!is_scalar($s)) {
throw new \UnexpectedValueException("bad value passed to escape");
}
/** @var html-escaped-string */
return htmlentities((string) $s);
}
?>
Some text
<?= escapeHtml($unsafe) ?>'
);

$this->analyzeFile($file_path, new Context());
}

public function testFileAnalyzerPlugin(): void
{
require_once __DIR__ . '/Plugin/FilePlugin.php';
Expand Down