Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 3f6450b

Browse files
committed
Merge pull request #192 from symfony-cmf/menunodebase
cleanup return values and relax the addChild method
2 parents 9ab067f + 7297c41 commit 3f6450b

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

Doctrine/Phpcr/Menu.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
class Menu extends ModelMenu implements HierarchyInterface
1919
{
2020
/**
21-
* Set the parent of this menu node
21+
* Set the parent of this menu.
2222
*
23-
* @param $parent MenuNode - Parent node
23+
* @param object $parent A mapped document.
2424
*
25-
* @return MenuNode - this instance
25+
* @return Menu - this instance
2626
*/
2727
public function setParentDocument($parent)
2828
{
@@ -42,10 +42,10 @@ public function getParentDocument()
4242
/**
4343
* Convenience method to set parent and name at the same time.
4444
*
45-
* @param $parent MenuNode
46-
* @param $name string
45+
* @param object $parent A mapped object.
46+
* @param string $name
4747
*
48-
* @return MenuNode - this instance
48+
* @return Menu - this instance
4949
*/
5050
public function setPosition($parent, $name)
5151
{
@@ -60,11 +60,13 @@ public function setPosition($parent, $name)
6060
*
6161
* @param ModelMenuNode $child
6262
*
63-
* @return MenuNode - The newly added child node.
63+
* @return ModelMenuNode - The newly added child node.
6464
*/
6565
public function addChild(ModelMenuNode $child)
6666
{
67-
$child->setParentObject($this);
67+
if ($child instanceof MenuNode) {
68+
$child->setParentObject($this);
69+
}
6870

6971
return parent::addChild($child);
7072
}

Doctrine/Phpcr/MenuNode.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
class MenuNode extends ModelMenuNode implements HierarchyInterface
1818
{
1919
/**
20-
* Set the parent of this menu node
20+
* Set the parent of this menu node.
2121
*
22-
* @param $parent MenuNode - Parent node
22+
* @param object $parent A mapped document.
2323
*
2424
* @return MenuNode - this instance
2525
*/
@@ -29,7 +29,7 @@ public function setParentDocument($parent)
2929
}
3030

3131
/**
32-
* Returns the parent of this menu node
32+
* Returns the parent of this menu node.
3333
*
3434
* @return object
3535
*/
@@ -41,8 +41,8 @@ public function getParentDocument()
4141
/**
4242
* Convenience method to set parent and name at the same time.
4343
*
44-
* @param $parent MenuNode
45-
* @param $name string
44+
* @param object $parent A mapped document.
45+
* @param string $name
4646
*
4747
* @return MenuNode - this instance
4848
*/
@@ -57,13 +57,15 @@ public function setPosition($parent, $name)
5757
/**
5858
* Add a child menu node, automatically setting the parent node.
5959
*
60-
* @param MenuNode $child
60+
* @param ModelMenuNode $child
6161
*
62-
* @return MenuNode - The newly added child node.
62+
* @return ModelMenuNode - The newly added child node.
6363
*/
6464
public function addChild(ModelMenuNode $child)
6565
{
66-
$child->setParentObject($this);
66+
if ($child instanceof MenuNode) {
67+
$child->setParentObject($this);
68+
}
6769

6870
return parent::addChild($child);
6971
}

Model/MenuNodeBase.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Doctrine\Common\Collections\ArrayCollection;
1515
use Doctrine\Common\Collections\Collection;
1616
use Knp\Menu\NodeInterface;
17-
use Symfony\Cmf\Bundle\CoreBundle\Model\ChildInterface;
1817

1918
/**
2019
* This is a persistable implementation of the KnpMenu
@@ -161,7 +160,7 @@ public function getId()
161160
*
162161
* @param $id string
163162
*
164-
* @return MenuNode - this instance
163+
* @return MenuNodeBase - this instance
165164
*/
166165
public function setId($id)
167166
{
@@ -183,7 +182,7 @@ public function getName()
183182
*
184183
* @param string $name
185184
*
186-
* @return MenuNode - this instance
185+
* @return MenuNodeBase - this instance
187186
*/
188187
public function setName($name)
189188
{
@@ -207,7 +206,7 @@ public function getLabel()
207206
*
208207
* @param $label string
209208
*
210-
* @return MenuNode - this instance
209+
* @return MenuNodeBase - this instance
211210
*/
212211
public function setLabel($label)
213212
{
@@ -231,7 +230,7 @@ public function getUri()
231230
*
232231
* @param $uri string
233232
*
234-
* @return MenuNode - this instance
233+
* @return MenuNodeBase - this instance
235234
*/
236235
public function setUri($uri)
237236
{
@@ -255,7 +254,7 @@ public function getRoute()
255254
*
256255
* @param $route string - name of route
257256
*
258-
* @return MenuNode - this instance
257+
* @return MenuNodeBase - this instance
259258
*/
260259
public function setRoute($route)
261260
{
@@ -279,7 +278,7 @@ public function getAttributes()
279278
*
280279
* @param $attributes array
281280
*
282-
* @return MenuNode - this instance
281+
* @return MenuNodeBase - this instance
283282
*/
284283
public function setAttributes(array $attributes)
285284
{
@@ -311,7 +310,7 @@ public function getAttribute($name, $default = null)
311310
* @param string $name attribute name
312311
* @param string $value attribute value
313312
*
314-
* @return MenuNode - this instance
313+
* @return MenuNodeBase - this instance
315314
*/
316315
public function setAttribute($name, $value)
317316
{
@@ -335,7 +334,7 @@ public function getChildrenAttributes()
335334
*
336335
* @param array $attributes
337336
*
338-
* @return MenuNode - this instance
337+
* @return MenuNodeBase - this instance
339338
*/
340339
public function setChildrenAttributes(array $attributes)
341340
{
@@ -348,7 +347,7 @@ public function setChildrenAttributes(array $attributes)
348347
* Get all child menu nodes of this menu node. This will filter out all
349348
* non-NodeInterface children.
350349
*
351-
* @return MenuNode[]
350+
* @return NodeInterface[]
352351
*/
353352
public function getChildren()
354353
{
@@ -368,7 +367,7 @@ public function getChildren()
368367
*
369368
* @param MenuNode $child
370369
*
371-
* @return MenuNode - The newly added child node.
370+
* @return MenuNode The newly added child node.
372371
*/
373372
public function addChild(MenuNode $child)
374373
{
@@ -381,6 +380,8 @@ public function addChild(MenuNode $child)
381380
* Remove a child menu node
382381
*
383382
* @param MenuNode $child
383+
*
384+
* @return MenuNodeBase $this
384385
*/
385386
public function removeChild(MenuNode $child)
386387
{
@@ -402,7 +403,7 @@ public function getRouteParameters()
402403
*
403404
* @param array $routeParameters
404405
*
405-
* @return MenuNode - this instance
406+
* @return MenuNodeBase - this instance
406407
*/
407408
public function setRouteParameters($routeParameters)
408409
{
@@ -426,7 +427,7 @@ public function getExtras()
426427
*
427428
* @param array $extras
428429
*
429-
* @return MenuNode - this instance
430+
* @return MenuNodeBase - this instance
430431
*/
431432
public function setExtras(array $extras)
432433
{
@@ -450,7 +451,7 @@ public function getLinkAttributes()
450451
*
451452
* @param array $linkAttributes
452453
*
453-
* @return MenuNode - this instance
454+
* @return MenuNodeBase - this instance
454455
*/
455456
public function setLinkAttributes($linkAttributes)
456457
{
@@ -474,7 +475,7 @@ public function getLabelAttributes()
474475
*
475476
* @param array $labelAttributes
476477
*
477-
* @return MenuNode - this instance
478+
* @return MenuNodeBase - this instance
478479
*/
479480
public function setLabelAttributes($labelAttributes)
480481
{
@@ -498,7 +499,7 @@ public function getDisplay()
498499
*
499500
* @param boolean $display
500501
*
501-
* @return MenuNode - this instance
502+
* @return MenuNodeBase - this instance
502503
*/
503504
public function setDisplay($display)
504505
{
@@ -522,7 +523,7 @@ public function getDisplayChildren()
522523
*
523524
* @param boolean $displayChildren
524525
*
525-
* @return MenuNode - this instance
526+
* @return MenuNodeBase - this instance
526527
*/
527528
public function setDisplayChildren($displayChildren)
528529
{
@@ -547,7 +548,7 @@ public function getRouteAbsolute()
547548
*
548549
* @param boolean $routeAbsolute
549550
*
550-
* @return MenuNode - this instance
551+
* @return MenuNodeBase - this instance
551552
*/
552553
public function setRouteAbsolute($routeAbsolute)
553554
{

0 commit comments

Comments
 (0)