ZohoCRMUpdateException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 35
rs 10
c 4
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 2
A getFailedBeans() 0 4 1
1
<?php
2
3
namespace Wabel\Zoho\CRM\Exception;
4
5
use Wabel\Zoho\CRM\ZohoBeanInterface;
6
7
/**
8
 * Zoho CRM Exception triggered when an update fails. For instance, the ZohoID passed for a bean
9
 * does not exist in Zoho (because the record was deleted).
10
 */
11
class ZohoCRMUpdateException extends ZohoCRMException
12
{
13
    private $failedBeans;
14
    private $errorMessage = 'Some beans could not be updated in Zoho.';
15
16
    /**
17
     * @param \SplObjectStorage $failedBeans Key: the bean that failed. Value: the associated exception.
18
     */
19
    public function __construct(\SplObjectStorage $failedBeans)
20
    {
21
        $this->failedBeans = $failedBeans;
22
23
        /*
24
         * Building the error message by iterating the SplObjectStorage
25
         * @var ZohoBeanInterface $bean
26
         * @var ZohoCRMException $error
27
         */
28
        foreach ($this->failedBeans as $key) {
29
            $this->errorMessage .= "\n".'['.$this->getFailedBeans()->current()->getZohoId().'] '.$this->getFailedBeans()->getInfo()->getMessage();
30
        }
31
32
        // Repositioning the pointer at the beginning
33
        $this->failedBeans->rewind();
34
35
        parent::__construct($this->errorMessage);
36
    }
37
38
    /**
39
     * @return \SplObjectStorage Key: the bean that failed. Value: the associated exception.
40
     */
41
    public function getFailedBeans()
42
    {
43
        return $this->failedBeans;
44
    }
45
}
46