GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( bbd300...d1c314 )
by
unknown
10s
created

Util::webHostReport()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 15

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.2
c 0
b 0
f 0
cc 3
eloc 15
nc 4
nop 1
1
<?php
2
namespace Checkdomain\Comodo;
3
4
use Checkdomain\Comodo\Model\Exception\AccountException;
5
use Checkdomain\Comodo\Model\Exception\ArgumentException;
6
use Checkdomain\Comodo\Model\Exception\CSRException;
7
use Checkdomain\Comodo\Model\Exception\RequestException;
8
use Checkdomain\Comodo\Model\Exception\UnknownApiException;
9
use Checkdomain\Comodo\Model\Exception\UnknownException;
10
11
use Checkdomain\Comodo\Model\Result\AutoApplyResult;
12
use Checkdomain\Comodo\Model\Result\AutoReplaceResult;
13
use Checkdomain\Comodo\Model\Result\CollectSslResult;
14
use Checkdomain\Comodo\Model\Result\GetDCVEMailAddressListResult;
15
use Checkdomain\Comodo\Model\Result\GetMDCDomainDetailsResult;
16
use Checkdomain\Comodo\Model\Result\UpdateUserEvClickThroughResult;
17
use Checkdomain\Comodo\Model\Result\SslCheckerResult;
18
use Checkdomain\Comodo\Model\Result\WebHostReportResult;
19
20
/**
21
 * Class Util
22
 * Provides functions to communicate with the Comodo API,requires an Account object, given to the Communication-adapter
23
 */
