mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Dropped THtmlEscapedString
This commit is contained in:
parent
c1acab4606
commit
afa6497051
@ -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`
|
||||
|
@ -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).
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
@ -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_) {
|
||||
@ -46,7 +46,6 @@ class EchoChecker implements AfterStatementAnalysisInterface
|
||||
foreach ($types as $type) {
|
||||
if ($type instanceof TString
|
||||
&& !$type instanceof TLiteralString
|
||||
&& !$type instanceof THtmlEscapedString
|
||||
) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ArgumentTypeCoercion(
|
||||
|
@ -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>
|
||||
|
@ -16,7 +16,6 @@ use Psalm\Type\Atomic\TDependentGetType;
|
||||
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;
|
||||
@ -536,8 +535,7 @@ class ScalarTypeComparator
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -551,8 +549,7 @@ class ScalarTypeComparator
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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,
|
||||
|
@ -32,7 +32,6 @@ use Psalm\Type\Atomic\TEmptyScalar;
|
||||
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;
|
||||
@ -269,9 +268,6 @@ abstract class Atomic implements TypeNode
|
||||
case 'numeric-string':
|
||||
return new TNumericString();
|
||||
|
||||
case 'html-escaped-string':
|
||||
return new THtmlEscapedString();
|
||||
|
||||
case 'literal-string':
|
||||
return new TNonspecificLiteralString();
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Psalm\Type\Atomic;
|
||||
|
||||
/**
|
||||
* Special type, specifically for consumption by plugins.
|
||||
* @deprecated going to be removed in Psalm 5. Use taints instead.
|
||||
*/
|
||||
class THtmlEscapedString extends TString
|
||||
{
|
||||
public function getKey(bool $include_extra = true): string
|
||||
{
|
||||
return 'html-escaped-string';
|
||||
}
|
||||
|
||||
public function getId(bool $nested = false): string
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@ -293,55 +293,6 @@ class PluginTest extends TestCase
|
||||
$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';
|
||||
|
Loading…
Reference in New Issue
Block a user