File tree Expand file tree Collapse file tree 5 files changed +67
-0
lines changed Expand file tree Collapse file tree 5 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99### Added
1010
1111* Added facades for ` CollectionDocumentBuilder ` , ` ItemDocumentBuilder ` , ` ItemHydrator ` and ` TypeMapper ` .
12+ * Added ` hasType ` , ` hasAttributes ` and ` hasRelationships ` to ` ItemInterface ` .
1213
1314### Changed
1415
Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ public function setId(? string $id);
3434 */
3535 public function getType (): string ;
3636
37+ /**
38+ * @return bool
39+ */
40+ public function hasType (): bool ;
41+
3742 /**
3843 * @param string $type
3944 *
@@ -97,6 +102,16 @@ public function getAttribute($key);
97102 */
98103 public function setAttribute ($ key , $ value );
99104
105+ /**
106+ * @return bool
107+ */
108+ public function hasAttributes (): bool ;
109+
110+ /**
111+ * @return bool
112+ */
113+ public function hasRelationships (): bool ;
114+
100115 /**
101116 * @return array
102117 */
Original file line number Diff line number Diff line change @@ -223,6 +223,14 @@ public function canBeIncluded(): bool
223223 return true ;
224224 }
225225
226+ /**
227+ * @return bool
228+ */
229+ public function hasRelationships (): bool
230+ {
231+ return !empty ($ this ->getRelationships ());
232+ }
233+
226234 /**
227235 * @param string $key
228236 *
@@ -261,6 +269,14 @@ public function hasAttribute($key): bool
261269 return array_key_exists ($ key , $ this ->attributes );
262270 }
263271
272+ /**
273+ * @return bool
274+ */
275+ public function hasAttributes (): bool
276+ {
277+ return !empty ($ this ->toArray ());
278+ }
279+
264280 /**
265281 * @param string $key
266282 * @param mixed $value
Original file line number Diff line number Diff line change @@ -28,4 +28,12 @@ public function getType(): string
2828 {
2929 return $ this ->type ;
3030 }
31+
32+ /**
33+ * @return bool
34+ */
35+ public function hasType (): bool
36+ {
37+ return (bool )$ this ->type ;
38+ }
3139}
Original file line number Diff line number Diff line change @@ -138,6 +138,19 @@ public function it_returns_attributes()
138138 $ this ->assertEquals ($ this ->attributes , $ item ->getAttributes ());
139139 }
140140
141+ /**
142+ * @test
143+ */
144+ public function it_returns_a_boolean_indicating_if_it_has_attributes ()
145+ {
146+ $ item = new Item ();
147+ $ this ->assertFalse ($ item ->hasAttributes ());
148+
149+ $ item ->fill ($ this ->attributes );
150+
151+ $ this ->assertTrue ($ item ->hasAttributes ());
152+ }
153+
141154 /**
142155 * @test
143156 */
@@ -209,6 +222,20 @@ public function it_can_get_all_relations()
209222 ], $ relations );
210223 }
211224
225+ /**
226+ * @test
227+ */
228+ public function it_returns_a_boolean_indicating_if_it_has_relationships ()
229+ {
230+ $ masterItem = new MasterItem ();
231+ $ this ->assertFalse ($ masterItem ->hasRelationships ());
232+
233+ $ childItem = (new ChildItem ())->setId (1 );
234+ $ masterItem ->child ()->associate ($ childItem );
235+
236+ $ this ->assertTrue ($ masterItem ->hasRelationships ());
237+ }
238+
212239 /**
213240 * @test
214241 */
You can’t perform that action at this time.
0 commit comments