24
class Util
25
{
26
    const COMODO_AUTO_APPLY_URL                 = 'https://secure.comodo.net/products/!AutoApplySSL';
27
    const COMODO_AUTO_REVOKE_URL                = 'https://secure.comodo.net/products/!AutoRevokeSSL';
28
    const COMODO_DCV_MAIL_URL                   = 'https://secure.comodo.net/products/!GetDCVEmailAddressList';
29
    const COMODO_DCV_RESEND_URL                 = 'https://secure.comodo.net/products/!ResendDCVEmail';
30
    const COMODO_AUTO_UPDATE_DCV_URL            = 'https://secure.comodo.net/products/!AutoUpdateDCV';
31
    const COMODO_PROVIDE_EV_DETAILS_URL         = 'https://secure.comodo.net/products/!ProvideEVDetails';
32
    const COMODO_MDC_DOMAIN_DETAILS_URL         = 'https://secure.comodo.net/products/!GetMDCDomainDetails';
33
    const COMODO_AUTO_REPLACE_URL               = 'https://secure.comodo.net/products/!AutoReplaceSSL';
34
    const COMODO_COLLECT_SSL_URL                = 'https://secure.comodo.net/products/download/CollectSSL';
35
    const COMODO_UPDATE_USER_EV_CLICK_THROUGH   = 'https://secure.comodo.net/products/!UpdateUserEvClickThrough';
36
    const COMODO_WEB_HOST_REPORT                = 'https://secure.comodo.net/products/!WebHostReport';
37
    const COMODO_SSLCHECKER                     = 'https://secure.comodo.com/sslchecker';
38
39
    const COMODO_DCV_CODE_URL                   = 'https://secure.comodo.net/products/EnterDCVCode2';
40
41
    /**
42
     * @var CommunicationAdapter
43
     */
44
    protected $communicationAdapter;
45
46
    /**
47
     * @var ImapAdapter
48
     */
49
    protected $imapAdapter;
50
51
    /**
52
     * @var ImapHelper
53
     */
54
    protected $imapHelper;
55
56
    /**
57
     * Constructs the Util with a communicationAdapter
58
     *
59
     * @param CommunicationAdapter|null $communicationAdapter
60
     * @param ImapAdapter|null          $imapAdapter
61
     * @param ImapHelper|null           $imapHelper
62
     */
63
    public function __construct(CommunicationAdapter $communicationAdapter, ImapAdapter $imapAdapter, ImapHelper $imapHelper)
64
    {
65
        $this->communicationAdapter = $communicationAdapter;
66
        $this->imapAdapter          = $imapAdapter;
67
        $this->imapHelper           = $imapHelper;
68
    }
69
70
71
    /**
72
     * @return CommunicationAdapter
73
     */
74
    public function getCommunicationAdapter()
75
    {
76
        return $this->communicationAdapter;
77
    }
78
79
    /**
80
     * @param CommunicationAdapter $communicationAdapter
81
     *
82
     * @return Util
83
     */
84
    public function setCommunicationAdapter(CommunicationAdapter $communicationAdapter)
85
    {
86
        $this->communicationAdapter = $communicationAdapter;
87
88
        return $this;
89
    }
90
91
    /**
92
     * @return ImapHelper
93
     */
94
    public function getImapHelper()
95
    {
96
        return $this->imapHelper;
97
    }
98
99
    /**
100
     * @param ImapHelper $imapHelper
101
     *
102
     * @return Util
103
     */
104
    public function setImapHelper(ImapHelper $imapHelper)
105
    {
106
        $this->imapHelper = $imapHelper;
107
108
        return $this;
109
    }
110
111
    /**
112
     * @return ImapAdapter
113
     */
114
    public function getImapAdapter()
115
    {
116
        return $this->imapAdapter;
117
    }
118
119
    /**
120
     * @param ImapAdapter $imapAdapter
121
     *
122
     * @return Util
123
     */
124
    public function setImapAdapter(ImapAdapter $imapAdapter)
125
    {
126
        $this->imapAdapter = $imapAdapter;
127
128
        return $this;
129
    }
130
131
    /**
132
     * Function apply for a certificate
133
     *
134
     * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/
135
     *
136
     * @param array $params
137
     *
138
     * @return AutoApplyResult
139
     * @throws Model\Exception\AccountException
140
     * @throws Model\Exception\ArgumentException
141
     * @throws Model\Exception\CSRException
142
     * @throws Model\Exception\RequestException
143
     * @throws Model\Exception\UnknownApiException
144
     * @throws Model\Exception\UnknownException
145
     */
146
    public function autoApplySSL(array $params)
147
    {
148
        // Two choices, we want url-encoded
149
        $params['responseFormat']    = CommunicationAdapter::RESPONSE_URL_ENCODED;
150
        $params['showCertificateID'] = 'Y';
151
152
        // Send request
153
        $arr = $this
154
            ->communicationAdapter
155
            ->sendToApi(self::COMODO_AUTO_APPLY_URL, $params, CommunicationAdapter::RESPONSE_URL_ENCODED);
156
157
        // Successful
158
        if ($arr['errorCode'] == 1 || $arr['errorCode'] == 0) {
159
            $result = new AutoApplyResult();
160
161
            if ($arr['errorCode'] == 0) {
162
                $paid = true;
163
            } else {
164
                $paid = false;
165
            }
166
167
            $result
168
                ->setPaid($paid)
169
                ->setCertificateID($arr['certificateID'])
170
                ->setExpectedDeliveryTime($arr['expectedDeliveryTime'])
171
                ->setOrderNumber($arr['orderNumber'])
172
                ->setTotalCost($arr['totalCost'])
173
                ->setRequestQuery($arr['requestQuery']);
174
175
            return $result;
176
        } else {
177
            throw $this->createException($arr);
178
        }
179
    }
180
181
    /**
182
     * @param array $params
183
     *
184
     * @return UpdateUserEvClickThroughResult
185
     * @throws AccountException
186
     * @throws ArgumentException
187
     * @throws CSRException
188
     * @throws RequestException
189
     * @throws UnknownApiException
190
     * @throws UnknownException
191
     */
192
    public function updateUserEvClickThrough(array $params)
193
    {
194
        // Send request
195
        $arr = $this
196
            ->communicationAdapter
197
            ->sendToApi(
198
                self::COMODO_UPDATE_USER_EV_CLICK_THROUGH,
199
                $params,
200
                CommunicationAdapter::RESPONSE_URL_ENCODED
201
            );
202
203
        // Successful
204
        if ($arr['errorCode'] == 0) {
205
            $result = new UpdateUserEvClickThroughResult();
206
207
            $result
208
                ->setStatus($arr['status']);
209
210
            return $result;
211
        } else {
212
            throw $this->createException($arr);
213
        }
214
    }
215
216
    /**
217
     * Function update for a certificate
218
     *
219
     * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/
220
     *
221
     * @param array $params
222
     *
223
     * @return AutoApplyResult
224
     * @throws Model\Exception\AccountException
225
     * @throws Model\Exception\ArgumentException
226
     * @throws Model\Exception\CSRException
227
     * @throws Model\Exception\RequestException
228
     * @throws Model\Exception\UnknownApiException
229
     * @throws Model\Exception\UnknownException
230
     */
231 View Code Duplication
    public function autoReplaceSSL(array $params)
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...
232
    {
233
        // Two choices, we want url-encoded
234
        $params['responseFormat'] = CommunicationAdapter::RESPONSE_URL_ENCODED;
235
236
        // Send request
237
        $arr = $this
238
            ->communicationAdapter
239
            ->sendToApi(
240
                self::COMODO_AUTO_REPLACE_URL,
241
                $params,
242
                CommunicationAdapter::RESPONSE_URL_ENCODED
243
            );
244
245
        // Successful
246
        if ($arr['errorCode'] == 0) {
247
            $result = new AutoReplaceResult();
248
249
            $result
250
                ->setCertificateID($arr['certificateID'])
251
                ->setExpectedDeliveryTime($arr['expectedDeliveryTime']);
252
253
            return $result;
254
        } else {
255
            throw $this->createException($arr);
256
        }
257
    }
258
259
    /**
260
     * Function to revoke order
261
     *
262
     * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/
263
     *
264
     * @param array $params
265
     *
266
     * @return bool
267
     * @throws Model\Exception\AccountException
268
     * @throws Model\Exception\ArgumentException
269
     * @throws Model\Exception\RequestException
270
     * @throws Model\Exception\UnknownApiException
271
     * @throws Model\Exception\UnknownException
272
     */
273
    public function autoRevokeSSL(array $params)
274
    {
275
        // Two choices, we want url-encoded
276
        $params['responseFormat'] = CommunicationAdapter::RESPONSE_URL_ENCODED;
277
278
        return $this->sendBooleanRequest(
279
            self::COMODO_AUTO_REVOKE_URL,
280
            $params,
281
            CommunicationAdapter::RESPONSE_URL_ENCODED
282
        );
283
    }
284
285
    /**
286
     * Function to auto update dcv
287
     *
288
     * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/
289
     *
290
     * @param array $params
291
     *
292
     * @return bool
293
     * @throws Model\Exception\AccountException
294
     * @throws Model\Exception\ArgumentException
295
     * @throws Model\Exception\RequestException
296
     * @throws Model\Exception\UnknownApiException
297
     * @throws Model\Exception\UnknownException
298
     */
299
    public function autoUpdateDCV(array $params)
300
    {
301
        return $this->sendBooleanRequest(
302
            self::COMODO_AUTO_UPDATE_DCV_URL,
303
            $params,
304
            CommunicationAdapter::RESPONSE_URL_ENCODED
305
        );
306
    }
307
308
    /**
309
     * Function to get details of a certificate
310
     *
311
     * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/
312
     *
313
     * @param array $params
314
     *
315
     * @return CollectSslResult
316
     * @throws Model\Exception\AccountException
317
     * @throws Model\Exception\ArgumentException
318
     * @throws Model\Exception\CSRException
319
     * @throws Model\Exception\RequestException
320
     * @throws Model\Exception\UnknownApiException
321
     * @throws Model\Exception\UnknownException
322
     */
323
    public function collectSsl(array $params)
324
    {
325
        // Not decode the following indexes
326
        $notDecode = array('caCertificate', 'certificate', 'netscapeCertificateSequence', 'zipFile');
327
328
        // Force threating as array
329
        $forceArray = array('caCertificate');
330
331
        // Two choices, we want url-encoded
332
        $params['responseFormat'] = CommunicationAdapter::RESPONSE_URL_ENCODED;
333
334
        // Send request
335
        $arr = $this
336
            ->communicationAdapter
337
            ->sendToApi(
338
                self::COMODO_COLLECT_SSL_URL,
339
                $params,
340
                CommunicationAdapter::RESPONSE_URL_ENCODED,
341
                $notDecode,
342
                $forceArray
343
            );
344
345
        // Successful
346
        if ($arr['errorCode'] >= 0) {
347
            $result = new CollectSslResult();
348
349
            $this->fill($result, $arr, array('notBefore', 'notAfter'));
0 ignored issues
show
Bug introduced by
It seems like $arr defined by $this->communicationAdap...notDecode, $forceArray) on line 335 can also be of type boolean; however, Checkdomain\Comodo\Util::fill() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
350
351
            return $result;
352
        } else {
353
            throw $this->createException($arr);
354
        }
355
    }
