Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReindexResponse
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 7
132
0.00% covered (danger)
0.00%
0 / 1
 isSuccessful
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 getUnsuccessfulReason
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 isComplete
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isFailed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFailures
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isCanceled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 getCanceledReason
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace CirrusSearch\Elastica;
4
5use Exception;
6
7class ReindexResponse extends ReindexStatus {
8    /**
9     * @return bool True when the reindex completed successfully
10     */
11    public function isSuccessful() {
12        return !$this->isFailed() && !$this->isCanceled();
13    }
14
15    /**
16     * @return string The reason the reindex was unsuccessful
17     * @throws Exception If the reindex completed successfully
18     */
19    public function getUnsuccessfulReason() {
20        if ( $this->isCanceled() ) {
21            return "Canceled: " . $this->getCanceledReason();
22        } elseif ( $this->isFailed() ) {
23            return "Failed: " . json_encode( $this->getFailures() );
24        } else {
25            throw new Exception( "Request was successful" );
26        }
27    }
28
29    /**
30     * @return bool
31     */
32    public function isComplete() {
33        return true;
34    }
35
36    /**
37     * @return bool
38     */
39    public function isFailed() {
40        return !empty( $this->status['failures'] );
41    }
42
43    /**
44     * @return string[]
45     */
46    public function getFailures() {
47        return $this->status['failures'];
48    }
49
50    /**
51     * @return bool True If the reindex was canceled (as opposed to failing)
52     */
53    public function isCanceled() {
54        return isset( $this->status['canceled'] ) && (bool)$this->status['canceled'];
55    }
56
57    /**
58     * @return string The reason the reindex was canceled
59     */
60    public function getCanceledReason() {
61        return $this->status['canceled'];
62    }
63}