DescriptionPrompt::getValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
crap 1
1
<?php
2
3
namespace CL\ComposerInit\Prompt;
4
5
use GuzzleHttp\Client;
6
use CL\ComposerInit\GitConfig;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Helper\DialogHelper;
9
10
/**
11
 * @author    Ivan Kerin <[email protected]>
12
 * @copyright (c) 2014 Clippings Ltd.
13
 * @license   http://spdx.org/licenses/BSD-3-Clause
14
 */
15
class DescriptionPrompt implements PromptInterface
16
{
17
    /**
18
     * Github Client
19
     *
20
     * @var Client
21
     */
22
    private $github;
23
24
25
    /**
26
     * @var GitConfig
27
     */
28
    private $gitConfig;
29
30
    /**
31
     * @param GitConfig $gitConfig
32
     * @param Client    $github
33
     */
34 1
    public function __construct(GitConfig $gitConfig, Client $github)
35
    {
36 1
        $this->gitConfig = $gitConfig;
37 1
        $this->github = $github;
38 1
    }
39
40
    /**
41
     * @return Client
42
     */
43 1
    public function getGithub()
44
    {
45 1
        return $this->github;
46
    }
47
48
    /**
49
     * @return GitConfig
50
     */
51 1
    public function getGitConfig()
52
    {
53 1
        return $this->gitConfig;
54
    }
55
56
    /**
57
     * @return string|null
58
     */
59 2
    public function getDefault()
60
    {
61 2
        $origin = $this->gitConfig->getOrigin();
62
63 2
        if (null !== $origin) {
64 1
            $response = $this->github->get("/repos/{$origin}");
65 1
            $repo = json_decode($response->getBody(), true);
66 1
            return $repo['description'];
67
        }
68 1
    }
69
70
    /**
71
     * @param  OutputInterface $output
72
     * @param  DialogHelper    $dialog
73
     * @return array
74
     */
75 1
    public function getValues(OutputInterface $output, DialogHelper $dialog)
76
    {
77 1
        $default = $this->getDefault();
78
79 1
        $value = $dialog->ask(
80 1
            $output,
81 1
            "<info>Description</info> ({$default}): ",
82
            $default
83 1
        );
84
85
        return [
86 1
            'description' => $value,
87 1
        ];
88
    }
89
}
90
91