356
357
    /**
358
     * Function to resend the DCV Email
359
     *
360
     * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/
361
     *
362
     * @param array $params
363
     *
364
     * @return bool
365
     * @throws Model\Exception\AccountException
366
     * @throws Model\Exception\ArgumentException
367
     * @throws Model\Exception\RequestException
368
     * @throws Model\Exception\UnknownApiException
369
     * @throws Model\Exception\UnknownException
370
     */
371
    public function resendDCVEMail(array $params)
372
    {
373
        return $this
374
            ->sendBooleanRequest(
375
                self::COMODO_DCV_RESEND_URL,
376
                $params,
377
                CommunicationAdapter::RESPONSE_URL_ENCODED
378
            );
379
    }
380
381
    /**
382
     * @param array $params
383
     *
384
     * @deprecated Comodo support told this function doesn't have any effect anymore
385
     *
386
     * @return bool
387
     * @throws Model\Exception\AccountException
388
     * @throws Model\Exception\ArgumentException
389
     * @throws Model\Exception\CSRException
390
     * @throws Model\Exception\RequestException
391
     * @throws Model\Exception\UnknownApiException
392
     * @throws Model\Exception\UnknownException
393
     */
394
    public function provideEVDetails(array $params)
395
    {
396
        return $this->sendBooleanRequest(
397
            self::COMODO_PROVIDE_EV_DETAILS_URL,
398
            $params,
399
            CommunicationAdapter::RESPONSE_URL_ENCODED
400
        );
401
    }
