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.

SearchAllCommand::handleResponse()   C
last analyzed

Complexity

Conditions 7
Paths 21

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 32
rs 6.7272
cc 7
eloc 21
nc 21
nop 1
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\SearchAllPayload;
15
use CL\Slack\Payload\SearchAllPayloadResponse;
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 SearchAllCommand extends AbstractApiCommand
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
31
        $this->setName('search:all');
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:all</info> command allows you to search both messages and files with a single query.
41
42
The response returns matches broken down by their type of content, similar to the facebook/gmail auto-completed search widgets.
43
44
For more information about the related API method, check out the official documentation:
45
<comment>https://api.slack.com/methods/search.all</comment>
46
EOT
47
        );
48
    }
49
50
    /**
51
     * @return SearchAllPayload
52
     */
53
    protected function createPayload()
54
    {
55
        $payload = new SearchAllPayload();
56
        $payload->setQuery($this->input->getArgument('query'));
57
        $payload->setSort($this->input->getOption('sort'));
58
        $payload->setSortDir($this->input->getOption('sort-dir'));
59
        $payload->setPage($this->input->getOption('page'));
60
        $payload->setCount($this->input->getOption('count'));
61
        $payload->setHighlight($this->input->getOption('highlight'));
62
63
        return $payload;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     *
69
     * @param SearchAllPayloadResponse $payloadResponse
70
     */
71
    protected function handleResponse($payloadResponse)
72
    {
73
        if ($payloadResponse->isOk()) {
74
            $total = 0;
75
            if ($messageSearchResult = $payloadResponse->getMessageResult()) {
76
                $total += $messageSearchResult->getTotal();
77
            }
78
            if ($fileSearchResult = $payloadResponse->getFileResult()) {
79
                $total += $fileSearchResult->getTotal();
80
            }
81
82
            $this->writeComment(sprintf('Got %d results...', $total));
83
84
            if ($total > 0) {
85
                $this->writeComment('Listing messages...');
86
                if ($messageSearchResult->getTotal() > 1) {
87
                    $this->renderTable($messageSearchResult->getMatches());
88
                } else {
89
                    $this->writeComment('No messages matched the query');
90
                }
91
92
                $this->writeComment('Listing files...');
93
                if ($fileSearchResult->getTotal() > 1) {
94
                    $this->renderTable($fileSearchResult->getMatches());
95
                } else {
96
                    $this->writeComment('No files matched the query');
97
                }
98
            }
99
        } else {
100
            $this->writeError(sprintf('Failed to search. %s', lcfirst($payloadResponse->getErrorExplanation())));
101
        }
102
    }
103
}
104