|
32 | 32 | */ |
33 | 33 | final class Attributes implements AttributesInterface |
34 | 34 | { |
35 | | - use AccessTrait; |
| 35 | + use AccessTrait; |
36 | 36 |
|
37 | | - /** |
38 | | - * @var DataContainerInterface |
39 | | - */ |
40 | | - protected $container; |
| 37 | + /** |
| 38 | + * @var DataContainerInterface |
| 39 | + */ |
| 40 | + protected $container; |
41 | 41 |
|
42 | | - /** |
43 | | - * @var FactoryManagerInterface |
44 | | - */ |
45 | | - protected $manager; |
| 42 | + /** |
| 43 | + * @var FactoryManagerInterface |
| 44 | + */ |
| 45 | + protected $manager; |
46 | 46 |
|
47 | | - /** |
48 | | - * Sets the manager and parent |
49 | | - * |
50 | | - * @param FactoryManagerInterface $manager The manager |
51 | | - * @param AccessInterface $parent The parent |
52 | | - */ |
53 | | - public function __construct(FactoryManagerInterface $manager, AccessInterface $parent = null) |
54 | | - { |
55 | | - $this->manager = $manager; |
| 47 | + /** |
| 48 | + * Sets the manager and parent |
| 49 | + * |
| 50 | + * @param FactoryManagerInterface $manager The manager |
| 51 | + * @param AccessInterface $parent The parent |
| 52 | + */ |
| 53 | + public function __construct(FactoryManagerInterface $manager, AccessInterface $parent = null) |
| 54 | + { |
| 55 | + $this->manager = $manager; |
56 | 56 |
|
57 | | - $this->container = new DataContainer(); |
58 | | - } |
| 57 | + $this->container = new DataContainer(); |
| 58 | + } |
59 | 59 |
|
60 | | - /** |
61 | | - * Parses the data for this element |
62 | | - * |
63 | | - * @param mixed $object The data |
64 | | - * |
65 | | - * @return self |
66 | | - * |
67 | | - * @throws ValidationException |
68 | | - */ |
69 | | - public function parse($object) |
70 | | - { |
71 | | - if ( ! is_object($object) ) |
72 | | - { |
73 | | - throw new ValidationException('Attributes has to be an object, "' . gettype($object) . '" given.'); |
74 | | - } |
| 60 | + /** |
| 61 | + * Parses the data for this element |
| 62 | + * |
| 63 | + * @param mixed $object The data |
| 64 | + * |
| 65 | + * @throws ValidationException |
| 66 | + * |
| 67 | + * @return self |
| 68 | + */ |
| 69 | + public function parse($object) |
| 70 | + { |
| 71 | + if (! is_object($object)) { |
| 72 | + throw new ValidationException('Attributes has to be an object, "' . gettype($object) . '" given.'); |
| 73 | + } |
75 | 74 |
|
76 | | - if ( property_exists($object, 'type') or property_exists($object, 'id') or property_exists($object, 'relationships') or property_exists($object, 'links') ) |
77 | | - { |
78 | | - throw new ValidationException('These properties are not allowed in attributes: `type`, `id`, `relationships`, `links`'); |
79 | | - } |
| 75 | + if (property_exists($object, 'type') or property_exists($object, 'id') or property_exists($object, 'relationships') or property_exists($object, 'links')) { |
| 76 | + throw new ValidationException('These properties are not allowed in attributes: `type`, `id`, `relationships`, `links`'); |
| 77 | + } |
80 | 78 |
|
81 | | - $object_vars = get_object_vars($object); |
| 79 | + $object_vars = get_object_vars($object); |
82 | 80 |
|
83 | | - if ( count($object_vars) === 0 ) |
84 | | - { |
85 | | - return $this; |
86 | | - } |
| 81 | + if (count($object_vars) === 0) { |
| 82 | + return $this; |
| 83 | + } |
87 | 84 |
|
88 | | - foreach ($object_vars as $name => $value) |
89 | | - { |
90 | | - $this->container->set($name, $value); |
91 | | - } |
| 85 | + foreach ($object_vars as $name => $value) { |
| 86 | + $this->container->set($name, $value); |
| 87 | + } |
92 | 88 |
|
93 | | - return $this; |
94 | | - } |
| 89 | + return $this; |
| 90 | + } |
95 | 91 |
|
96 | | - /** |
97 | | - * Get a value by the key of this object |
98 | | - * |
99 | | - * @param string $key The key of the value |
100 | | - * @return mixed The value |
101 | | - */ |
102 | | - public function get($key) |
103 | | - { |
104 | | - try |
105 | | - { |
106 | | - return $this->container->get($key); |
107 | | - } |
108 | | - catch (AccessException $e) |
109 | | - { |
110 | | - throw new AccessException('"' . $key . '" doesn\'t exist in this object.'); |
111 | | - } |
112 | | - } |
| 92 | + /** |
| 93 | + * Get a value by the key of this object |
| 94 | + * |
| 95 | + * @param string $key The key of the value |
| 96 | + * |
| 97 | + * @return mixed The value |
| 98 | + */ |
| 99 | + public function get($key) |
| 100 | + { |
| 101 | + try { |
| 102 | + return $this->container->get($key); |
| 103 | + } catch (AccessException $e) { |
| 104 | + throw new AccessException('"' . $key . '" doesn\'t exist in this object.'); |
| 105 | + } |
| 106 | + } |
113 | 107 | } |
0 commit comments