Skip to content

Commit

Permalink
Merge pull request #7285 from weirdan/drop-html-escaped-string
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Jan 3, 2022
2 parents c1acab4 + f09814a commit c2c3247
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 96 deletions.
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

0 comments on commit c2c3247

Please sign in to comment.