Completed
Pull Request — master (#20)
by
unknown
03:12
created

InlineQueryResults::newArticle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 6
1
<?php
2
3
namespace PhpBotFramework\Entities;
4
5
/**
6
 * \class InlineQueryResults InlineQueryResults
7
 * \brief Handle and store results before sending them to an answerInlineQuery api call.
8
 */
9
class InlineQueryResults {
10
11
    /**
12
     * \addtogroup InlineQueryResults InlineQueryResults
13
     * \brief Handle and store results before sending them to an answerInlineQuery api call.
14
     * @{
15
     */
16
17
    /** \brief Array of the results stored */
18
    private $results;
19
20
    /** \brief Count the result so we can assign them an unique id */
21
    private $id_article;
22
23
    /**
24
     * \constructor Create an InlineQueryResult object. */
25
    public function __construct() {
26
27
        // Initialize the array to empty
28
        $this->results = [];
29
30
        $this->id_article = 0;
31
32
    }
33
34
    /**
35
     * \brief Add a result of type article article.
36
     * \details Add a result that will be show to the user.
37
     * @param $title Title of the result.
38
     * @param $message_text Text of the message to be sent.
39
     * @param $description <i>Optional</i>. Short description of the result
40
     * @param $reply_markup Inline keyboard object (Not JSON serialized, use getArray from InlineKeyboard class).
41
     * @param $parse_mode <i>Optional</i>. Formattation of the message.
42
     * @param $disable_web_preview <i>Optional</i>. Disables link previews for links in the sent message
43
     * @return Id the the article added
44
     */
45
    public function newArticle($title, $message_text, $description = '', array $reply_markup = null, $parse_mode = 'HTML', $disable_web_preview = false) {
46
47
        array_push($this->results, [
48
            'type' => 'article',
49
            'id' => (string)$this->id_article,
50
            'title' => $title,
51
            'message_text' => $message_text,
52
            'description' => $description,
53
            'parse_mode' => $parse_mode,
54
            'reply_markup' => $reply_markup,
55
            'disable_web_page_preview' => $disable_web_preview
56
        ]);
57
58
        return $this->id_article++;
59
60
    }
61
62
    /**
63
     * \brief Get all results created.
64
     * @return JSON-serialized string containing the results.
0 ignored issues
show
Documentation introduced by
The doc-type JSON-serialized could not be parsed: Unknown type name "JSON-serialized" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
65
     */
66
    public function getResults() {
67
68
        // Encode the results to get a JSON-serialized object
69
        $encoded_results = json_encode($this->results);
70
71
        // Clear the results
72
        $this->results = [];
73
74
        return $encoded_results;
75
76
    }
77
}
78
79
/** @} */
80