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.

ImHistoryCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
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 76
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 35 1
A createPayload() 0 10 1
B handleResponse() 0 15 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\ImHistoryPayload;
15
use CL\Slack\Payload\ImHistoryPayloadResponse;
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 ImHistoryCommand extends AbstractApiCommand
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
31
        $this->setName('im:history');
32
        $this->setDescription('Returns a portion of messages/events from the specified im (see `--help`)');
33
        $this->addArgument('im-id', InputArgument::REQUIRED, 'ID of the IM channel to fetch history for');
34
        $this->addOption('latest', 'l', InputOption::VALUE_REQUIRED, 'Latest message timestamp to include in results');
35
        $this->addOption('oldest', 'o', InputOption::VALUE_REQUIRED, 'Oldest message timestamp to include in results');
36
        $this->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'Number of messages to return, between 1 and 1000.');
37
        $this->setHelp(<<<EOT
38
The <info>im:history</info> command returns a portion of messages/events from the specified im.
39
To read the entire history for a im, 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 im history, by running the <info>im.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/im.history</comment>
59
EOT
60
        );
61
    }
62
63
    /**
64
     * @return ImHistoryPayload
65
     */
66
    protected function createPayload()
67
    {
68
        $payload = new ImHistoryPayload();
69
        $payload->setImId($this->input->getArgument('im-id'));
70
        $payload->setLatest($this->input->getOption('latest'));
71
        $payload->setOldest($this->input->getOption('oldest'));
72
        $payload->setCount($this->input->getOption('count'));
73
74
        return $payload;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     *
80
     * @param ImHistoryPayloadResponse $payloadResponse
81
     */
82
    protected function handleResponse($payloadResponse)
83
    {
84
        if ($payloadResponse->isOk()) {
85
            $this->writeOk('Successfully retrieved history');
86
            $this->renderTable($payloadResponse->getMessages());
87
            if ($payloadResponse->getLatest() !== null) {
88
                $this->output->writeln(sprintf('Latest: <comment>%s</comment>', $payloadResponse->getLatest()));
89
            }
90
            if ($payloadResponse->getHasMore() !== null) {
91
                $this->output->writeln(sprintf('Has more: <comment>%s</comment>', $payloadResponse->getHasMore() ? 'yes' : 'no'));
92
            }
93
        } else {
94
            $this->writeError(sprintf('Failed to retrieve history for this IM channel: %s', lcfirst($payloadResponse->getErrorExplanation())));
95
        }
96
    }
97
}
98