ZohoCRMUpdateException::getFailedBeans()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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