Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
42.86% covered (danger)
42.86%
3 / 7
CRAP
80.00% covered (warning)
80.00%
16 / 20
ParseWarning
0.00% covered (danger)
0.00%
0 / 1
42.86% covered (danger)
42.86%
3 / 7
10.80
80.00% covered (warning)
80.00%
16 / 20
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 getMessage
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getExpectedTokens
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getActualToken
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getStart
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getMessageParams
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 toArray
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
9 / 9
<?php
namespace CirrusSearch\Parser\AST;
/**
 * A warning that occurred during the parse process.
 */
class ParseWarning {
    /**
     * @var string
     */
    private $message;
    /**
     * @var string[]
     */
    private $expectedTokens;
    /**
     * @var string
     */
    private $actualToken;
    /**
     * @var int
     */
    private $start;
    /**
     * @var string[]
     */
    private $messageParams;
    /**
     * @param string $message
     * @param int $start
     * @param string[] $expectedTokens
     * @param string|null $actualToken
     * @param mixed[] $messageParams
     */
    public function __construct( $message, $start, array $expectedTokens = [], $actualToken = null, array $messageParams = [] ) {
        $this->message = $message;
        $this->expectedTokens = $expectedTokens;
        $this->actualToken = $actualToken;
        $this->start = $start;
        $this->messageParams = $messageParams;
    }
    /**
     * message code
     * @return string
     */
    public function getMessage() {
        return $this->message;
    }
    /**
     * Token types that were expected
     * The type names are parser dependent but should provide meaningful
     * hints to the user
     * @return string[]
     */
    public function getExpectedTokens() {
        return $this->expectedTokens;
    }
    /**
     * Token found
     * @return string
     */
    public function getActualToken() {
        return $this->actualToken;
    }
    /**
     * Offset of the error.
     * NOTE: Offset in byte (mb_strcut if you want to provide feedback and print the error in context)
     * @return int
     */
    public function getStart() {
        return $this->start;
    }
    /**
     * @return mixed[]
     */
    public function getMessageParams() {
        return $this->messageParams;
    }
    /**
     * @return array
     */
    public function toArray() {
        $ar = [
            'msg' => $this->message,
            'start' => $this->getStart(),
        ];
        if ( $this->expectedTokens !== [] ) {
            $ar['expected'] = $this->expectedTokens;
        }
        if ( $this->actualToken !== null ) {
            $ar['actual'] = $this->actualToken;
        }
        if ( $this->messageParams !== [] ) {
            $ar['message_params'] = $this->messageParams;
        }
        return $ar;
    }
}