Skip to content

Commit

Permalink
Refactoring main class
Browse files Browse the repository at this point in the history
  • Loading branch information
bissolli committed Aug 13, 2018
1 parent 842bdc9 commit e7ad541
Show file tree
Hide file tree
Showing 6 changed files with 612 additions and 0 deletions.
254 changes: 254 additions & 0 deletions src/Models/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
<?php

namespace Bissolli\TwitterScraper\Models;

class Account extends ModelAbstract
{
/**
* Name
* @var string
*/
protected $name = null;

/**
* Joined on Twitter at
* @var string
*/
protected $joinedAt = null;

/**
* Avatar url
* @var string
*/
protected $avatarUrl = null;

/**
* Cover url
* @var string
*/
protected $coverUrl = null;

/**
* Website url
* @var string
*/
protected $website = null;

/**
* Locale
* @var string
*/
protected $locale = null;

/**
* Bio filled by the user
* @var string
*/
protected $bio = null;

/**
* Number of users the user is following
* @var integer
*/
protected $followingCount = 0;

/**
* Number of followers
* @var integer
*/
protected $followersCount = 0;

/**
* Total number of tweets published by the user
* @var integer
*/
protected $tweetsCount = 0;

/**
* Total of favorites
* @var integer
*/
protected $favoritesCount = 0;

/**
* Total of lists
* @var integer
*/
protected $listsCount = 0;

/**
* Date of birth
* @var integer
*/
protected $dateOfBirth = null;

/**
* true if verified by Twitter
* @var boolean
*/
protected $isVerified = false;

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @return string
*/
public function getAvatarUrl()
{
return $this->avatarUrl;
}

/**
* @return string
*/
public function getCoverUrl()
{
return $this->coverUrl;
}

/**
* @return string
*/
public function getWebsite()
{
return $this->website;
}

/**
* @return string
*/
public function getLocale()
{
return $this->locale;
}

/**
* @return string
*/
public function getBio()
{
return $this->bio;
}

/**
* @return int
*/
public function getFollowingCount()
{
return $this->followingCount;
}

/**
* @return int
*/
public function getFollowersCount()
{
return $this->followersCount;
}

/**
* @return int
*/
public function getTweetsCount()
{
return $this->tweetsCount;
}

/**
* @return int
*/
public function getListsCount()
{
return $this->listsCount;
}

/**
* @return int
*/
public function getFavoritesCount()
{
return $this->favoritesCount;
}

/**
* @return bool
*/
public function isVerified()
{
return $this->isVerified;
}

/**
* @return int
*/
public function getDateOfBirth()
{
return $this->dateOfBirth;
}

/**
* @return string
*/
public function getJoinedAt()
{
return $this->joinedAt;
}

/**
* @param $value
* @param $prop
*/
public function initProperties($value, $prop)
{
switch ($prop) {
case 'name':
$this->name = $value;
break;
case 'joined_at':
$this->joinedAt = $value;
break;
case 'avatar_url':
$this->avatarUrl = $value;
break;
case 'cover_url':
$this->coverUrl = $value;
break;
case 'website':
$this->website = $value;
break;
case 'locale':
$this->locale = $value;
break;
case 'bio':
$this->bio = $value;
break;
case 'following_count':
$this->followingCount = $value;
break;
case 'followers_count':
$this->followersCount = $value;
break;
case 'tweets_count':
$this->tweetsCount = $value;
break;
case 'favorites_count':
$this->favoritesCount = $value;
break;
case 'lists_count':
$this->listsCount = $value;
break;
case 'date_of_birth':
$this->dateOfBirth = $value;
break;
case 'is_verified':
$this->isVerified = (bool) $value;
break;
}
}
}
56 changes: 56 additions & 0 deletions src/Models/ModelAbstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Bissolli\TwitterScraper\Models;

use ArrayAccess;
use Bissolli\TwitterScraper\Traits\ArrayLikeTrait;

abstract class ModelAbstract implements ArrayAccess, ModelInterface
{
use ArrayLikeTrait;

/**
* @param array $props
*/
protected function __construct(array $props = null)
{
$this->init($props);
}

/**
* @param array $props
*
* @return $this
*/
final protected function init(array $props)
{
foreach ($props as $prop => $value) {
$this->initProperties($value, $prop);
}

return $this;
}

/**
* @var array
*/
protected static $initPropertiesMap = [];

/**
* @return array
*/
public static function getColumns()
{
return array_keys(static::$initPropertiesMap);
}

/**
* @param array $params
*
* @return static
*/
public static function create(array $params = null)
{
return new static($params);
}
}
12 changes: 12 additions & 0 deletions src/Models/ModelInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Bissolli\TwitterScraper\Models;

interface ModelInterface
{
/**
* @param $value
* @param $prop
*/
public function initProperties($value, $prop);
}
Loading

0 comments on commit e7ad541

Please sign in to comment.