402
403
    /**
404
     * Function to get the DCV e-mail address-list
405
     *
406
     * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/
407
     *
408
     * @param array $params
409
     *
410
     * @return GetDCVEMailAddressListResult
411
     * @throws AccountException
412
     * @throws ArgumentException
413
     * @throws CSRException
414
     * @throws RequestException
415
     * @throws UnknownApiException
416
     * @throws UnknownException
417
     */
418
    public function getDCVEMailAddressList(array $params)
419
    {
420
        // Force threating as array
421
        $forceArray = array('whois_email', 'level2_email', 'level3_email');
422
423
        // Response is always new line encoded
424
        $responseArray = $this
425
            ->communicationAdapter
426
            ->sendToApi(
427
                self::COMODO_DCV_MAIL_URL,
428
                $params,
429
                CommunicationAdapter::RESPONSE_NEW_LINE,
430
                null,
431
                $forceArray
432
            );
433
434
        if ($responseArray['errorCode'] == 0) {
435
            $result = new GetDCVEMailAddressListResult();
436
437
            $result
438
                ->setDomainName($responseArray['domain_name'])
439
                ->setWhoisEmail($responseArray['whois_email'])
440
                ->setLevel2Emails($responseArray['level2_email'])
441
                ->setRequestQuery($responseArray['requestQuery']);
442
443
            if (isset($responseArray['level3_email'])) {
444
                $result->setLevel3Emails($responseArray['level3_email']);
445
            }
446
447
            return $result;
448
        } else {
449
            throw $this->createException($responseArray);
450
        }
451
    }
452
453
    /**
454
     * Function to get details of a order-number (this API support just one domain)
455
     *
456
     * https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/GetMDCDomainDetails%20v1.00.pdf
457
     *
458
     * @param array $params
459
     *
460
     * @return GetMDCDomainDetailsResult
461
     *
462
     * @throws Model\Exception\AccountException
463
     * @throws Model\Exception\ArgumentException
464
     * @throws Model\Exception\CSRException
465
     * @throws Model\Exception\RequestException
466
     * @throws Model\Exception\UnknownApiException
467
     * @throws Model\Exception\UnknownException
468
     */
469 View Code Duplication
    public function getMDCDomainDetails(array $params)
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...
470
    {
471
        // Response is always new line encoded
472
        $responseArray = $this
473
            ->communicationAdapter
474
            ->sendToApi(
475
                self::COMODO_MDC_DOMAIN_DETAILS_URL,
476
                $params,
477
                CommunicationAdapter::RESPONSE_URL_ENCODED
478
            );
479
480
        if ($responseArray['errorCode'] == 0) {
481
            $result = new GetMDCDomainDetailsResult();
482
483
            $result
484
                ->setDomainName($responseArray['1_domainName'])
485
                ->setDcvMethod($responseArray['1_dcvMethod'])
486
                ->setDcvStatus($responseArray['1_dcvStatus']);
487
488
            return $result;
489
        } else {
490
            throw $this->createException($responseArray);
491
        }
492
    }
