Passed
Pull Request — master (#56)
by Robbie
04:41
created

AbstractMemberCommand::getMember()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 2
1
<?php
2
3
namespace SilverLeague\Console\Command\Member;
4
5
use SilverLeague\Console\Command\SilverStripeCommand;
6
use SilverStripe\Security\Member;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Provides a base for member related commands, lookups etc
12
 *
13
 * @package silverstripe-console
14
 * @author  Robbie Averill <[email protected]>
15
 */
16
abstract class AbstractMemberCommand extends SilverStripeCommand
17
{
18
    /**
19
     * Get a member by the provided email address, output an error message if not found
20
     *
21
     * @param InputInterface $input
22
     * @param OutputInterface $output
23
     * @return Member|false
24
     */
25
    protected function getMember(InputInterface $input, OutputInterface $output)
26
    {
27
        $email = $this->getOrAskForArgument($input, $output, 'email', 'Enter email address: ');
28
        if (empty($email)) {
29
            $output->writeln('<error>Please enter an email address.</error>');
30
            return false;
31
        }
32
33
        /** @var Member $member */
34
        $member = Member::get()->filter('email', $email)->first();
35
        if (!$member) {
36
            $output->writeln('<error>Member with email "' . $email . '" was not found.');
37
            return false;
38
        }
39
40
        return $member;
41
    }
42
}
43
44