etrepat/baum — pull request #26 by ziadoz (2013-11-13 21:01:53+00:00)
Title: Prevent impossible moves to the left or right.

I've noticed an error occurs when performing a `moveLeft()` or `moveRight()` on a node that can't possibly move in that direction.

```php
Fatal error: Call to a member function insideSubtree() on a non-object in /vendor/baum/baum/src/Baum/Move.php on line 208
```

Right now I'm using a custom check to prevent the error from occurring (see below), but I suspect a `MoveNotPossibleException` should be thrown (which in my case I could catch and discard, since I don't care if the move fails).

```php
$category = Category::find($id);
$parent = $category->parent()->first();

switch ($direction) {
case 'left':
if ($category->lft > $parent->lft + 1) {
$category->moveLeft();
}
break;

case 'right':
if ($category->rgt < $parent->rgt - 1) {
$category->moveRight();
}
break;
}
```

I've made a few quick changes to the `Move` class, that will trigger the appropriate exceptions, however I'm not familiar enough with the codebase, or nested sets, to know if this is the best possible solution.