AuthorEmailPrompt   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 57
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getGitConfig() 0 4 1
A getDefault() 0 4 1
A getValues() 0 20 2
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