Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
luuhoangnam committed Mar 20, 2015
1 parent 983d3b7 commit aa0be17
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
11 changes: 3 additions & 8 deletions src/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ class Comment extends Object
/**
* Relation to profile who make this comment
*
* @param string $profile Profile class
* @param string $type Profile class
*
* @return EdgeOut
*/
public function owner($profile = null)
public function owner($type = null)
{
if ( ! is_null($profile))
if ( ! (new $profile) instanceof Profile)
throw new \InvalidArgumentException("[{$profile}] class must be inheritance from Namest\\Facebook\\Profile");

if (is_null($profile))
$profile = Profile::class;
$profile = $this->makeProfileFromClassName($type);

return $this->belongsTo($profile, 'LEAVE', false, Edge::OUT);
}
Expand Down
17 changes: 17 additions & 0 deletions src/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,4 +869,21 @@ public function deleteNode()

return $node->delete();
}

/**
* @param string $profile
*
* @return string
*/
protected function makeProfileFromClassName($profile = null)
{
if ( ! is_null($profile))
if ( ! (new $profile) instanceof Profile)
throw new \InvalidArgumentException("[{$profile}] class must be inheritance from Namest\\Facebook\\Profile");

if (is_null($profile))
$profile = Profile::class;

return $profile;
}
}
11 changes: 3 additions & 8 deletions src/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ class Photo extends Object
];

/**
* @param string $profile Profile class
* @param string $type Profile class
*
* @return EdgeOut
*/
public function uploader($profile = null)
public function uploader($type = null)
{
if ( ! is_null($profile))
if ( ! (new $profile) instanceof Profile)
throw new \InvalidArgumentException("[{$profile}] class must be inheritance from Namest\\Facebook\\Profile");

if (is_null($profile))
$profile = Profile::class;
$profile = $this->makeProfileFromClassName($type);

return $this->belongsTo($profile, 'UPLOADED', null, Edge::OUT);
}
Expand Down
11 changes: 3 additions & 8 deletions src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,13 @@ class Post extends Object
];

/**
* @param string $profile Profile class
* @param string $type Profile class
*
* @return EdgeOut
*/
public function publisher($profile = null)
public function publisher($type = null)
{
if ( ! is_null($profile))
if ( ! (new $profile) instanceof Profile)
throw new \InvalidArgumentException("[{$profile}] class must be inheritance from Namest\\Facebook\\Profile");

if (is_null($profile))
$profile = Profile::class;
$profile = $this->makeProfileFromClassName($type);

return $this->belongsTo($profile, 'PUBLISHED', null, Edge::OUT);
}
Expand Down

0 comments on commit aa0be17

Please sign in to comment.