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.

SearchFilesCommand::handleResponse()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 22
rs 8.6737
cc 5
eloc 14
nc 7
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\SearchFilesPayload;
15
use CL\Slack\Payload\SearchFilesPayloadResponse;
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 SearchFilesCommand extends AbstractApiCommand
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
31
        $this->setName('search:files');
32
        $this->setDescription('Searches 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:files</info> command allows you to search for files 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.files</comment>
51
EOT
52
        );
53
    }
54
55
    /**
56
     * @return SearchFilesPayload
57
     */
58
    protected function createPayload()
59
    {
60
        $payload = new SearchFilesPayload();
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 SearchFilesPayloadResponse $payloadResponse
75
     */
76
    protected function handleResponse($payloadResponse)
77
    {
78
        if ($payloadResponse->isOk()) {
79
            $total = 0;
80
            if ($fileSearchResult = $payloadResponse->getResult()) {
81
                $total += $fileSearchResult->getTotal();
82
            }
83
84
            $this->writeComment(sprintf('Got %d results...', $total));
85
86
            if ($total > 0) {
87
                $this->writeComment('Listing files...');
88
                if ($fileSearchResult->getTotal() > 1) {
89
                    $this->renderTable($fileSearchResult->getMatches());
90
                } else {
91
                    $this->writeComment('No files matched the query');
92
                }
93
            }
94
        } else {
95
            $this->writeError(sprintf('Failed to search. %s', lcfirst($payloadResponse->getErrorExplanation())));
96
        }
97
    }
98
}
99