GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SearchMessagesCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 7
c 5
b 1
f 0
lcom 3
cbo 5
dl 0
loc 77
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 27 1
A createPayload() 0 12 1
B handleResponse() 0 22 5
1
<?php
2
3
/*
4
 * This file is part of the slack-cli package.
5
 *
6
 * (c) Cas Leentfaar <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CL\SlackCli\Command;
13
14
use CL\Slack\Payload\SearchMessagesPayload;
15
use CL\Slack\Payload\SearchMessagesPayloadResponse;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputOption;
18
19
/**
20
 * @author Cas Leentfaar <[email protected]>
21
 */
22
class SearchMessagesCommand extends AbstractApiCommand
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
31
        $this->setName('search:messages');
32
        $this->setDescription('Searches messages and files within your Slack team');
33
        $this->addArgument('query', InputArgument::REQUIRED, 'Search query. May contains booleans, etc.');
34
        $this->addOption('sort', null, InputOption::VALUE_REQUIRED, 'Return matches sorted by either score or timestamp');
35
        $this->addOption('sort-dir', null, InputOption::VALUE_REQUIRED, 'Change sort direction to ascending (asc) or descending (desc)');
36
        $this->addOption('highlight', null, InputOption::VALUE_REQUIRED, 'Pass a value of 1 to enable query highlight markers');
37
        $this->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'Number of items to return per page');
38
        $this->addOption('page', 'p', InputOption::VALUE_REQUIRED, 'Page number of results to return');
39
        $this->setHelp(<<<EOT
40
The <info>search:messages</info> command allows you to search for messages matching a given query
41
42
If the `--highlight` option is specified, the matching query terms will be marked up in the results so that clients may
43
replace them with appropriate highlighting markers (e.g. <span class="highlight"></span>).
44
45
The UTF-8 markers used are:
46
- start: "\xEE\x80\x80"; # U+E000 (private-use)
47
- end  : "\xEE\x80\x81"; # U+E001 (private-use)
48
49
For more information about the related API method, check out the official documentation:
50
<comment>https://api.slack.com/methods/search.messages</comment>
51
EOT
52
        );
53
    }
54
55
    /**
56
     * @return SearchMessagesPayload
57
     */
58
    protected function createPayload()
59
    {
60
        $payload = new SearchMessagesPayload();
61
        $payload->setQuery($this->input->getArgument('query'));
62
        $payload->setSort($this->input->getOption('sort'));
63
        $payload->setSortDir($this->input->getOption('sort-dir'));
64
        $payload->setPage($this->input->getOption('page'));
65
        $payload->setCount($this->input->getOption('count'));
66
        $payload->setHighlight($this->input->getOption('highlight'));
67
68
        return $payload;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     *
74
     * @param SearchMessagesPayloadResponse $payloadResponse
75
     */
76
    protected function handleResponse($payloadResponse)
77
    {
78
        if ($payloadResponse->isOk()) {
79
            $total = 0;
80
            if ($messageSearchResult = $payloadResponse->getResult()) {
81
                $total += $messageSearchResult->getTotal();
82
            }
83
84
            $this->writeComment(sprintf('Got %d results...', $total));
85
86
            if ($total > 0) {
87
                $this->writeComment('Listing messages...');
88
                if ($messageSearchResult->getTotal() > 1) {
89
                    $this->renderTable($messageSearchResult->getMatches());
90
                } else {
91
                    $this->writeComment('No messages matched the query');
92
                }
93
            }
94
        } else {
95
            $this->writeError(sprintf('Failed to search. %s', lcfirst($payloadResponse->getErrorExplanation())));
96
        }
97
    }
98
}
99