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.

ChannelsListCommand::handleResponse()   B
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6.0061

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 22
ccs 17
cts 18
cp 0.9444
rs 8.6737
cc 6
eloc 16
nc 7
nop 1
crap 6.0061
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\ChannelsListPayload;
15
use CL\Slack\Payload\ChannelsListPayloadResponse;
16
use Symfony\Component\Console\Input\InputOption;
17
18
/**
19
 * @author Cas Leentfaar <[email protected]>
20
 */
21
class ChannelsListCommand extends AbstractApiCommand
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26 1
    protected function configure()
27
    {
28 1
        parent::configure();
29
30 1
        $this->setName('channels:list');
31 1
        $this->setDescription('Returns a list of all channels in your Slack team');
32 1
        $this->addOption('exclude-archived', null, InputOption::VALUE_OPTIONAL, 'Don\'t return archived channels.');
33 1
        $this->setHelp(<<<EOT
34
The <info>channels:list</info> command returns a list of all channels in your Slack team.
35
This includes channels the caller is in, channels they are not currently in, and archived channels.
36
The number of (non-deactivated) members in each channel is also returned.
37
38
For more information about the related API method, check out the official documentation:
39
<comment>https://api.slack.com/methods/channels.list</comment>
40
EOT
41 1
        );
42 1
    }
43
44
    /**
45
     * @return ChannelsListPayload
46
     */
47 1
    protected function createPayload()
48
    {
49 1
        $payload = new ChannelsListPayload();
50 1
        $payload->setExcludeArchived($this->input->getOption('exclude-archived'));
51
52 1
        return $payload;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     *
58
     * @param ChannelsListPayloadResponse $payloadResponse
59
     */
60 1
    protected function handleResponse($payloadResponse)
61
    {
62 1
        if ($payloadResponse->isOk()) {
63 1
            $channels = $payloadResponse->getChannels();
64 1
            $this->output->writeln(sprintf('Received <comment>%d</comment> channels...', count($channels)));
65 1
            if (!empty($channels)) {
66 1
                $rows = [];
67 1
                foreach ($payloadResponse->getChannels() as $channel) {
68 1
                    $row = $this->serializeObjectToArray($channel);
69 1
                    $row['purpose'] = !$channel->getPurpose() ?: $channel->getPurpose()->getValue();
70 1
                    $row['topic'] = !$channel->getTopic() ?: $channel->getTopic()->getValue();
71
72 1
                    $rows[] = $row;
73 1
                }
74 1
                $this->renderTable($rows, null);
75 1
            } else {
76
                $this->writeError('No channels seem to be assigned to your team... this is strange...');
77
            }
78 1
        } else {
79 1
            $this->writeError(sprintf('Failed to list channels. %s', lcfirst($payloadResponse->getErrorExplanation())));
80
        }
81 1
    }
82
}
83