493
494
    /**
495
     * Function to do a sslcheck
496
     *
497
     * https://secure.comodo.net/api/pdf/latest/SSLChecker.pdf
498
     *
499
     * @param array $params
500
     *
501
     * @return GetMDCDomainDetailsResult
502
     *
503
     * @throws Model\Exception\AccountException
504
     * @throws Model\Exception\ArgumentException
505
     * @throws Model\Exception\CSRException
506
     * @throws Model\Exception\RequestException
507
     * @throws Model\Exception\UnknownApiException
508
     * @throws Model\Exception\UnknownException
509
     */
510
    public function sslChecker(array $params)
511
    {
512
        // Response is always new line encoded
513
        $responseArray = $this
514
            ->communicationAdapter
515
            ->sendToApi(
516
                self::COMODO_SSLCHECKER,
517
                $params,
518
                CommunicationAdapter::RESPONSE_URL_ENCODED
519
            );
520
521
        if ($responseArray['error_code'] == 0) {
522
            $result = new SslCheckerResult();
523
524
            $result
525
                ->setServerUrl($responseArray['server_url'])
526
                ->setServerDomainIsIDN($responseArray['server_domain_isIDN'])
527
                ->setServerDomainUtf8($responseArray['server_domain_utf8'])
528
                ->setServerDomainAce($responseArray['server_domain_ace'])
529
                ->setServerIp($responseArray['server_ip'])
530
                ->setServerPort($responseArray['server_port'])
531
                ->setServerSoftware($responseArray['server_software'])
532
                ->setCertNotBeforeFromUnixTimestamp($responseArray['cert_notBefore'])
533
                ->setCertNotAfterFromUnixTimestamp($responseArray['cert_notAfter'])
534
                ->setCertValidityNotBefore($responseArray['cert_validity_notBefore'])
535
                ->setCertValidityNotAfter($responseArray['cert_validity_notAfter'])
536
                ->setCertKeyAlgorithm($responseArray['cert_key_algorithm'])
537
                ->setCertKeySize($responseArray['cert_key_size'])
538
                ->setCertSubjectCN($responseArray['cert_subject_DN'])
539
                ->setCertSubjectCN($responseArray['cert_subject_CN'])
540
                ->setCertSubjectOU($responseArray['cert_subject_OU'])
541
                ->setCertSubjectOrganization($responseArray['cert_subject_O'])
542
                ->setCertSubjectStreetAddress1($responseArray['cert_subject_streetAddress_1'])
543
                ->setCertSubjectStreetAddress2($responseArray['cert_subject_streetAddress_2'])
544
                ->setCertSubjectStreetAddress3($responseArray['cert_subject_streetAddress_3'])
545
                ->setCertSubjectLocality($responseArray['cert_subject_L'])
546
                ->setCertSubjectState($responseArray['cert_subject_S'])
547
                ->setCertSubjectPostalCode($responseArray['cert_subject_postalCode'])
548
                ->setCertSubjectCountry($responseArray['cert_subject_C'])
549
                ->setCertIsMultiDomain($responseArray['cert_isMultiDomain'])
550
                ->setCertIsWildcard($responseArray['cert_isWildcard'])
551
                ->setCertIssuerDN($responseArray['cert_issuer_DN'])
552
                ->setCertIssuerCN($responseArray['cert_issuer_CN'])
553
                ->setCertIssuerOrganization($responseArray['cert_issuer_O'])
554
                ->setCertIssuerOrganization($responseArray['cert_issuer_C'])
555
                ->setCertIssuerBrand($responseArray['cert_issuer_brand'])
556
                ->setCertPolicyOID($responseArray['cert_policyOID'])
557
                ->setCertValidation($responseArray['cert_validation']);
558
559
            return $result;
560
        } else {
561
            throw $this->createException($responseArray);
562
        }
563
    }
