WSException::getAllProperties()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
* Vtiger Web Services PHP Client Library
4
*
5
* The MIT License (MIT)
6
*
7
* Copyright (c) 2015, Zhmayev Yaroslav <[email protected]>
8
*
9
* Permission is hereby granted, free of charge, to any person obtaining a copy
10
* of this software and associated documentation files (the "Software"), to deal
11
* in the Software without restriction, including without limitation the rights
12
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
* copies of the Software, and to permit persons to whom the Software is
14
* furnished to do so, subject to the following conditions:
15
*
16
* The above copyright notice and this permission notice shall be included in
17
* all copies or substantial portions of the Software.
18
*
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
* THE SOFTWARE.
26
*
27
* @author    Zhmayev Yaroslav <[email protected]>
28
* @copyright 2015-2016 Zhmayev Yaroslav
29
* @license   The MIT License (MIT)
30
*/
31
32
namespace Salaros\Vtiger\VTWSCLib;
33
34
use \Exception;
35
use \IteratorAggregate;
36
37
/**
38
* Vtiger Web Services PHP Client Exception class
39
*
40
* Class WSException
41
* @package Salaros\Vtiger\VTWSCLib
42
*/
43
class WSException extends Exception implements IteratorAggregate
44
{
45
    protected $message;
46
    protected $code;
47
    
48
    /**
49
     * Redefine the exception so message isn't optional
50
     * @access public
51
     */
52
    public function __construct($message, $code = 'UNKNOWN', Exception $previous = null)
53
    {
54
        $this->message = $message;
55
        $this->code = $code;
56
        
57
        // make sure everything is assigned properly
58
        parent::__construct($this->message, 0, $previous);
59
    }
60
    
61
    /**
62
     * Custom string representation of object
63
     * @access public
64
     * @return string A custom string representation of exception
65
     */
66
    public function __toString()
67
    {
68
        return __CLASS__.": [{$this->code}]: {$this->message}\n";
69
    }
70
    
71
    /**
72
     * Retrieve an external iterator
73
     * @access public
74
     * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
75
     * @return \Traversable An instance of an object implementing \Traversable
76
     */
77
    public function getIterator()
78
    {
79
        $properties = $this->getAllProperties();
80
        $iterator = new \ArrayIterator($properties);
81
        
82
        return $iterator;
83
    }
84
    
85
    /**
86
     * Gets all the properties of the object
87
     * @access public
88
     * @return array Array of properties
89
     */
90
    private function getAllProperties()
91
    {
92
        $allProperties = get_object_vars($this);
93
        $properties = array();
94
        foreach ($allProperties as $fullName => $value) {
95
            $fullNameComponents = explode("\0", $fullName);
96
            $propertyName = array_pop($fullNameComponents);
97
            if ($propertyName && isset($value)) {
98
                $properties[ $propertyName ] = $value;
99
            }
100
        }
101
        
102
        return $properties;
103
    }
104
}
105