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.

ChannelsHistoryCommand::handleResponse()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.7283

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 15
ccs 9
cts 13
cp 0.6923
rs 8.8571
cc 5
eloc 10
nc 5
nop 1
crap 5.7283
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\ChannelsHistoryPayload;
15
use CL\Slack\Payload\ChannelsHistoryPayloadResponse;
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 ChannelsHistoryCommand extends AbstractApiCommand
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27 1
    protected function configure()
28
    {
29 1
        parent::configure();
30
31 1
        $this->setName('channels:history');
32 1
        $this->setDescription('Returns a portion of messages/events from the specified channel (see `--help`)');
33 1
        $this->addArgument('channel-id', InputArgument::REQUIRED, 'Channel to fetch history for');
34 1
        $this->addOption('latest', 'l', InputOption::VALUE_REQUIRED, 'Latest message timestamp to include in results');
35 1
        $this->addOption('oldest', 'o', InputOption::VALUE_REQUIRED, 'Oldest message timestamp to include in results');
36 1
        $this->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'Number of messages to return, between 1 and 1000.');
37 1
        $this->setHelp(<<<EOT
38
The <info>channels:history</info> command returns a portion of messages/events from the specified channel.
39
To read the entire history for a channel, run the command with no `latest` or `oldest` options, and then continue paging
40
using the instructions below.
41
42
The messages array up to 100 messages between `--latest` and `--oldest`. If there were more than 100 messages between
43
those two points, then has_more will be true.
44
45
If a message has the same timestamp as latest or oldest it will not be included in the list. This allows a client to fetch
46
all messages in a hole in channel history, by running the <info>channels.history</info> command with `--latest`
47
set to the oldest message they have after the hole, and `--oldest` to the latest message they have before the hole.
48
If the response includes `has_more` then the client can make another call, using the `ts` value of the final messages as
49
the latest param to get the next page of messages.
50
51
If there are more than 100 messages between the two timestamps then the messages returned are the ones closest to latest.
52
In most cases an application will want the most recent messages and will page backward from there. If oldest is provided
53
but not latest then the messages returned are those closest to oldest, allowing you to page forward through history if desired.
54
55
If either of the latest or oldest arguments are provided then those timestamps will also be included in the output.
56
57
For more information about the related API method, check out the official documentation:
58
<comment>https://api.slack.com/methods/channels.history</comment>
59
EOT
60 1
        );
61 1
    }
62
63
    /**
64
     * @return ChannelsHistoryPayload
65
     */
66 1
    protected function createPayload()
67
    {
68 1
        $payload = new ChannelsHistoryPayload();
69 1
        $payload->setChannelId($this->input->getArgument('channel-id'));
70 1
        $payload->setLatest($this->input->getOption('latest'));
71 1
        $payload->setOldest($this->input->getOption('oldest'));
72 1
        $payload->setCount($this->input->getOption('count'));
73
74 1
        return $payload;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     *
80
     * @param ChannelsHistoryPayloadResponse $payloadResponse
81
     */
82 1
    protected function handleResponse($payloadResponse)
83
    {
84 1
        if ($payloadResponse->isOk()) {
85 1
            $this->writeOk('Successfully retrieved history');
86 1
            $this->renderTable($payloadResponse->getMessages());
87 1
            if ($payloadResponse->getLatest() !== null) {
88
                $this->output->writeln(sprintf('Latest: <comment>%s</comment>', $payloadResponse->getLatest()));
89
            }
90 1
            if ($payloadResponse->getHasMore() !== null) {
91
                $this->output->writeln(sprintf('Has more: <comment>%s</comment>', $payloadResponse->getHasMore() ? 'yes' : 'no'));
92
            }
93 1
        } else {
94 1
            $this->writeError(sprintf('Failed to retrieve history for this channel: %s', lcfirst($payloadResponse->getErrorExplanation())));
95
        }
96 1
    }
97
}
98