1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Make all mixed issues implement MixedIssue

This commit is contained in:
Matt Brown 2021-03-20 21:44:04 -04:00
parent d1740394aa
commit 7f8d522912
22 changed files with 144 additions and 45 deletions

View File

@ -116,10 +116,10 @@ abstract class CodeIssue
$this instanceof TaintedInput
? $this->getTaintTrace()
: null,
$this instanceof MixedAssignment && $this->origin_location
$this instanceof MixedIssue && ($origin_location = $this->getOriginalLocation())
? [
TaintedInput::nodeToDataFlowNodeData(
$this->origin_location,
$origin_location,
'The type of ' . $location->getSelectedText() . ' is sourced from here',
''
)

View File

@ -1,8 +1,24 @@
<?php
namespace Psalm\Issue;
class MixedArgument extends ArgumentIssue
use Psalm\CodeLocation;
class MixedArgument extends ArgumentIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 30;
use MixedIssueTrait;
public function __construct(
string $message,
CodeLocation $code_location,
?string $function_id = null,
?CodeLocation $origin_location = null
) {
$this->code_location = $code_location;
$this->message = $message;
$this->function_id = $function_id ? strtolower($function_id) : null;
$this->origin_location = $origin_location;
}
}

View File

@ -1,8 +1,24 @@
<?php
namespace Psalm\Issue;
class MixedArgumentTypeCoercion extends ArgumentIssue
use Psalm\CodeLocation;
class MixedArgumentTypeCoercion extends ArgumentIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 194;
use MixedIssueTrait;
public function __construct(
string $message,
CodeLocation $code_location,
?string $function_id = null,
?CodeLocation $origin_location = null
) {
$this->code_location = $code_location;
$this->message = $message;
$this->function_id = $function_id ? strtolower($function_id) : null;
$this->origin_location = $origin_location;
}
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedArrayAccess extends CodeIssue
class MixedArrayAccess extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 51;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedArrayAssignment extends CodeIssue
class MixedArrayAssignment extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 117;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedArrayOffset extends CodeIssue
class MixedArrayOffset extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 31;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedArrayTypeCoercion extends CodeIssue
class MixedArrayTypeCoercion extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 195;
use MixedIssueTrait;
}

View File

@ -3,32 +3,10 @@ namespace Psalm\Issue;
use Psalm\CodeLocation;
class MixedAssignment extends CodeIssue
class MixedAssignment extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 32;
/**
* @var ?CodeLocation
* @readonly
*/
public $origin_location;
public function __construct(
string $message,
CodeLocation $code_location,
?CodeLocation $origin_location = null
) {
$this->code_location = $code_location;
$this->message = $message;
$this->origin_location = $origin_location;
}
public function getMessage() : string
{
return $this->message
. ($this->origin_location
? ', derived from expression at ' . $this->origin_location->getShortSummary()
: '');
}
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedClone extends CodeIssue
class MixedClone extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 227;
use MixedIssueTrait;
}

View File

@ -2,8 +2,10 @@
namespace Psalm\Issue;
class MixedFunctionCall extends CodeIssue
class MixedFunctionCall extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 185;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedInferredReturnType extends CodeIssue
class MixedInferredReturnType extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 47;
use MixedIssueTrait;
}

View File

@ -0,0 +1,11 @@
<?php
namespace Psalm\Issue;
use Psalm\CodeLocation;
interface MixedIssue
{
public function getMixedOriginMessage() : string;
public function getOriginalLocation() : ?CodeLocation;
}

View File

@ -0,0 +1,36 @@
<?php
namespace Psalm\Issue;
use Psalm\CodeLocation;
trait MixedIssueTrait
{
/**
* @var ?CodeLocation
* @readonly
*/
public $origin_location;
public function __construct(
string $message,
CodeLocation $code_location,
?CodeLocation $origin_location = null
) {
$this->code_location = $code_location;
$this->message = $message;
$this->origin_location = $origin_location;
}
public function getMixedOriginMessage() : string
{
return $this->message
. ($this->origin_location
? '. Consider improving the type at ' . $this->origin_location->getShortSummary()
: '');
}
public function getOriginalLocation() : ?CodeLocation
{
return $this->origin_location;
}
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedMethodCall extends CodeIssue
class MixedMethodCall extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 15;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedOperand extends CodeIssue
class MixedOperand extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 59;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedPropertyAssignment extends CodeIssue
class MixedPropertyAssignment extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 33;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedPropertyFetch extends CodeIssue
class MixedPropertyFetch extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 34;
use MixedIssueTrait;
}

View File

@ -1,8 +1,22 @@
<?php
namespace Psalm\Issue;
class MixedPropertyTypeCoercion extends PropertyIssue
use Psalm\CodeLocation;
class MixedPropertyTypeCoercion extends PropertyIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 196;
use MixedIssueTrait;
public function __construct(
string $message,
\Psalm\CodeLocation $code_location,
string $property_id,
?CodeLocation $origin_location = null
) {
parent::__construct($message, $code_location, $property_id);
$this->origin_location = $origin_location;
}
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedReturnStatement extends CodeIssue
class MixedReturnStatement extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 138;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedReturnTypeCoercion extends CodeIssue
class MixedReturnTypeCoercion extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 197;
use MixedIssueTrait;
}

View File

@ -1,8 +1,10 @@
<?php
namespace Psalm\Issue;
class MixedStringOffsetAssignment extends CodeIssue
class MixedStringOffsetAssignment extends CodeIssue implements MixedIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 35;
use MixedIssueTrait;
}

View File

@ -254,8 +254,8 @@ class IssueBuffer
$message = $e instanceof \Psalm\Issue\TaintedInput
? $e->getJourneyMessage()
: ($e instanceof \Psalm\Issue\MixedAssignment
? $e->getMessage()
: ($e instanceof \Psalm\Issue\MixedIssue
? $e->getMixedOriginMessage()
: $e->message);
throw new Exception\CodeException(