2016-06-10 00:08:25 +02:00
|
|
|
<?php
|
2016-07-26 00:37:44 +02:00
|
|
|
namespace Psalm\Issue;
|
2016-06-10 00:08:25 +02:00
|
|
|
|
2016-12-04 01:11:30 +01:00
|
|
|
use Psalm\CodeLocation;
|
|
|
|
|
2016-06-10 00:08:25 +02:00
|
|
|
abstract class CodeIssue
|
|
|
|
{
|
|
|
|
const CODE_EXCEPTION = 1;
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2016-12-04 01:11:30 +01:00
|
|
|
* @var CodeLocation
|
2016-11-02 07:29:00 +01:00
|
|
|
*/
|
2016-12-04 01:11:30 +01:00
|
|
|
protected $code_location;
|
2016-11-01 05:39:41 +01:00
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-06-10 00:08:25 +02:00
|
|
|
protected $message;
|
|
|
|
|
2016-11-01 05:39:41 +01:00
|
|
|
/**
|
2016-12-04 01:11:30 +01:00
|
|
|
* @param string $message
|
|
|
|
* @param CodeLocation $code_location
|
2016-11-01 05:39:41 +01:00
|
|
|
*/
|
2016-12-04 01:11:30 +01:00
|
|
|
public function __construct($message, CodeLocation $code_location)
|
2016-06-10 00:08:25 +02:00
|
|
|
{
|
2016-12-04 01:11:30 +01:00
|
|
|
$this->code_location = $code_location;
|
2016-06-10 00:08:25 +02:00
|
|
|
$this->message = $message;
|
|
|
|
}
|
|
|
|
|
2016-12-04 01:11:30 +01:00
|
|
|
/**
|
2016-12-08 04:38:57 +01:00
|
|
|
* @return CodeLocation
|
2016-12-04 01:11:30 +01:00
|
|
|
*/
|
2016-12-08 04:38:57 +01:00
|
|
|
public function getLocation()
|
2016-12-04 01:11:30 +01:00
|
|
|
{
|
2016-12-08 04:38:57 +01:00
|
|
|
return $this->code_location;
|
2016-12-04 01:11:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-08 04:38:57 +01:00
|
|
|
public function getShortLocation()
|
2016-12-04 01:11:30 +01:00
|
|
|
{
|
2017-06-21 20:22:52 +02:00
|
|
|
$previous_text = '';
|
|
|
|
|
|
|
|
if ($this->code_location->previous_location) {
|
|
|
|
$previous_location = $this->code_location->previous_location;
|
|
|
|
$previous_text = ' from ' . $previous_location->file_name . ':' . $previous_location->getLineNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->code_location->file_name . ':' . $this->code_location->getLineNumber() . $previous_text;
|
2016-06-10 00:08:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-08 04:38:57 +01:00
|
|
|
public function getFilePath()
|
2016-06-10 00:08:25 +02:00
|
|
|
{
|
2016-12-08 04:38:57 +01:00
|
|
|
return $this->code_location->file_path;
|
2016-06-10 00:08:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-08 04:38:57 +01:00
|
|
|
public function getFileName()
|
2016-06-10 00:08:25 +02:00
|
|
|
{
|
2016-12-08 04:38:57 +01:00
|
|
|
return $this->code_location->file_name;
|
2016-12-04 01:11:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-08 04:38:57 +01:00
|
|
|
public function getMessage()
|
2016-12-04 01:11:30 +01:00
|
|
|
{
|
2016-12-08 04:38:57 +01:00
|
|
|
return $this->message;
|
2016-06-10 00:08:25 +02:00
|
|
|
}
|
|
|
|
}
|