564
565
    /**
566
     * Function to call WebHostReport api
567
     *
568
     * https://secure.comodo.net/products/!WebHostReport
569
     *
570
     * Details for params usage:
571
     * https://secure.comodo.net/api/pdf/latest/WebHostReport.pdf
572
     *
573
     * @param array $params
574
     *
575
     * @return WebHostReportResult
576
     *
577
     * @throws Model\Exception\AccountException
578
     * @throws Model\Exception\ArgumentException
579
     * @throws Model\Exception\CSRException
580
     * @throws Model\Exception\RequestException
581
     * @throws Model\Exception\UnknownApiException
582
     * @throws Model\Exception\UnknownException
583
     */
584 View Code Duplication
    public function webHostReport(array $params) {
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...
585
586
        if (empty($params['lastResultNo'])) {
587
            $params['lastResultNo'] = 10;
588
        }
589
590
        // Response is always new line encoded
591
        $responseArray = $this
592
            ->communicationAdapter
593
            ->sendToApi(
594
                self::COMODO_WEB_HOST_REPORT,
595
                $params,
596
                CommunicationAdapter::RESPONSE_URL_ENCODED
597
            );
598
        if ($responseArray['error_code'] == 0) {
599
            $result = new WebHostReportResult();
600
            $result->importEntries($responseArray);
0 ignored issues
show
Bug introduced by
It seems like $responseArray defined by $this->communicationAdap...::RESPONSE_URL_ENCODED) on line 591 can also be of type boolean; however, Checkdomain\Comodo\Model...Result::importEntries() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
601
            return $result;
602
        } else {
603
            throw $this->createException($responseArray);
604
        }
605
    }
606
607
    /**
608
     * Function to enter the DCV code, coming from DCV E-Mail
609
     *
610
     * @param array $params
611
     *
612
     * @return bool
613
     * @throws Model\Exception\UnknownException
614
     * @throws Model\Exception\ArgumentException
615
     */
616
    public function enterDCVCode(array $params)
617
    {
618
        // Check parameters
619
        if (!isset($params['dcvCode'])) {
620
            throw new ArgumentException(-3, 'Please provide an order-number', 'dcvCode', '');
621
        }
622
623
        if (!isset($params['orderNumber'])) {
624
            throw new ArgumentException(-3, 'Please provide an order-number', 'orderNumber', '');
625
        }
626
627
        // this is not a official request, so we need to use the website
628
        $responseString = $this
629
            ->communicationAdapter
630
            ->sendToWebsite(self::COMODO_DCV_CODE_URL, $params);
631
632
        // Decode answer from website
633
        if (stristr($responseString, 'You have entered the correct Domain Control Validation code') !== false) {
634
            return true;
635
        } elseif (stristr($responseString, 'the certificate has already been issued') !== false) {
636
            throw new ArgumentException(-104, 'The certificate has already been issued', 'certificate', $responseString);
637
        } elseif (stristr($responseString, 'Invalid Validation Code!') !== false) {
638
            throw new ArgumentException(-103, 'Invalid Validation Code', 'validation-code', $responseString);
639
        } else {
640
            throw new UnknownException(99, 'UnknownException', $responseString);
641
        }
642
    }
643
644
    /**
645
     * @param string   $domainName
646
     * @param null     $orderNumbers
647
     * @param \Closure $callbackFunction
648
     *
649
     * @return array
650
     */
651
    public function getMails($domainName, $orderNumbers = null, \Closure $callbackFunction = null)
652
    {
653
        $orList    = ' OR ';
654
        $whereList = ' BODY "'.$domainName.'"';
655
        $whereList .= ' SUBJECT "'.$domainName.'"';
656
657
        if (is_array($orderNumbers)) {
658
            foreach ($orderNumbers as $orderNumber) {
659
                $orList .= ' OR OR ';
660
                $whereList .= ' BODY "'.$orderNumber.'"';
661
                $whereList .= ' SUBJECT "'.$orderNumber.'"';
662
            }
663
        }
664
665
        $search = $orList.' '.$whereList;
666
667
        return $this
668
            ->imapHelper
669
            ->fetchMails($this->imapAdapter, $search, false, false, $callbackFunction);
670
    }
671
672
    /**
673
     * @param bool     $markProcessed
674
     * @param \Closure $callbackFunction
675
     *
676
     * @return array
677
     */
678
    public function getUnprocessedMails($markProcessed = true, \Closure $callbackFunction = null)
679
    {
680
        $search = ' NOT KEYWORD "'.ImapHelper::PROCESSED_FLAG.'"';
681
682
        return $this
683
            ->imapHelper
684
            ->fetchMails(
685
                $this->imapAdapter,
686
                $search,
687
                $markProcessed,
688
                true,
689
                $callbackFunction
690
            );
691
    }
