Completed
Push — master ( a1ca1a...6a943d )
by David
01:56
created

EmailValidation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 75
Duplicated Lines 41.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 31
loc 75
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 14 14 1
A parse() 17 17 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
/*
4
 * Copyright (C) 2013 Mailgun
5
 *
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Mailgun\Api;
11
12
use Mailgun\Assert;
13
use Mailgun\Exception\HttpClientException;
14
use Mailgun\Exception\HttpServerException;
15
use Mailgun\Exception\InvalidArgumentException;
16
use Mailgun\Model\EmailValidation\Response\ParseResponse;
17
use Mailgun\Model\EmailValidation\Response\ValidateResponse;
18
19
/**
20
 * @see https://documentation.mailgun.com/en/latest/api-email-validation.html
21
 *
22
 * @author David Garcia <[email protected]>
23
 */
24
class EmailValidation extends HttpApi
25
{
26
    /**
27
     * Addresses are validated based off defined checks.
28
     *
29
     * This operation is only accessible with the private API key and not subject to the daily usage limits.
30
     *
31
     * @param string     $address             An email address to validate. Maximum: 512 characters.
32
     * @param bool|false $mailboxVerification If set to true, a mailbox verification check will be performed
33
     *                                        against the address. The default is False.
34
     *
35
     * @throws InvalidArgumentException Thrown when local validation returns an error
36
     * @throws HttpClientException      Thrown when there's an error on Client side
37
     * @throws HttpServerException      Thrown when there's an error on Server side
38
     * @throws \Exception               Thrown when we don't catch a Client or Server side Exception
39
     *
40
     * @return ValidateResponse
41
     */
42 View Code Duplication
    public function validate(string $address, $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...
43
    {
44
        Assert::stringNotEmpty($address);
45
        Assert::boolean($mailboxVerification);
46
47
        $params = [
48
            'address' => $address,
49
            'mailbox_verification' => $mailboxVerification,
50
        ];
51
52
        $response = $this->httpGet('/address/private/validate', $params);
53
54
        return $this->hydrateResponse($response, ValidateResponse::class);
55
    }
56
57
    /**
58
     * Parses a delimiter-separated list of email addresses into two lists: parsed addresses and unparsable portions.
59
     *
60
     * The parsed addresses are a list of addresses that are syntactically valid
61
     * (and optionally pass DNS and ESP specific grammar checks).
62
     *
63
     * The unparsable list is a list of character sequences that could not be parsed
64
     * (or optionally failed DNS or ESP specific grammar checks).
65
     *
66
     * Delimiter characters are comma (,) and semicolon (;).
67
     *
68
     * This operation is only accessible with the private API key and not subject to the daily usage limits.
69
     *
70
     * @param string     $addresses  A delimiter separated list of addresses. Maximum: 8000 characters.
71
     * @param bool|false $syntaxOnly Perform only syntax checks or DNS and ESP specific validation as well.
72
     *                               The default is True.
73
     *
74
     * @throws InvalidArgumentException Thrown when local validation returns an error
75
     * @throws HttpClientException      Thrown when there's an error on Client side
76
     * @throws HttpServerException      Thrown when there's an error on Server side
77
     * @throws \Exception               Thrown when we don't catch a Client or Server side Exception
78
     *
79
     * @return ParseResponse
80
     */
81 View Code Duplication
    public function parse($addresses, $syntaxOnly = true)
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...
82
    {
83
        Assert::stringNotEmpty($addresses);
84
        Assert::maxLength($addresses, 8000);
85
86
        // Validates the Syntax Only verification.
87
        Assert::boolean($syntaxOnly);
88
89
        $params = [
90
            'addresses' => $addresses,
91
            'syntax_only' => $syntaxOnly,
92
        ];
93
94
        $response = $this->httpGet('/address/private/parse', $params);
95
96
        return $this->hydrateResponse($response, ParseResponse::class);
97
    }
98
}
99