Completed
Push — master ( 2b60fb...0f5433 )
by David
02:06
created

EmailValidation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 71
Duplicated Lines 18.31 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 13
loc 71
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 13 13 1
A parse() 0 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2013 Mailgun
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license. See the LICENSE file for details.
10
 */
11
12
namespace Mailgun\Api;
13
14
use Mailgun\Assert;
15
use Mailgun\Exception\HttpClientException;
16
use Mailgun\Exception\HttpServerException;
17
use Mailgun\Exception\InvalidArgumentException;
18
use Mailgun\Model\EmailValidation\ParseResponse;
19
use Mailgun\Model\EmailValidation\ValidateResponse;
20
use Psr\Http\Message\ResponseInterface;
21
22
/**
23
 * @see https://documentation.mailgun.com/en/latest/api-email-validation.html
24
 *
25
 * @author David Garcia <[email protected]>
26
 */
27
class EmailValidation extends HttpApi
28
{
29
    /**
30
     * Addresses are validated based off defined checks.
31
     *
32
     * This operation is only accessible with the private API key and not subject to the daily usage limits.
33
     *
34
     * @param string $address             An email address to validate. Maximum: 512 characters.
35
     * @param bool   $mailboxVerification If set to true, a mailbox verification check will be performed
36
     *                                    against the address. The default is False.
37
     *
38
     * @throws InvalidArgumentException Thrown when local validation returns an error
39
     * @throws HttpClientException      Thrown when there's an error on Client side
40
     * @throws HttpServerException      Thrown when there's an error on Server side
41
     * @throws \Exception               Thrown when we don't catch a Client or Server side Exception
42
     *
43
     * @return ValidateResponse|ResponseInterface
44
     */
45 1 View Code Duplication
    public function validate(string $address, bool $mailboxVerification = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47 1
        Assert::stringNotEmpty($address);
48
49
        $params = [
50 1
            'address' => $address,
51 1
            'mailbox_verification' => $mailboxVerification,
52
        ];
53
54 1
        $response = $this->httpGet('/address/private/validate', $params);
55
56 1
        return $this->hydrateResponse($response, ValidateResponse::class);
57
    }
58
59
    /**
60
     * Parses a delimiter-separated list of email addresses into two lists: parsed addresses and unparsable portions.
61
     *
62
     * The parsed addresses are a list of addresses that are syntactically valid
63
     * (and optionally pass DNS and ESP specific grammar checks).
64
     *
65
     * The unparsable list is a list of character sequences that could not be parsed
66
     * (or optionally failed DNS or ESP specific grammar checks).
67
     *
68
     * Delimiter characters are comma (,) and semicolon (;).
69
     *
70
     * This operation is only accessible with the private API key and not subject to the daily usage limits.
71
     *
72
     * @param string $addresses  A delimiter separated list of addresses. Maximum: 8000 characters.
73
     * @param bool   $syntaxOnly Perform only syntax checks or DNS and ESP specific validation as well.
74
     *                           The default is True.
75
     *
76
     * @throws InvalidArgumentException Thrown when local validation returns an error
77
     * @throws HttpClientException      Thrown when there's an error on Client side
78
     * @throws HttpServerException      Thrown when there's an error on Server side
79
     * @throws \Exception               Thrown when we don't catch a Client or Server side Exception
80
     *
81
     * @return ParseResponse|ResponseInterface
82
     */
83 1
    public function parse(string $addresses, bool $syntaxOnly = true)
84
    {
85 1
        Assert::stringNotEmpty($addresses);
86 1
        Assert::maxLength($addresses, 8000);
87
88
        $params = [
89 1
            'addresses' => $addresses,
90 1
            'syntax_only' => $syntaxOnly,
91
        ];
92
93 1
        $response = $this->httpGet('/address/private/parse', $params);
94
95 1
        return $this->hydrateResponse($response, ParseResponse::class);
96
    }
97
}
98