AuthorEmailPrompt::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace CL\ComposerInit\Prompt;
4
5
use CL\ComposerInit\GitConfig;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Helper\DialogHelper;
8
use RuntimeException;
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 AuthorEmailPrompt implements PromptInterface
16
{
17
    /**
18
     * @var GitConfig
19
     */
20
    private $gitConfig;
21
22
    /**
23
     * @param GitConfig $gitConfig
24
     */
25 1
    public function __construct(GitConfig $gitConfig)
26
    {
27 1
        $this->gitConfig = $gitConfig;
28 1
    }
29
30
    /**
31
     * @return GitConfig
32
     */
33 1
    public function getGitConfig()
34
    {
35 1
        return $this->gitConfig;
36
    }
37
38
    /**
39
     * @return string
40
     */
41 1
    public function getDefault()
42
    {
43 1
        return $this->gitConfig->get('user.email');
44
    }
45
46
    /**
47
     * @param  OutputInterface $output
48
     * @param  DialogHelper    $dialog
49
     * @return array
50
     */
51 1
    public function getValues(OutputInterface $output, DialogHelper $dialog)
52
    {
53 1
        $default = $this->getDefault();
54
55 1
        $value = $dialog->askAndValidate(
56 1
            $output,
57 1
            "<info>Author email</info> ({$default}): ",
58 1
            function ($email) {
59 1
                if (false === filter_var($email, FILTER_VALIDATE_EMAIL)) {
60 1
                    throw new RuntimeException('Not a valid email');
61
                }
62
63 1
                return $email;
64 1
            },
65 1
            false,
66
            $default
67 1
        );
68
69 1
        return ['author_email' => $value];
70
    }
71
}
72