692
693
    /**
694
     * Function to create an exception for API errorcodes
695
     *
696
     * @param array|mixed $responseArray
697
     *
698
     * @return AccountException|ArgumentException|CSRException|RequestException|UnknownApiException|UnknownException
699
     *
700
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
701
     */
702
    protected function createException($responseArray)
703
    {
704
        if (is_array($responseArray) === false) {
705
            return new UnknownException(
706
                0,
707
                'Internal error',
708
                $responseArray['responseString']
709
            );
710
        }
711
712
        switch ($responseArray['errorCode']) {
713
            case -1: // Not using https:
714
            case -17: // Wrong HTTP-method
715
                return new RequestException(
716
                    $responseArray['errorCode'],
717
                    $responseArray['errorMessage'],
718
                    $responseArray['responseString']
719
                );
720
721
            case -2: // unrecognized argument
722
            case -3: // missing argument
723
            case -4: // invalid argument
724
            case -7: // invalid ISO Country
725
            case -18: // Name = Fully-Qualified Domain Name
726
            case -35: // Name = = IP
727
            case -19: // Name = = Accessible IP
728
                return new ArgumentException(
729
                    $responseArray['errorCode'],
730
                    $responseArray['errorMessage'],
731
                    ((isset($responseArray['errorItem'])) ? $responseArray['errorItem'] : null),
732
                    $responseArray['responseString']
733
                );
734
735
            case -16: // Permission denied
736
            case -15: // insufficient credits
737
                return new AccountException(
738
                    $responseArray['errorCode'],
739
                    $responseArray['errorMessage'],
740
                    $responseArray['responseString']
741
                );
742
743
            case -5: // contains wildcard
744
            case -6: // no wildcard, but must have
745
            case -8: // missing field
746
            case -9: // base64 decode exception
747
            case -10: // decode exception
748
            case -11: // unsupported algorithm
749
            case -12: // invalid signature
750
            case -13: // unsupported key size
751
            case -20: // Already rejected / Order relevated
752
            case -21: // Already revoked
753
            case -26: // current being issued
754
            case -40: // key compromised
755
                return new CSRException(
756
                    $responseArray['errorCode'],
757
                    $responseArray['errorMessage'],
758
                    $responseArray['responseString']
759
                );
760
761
            case -14:
762
                return new UnknownApiException(
763
                    $responseArray['errorCode'],
764
                    $responseArray['errorMessage'],
765
                    $responseArray['responseString']
766
                );
767
768
            default:
769
                return new UnknownException(
770
                    $responseArray['errorCode'],
771
                    $responseArray['errorMessage'],
772
                    $responseArray['responseString']
773
                );
774
        }
775
    }
776
777
    /**
778
     * @param CollectSslResult $object
779
     * @param array            $arr
780
     * @param array            $timestampFields
781
     *
782
     * @return $this
783
     */
784
    protected function fill(CollectSslResult $object, array $arr, array $timestampFields = array())
785
    {
786
        foreach ($arr as $key => $value) {
787
            if (in_array($key, $timestampFields)) {
788
                $value = new \DateTime('@'.$value);
789
            }
790
791
            $function = 'set'.ucfirst($key);
792
793
            // For example setErrorCode does not exists, so check before
794
            if (method_exists($object, $function)) {
795
                call_user_func(array($object, $function), $value);
796
            }
797
        }
798
799
        return $this;
800
    }
801
802
    /**
803
     * @param string $url
804
     * @param array  $params
805
     * @param int    $type
806
     *
807
     * @return bool
808
     * @throws AccountException
809
     * @throws ArgumentException
810
     * @throws CSRException
811
     * @throws RequestException
812
     * @throws UnknownApiException
813
     * @throws UnknownException
814
     */
815
    protected function sendBooleanRequest($url, array $params, $type)
816
    {
817
        // Response is always url encoded
818
        $responseArray = $this
819
            ->communicationAdapter
820
            ->sendToApi(
821
                $url,
822
                $params,
823
                $type
824
            );
825
826
        if ($responseArray['errorCode'] == 0) {
827
            return true;
828
        } else {
829
            throw $this->createException($responseArray);
830
        }
831
    }
832
}
833