Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Simplify code complexity & fix few issues round 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Omranic committed Jun 16, 2016
1 parent ba87e29 commit 4de4c2f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .codeclimate.yml
Expand Up @@ -19,6 +19,8 @@ engines:
enabled: false
Naming/ShortVariable:
enabled: false
CleanCode/ElseExpression:
enabled: false
ratings:
paths:
- "**.inc"
Expand Down
28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -26,8 +26,8 @@
- [EloquentRepository](#eloquentrepository)
- [`setContainer()`, `getContainer()`](#setcontainer-getcontainer)
- [`setRepositoryId()`, `getRepositoryId()`](#setrepositoryid-getrepositoryid)
- [`setCacheStatus()`, `getCacheStatus()`](#setcachestatus-getcachestatus)
- [`setCacheClearStatus()`, `getCacheClearStatus()`](#setcacheclearstatus-getcacheclearstatus)
- [`enableCache()`, `isCacheEnabled()`](#enablecache-iscacheenabled)
- [`enableCacheClear()`, `isCacheClearEnabled()`](#enablecacheclear-iscacheclearenabled)
- [`addGlobalScope()`, `withoutGlobalScopes()`](#addglobalscope-withoutglobalscopes)
- [`retrieveModel()`](#retrievemodel)
- [`forgetCache()`](#forgetcache)
Expand Down Expand Up @@ -277,26 +277,26 @@ $repository->setRepositoryId('rinvex.repository.entity');
$repositoryId = $repository->getRepositoryId();
```

#### `setCacheStatus()`, `getCacheStatus()`
#### `enableCache()`, `isCacheEnabled()`

The `setCacheStatus` method sets the repository cache status, while `getCacheStatus` returns it:
The `enableCache` method enables repository cache, while `isCacheEnabled` determines it's state:
```php
// Set the repository cache status
$repository->setCacheStatus(true);
// Enable repository cache
$repository->enableCache(true);

// Get the repository cache status
$repository->getCacheStatus();
// Determine if repository cache is enabled
$repository->isCacheEnabled();
```

#### `setCacheClearStatus()`, `getCacheClearStatus()`
#### `enableCacheClear()`, `isCacheClearEnabled()`

The `setCacheClearStatus` method sets the repository cache clear status, while `getCacheClearStatus` returns it:
The `enableCacheClear` method enables repository cache clear, while `isCacheClearEnabled` determines it's state:
```php
// Set the repository cache clear status
$repository->setCacheClearStatus(true);
// Enable repository cache clear
$repository->enableCacheClear(true);

// Get the repository cache clear status
$repository->getCacheClearStatus();
// Determine if repository cache clear is enabled
$repository->isCacheClearEnabled();
```

#### `addGlobalScope()`, `withoutGlobalScopes()`
Expand Down
18 changes: 9 additions & 9 deletions src/Contracts/RepositoryContract.php
Expand Up @@ -55,36 +55,36 @@ public function setRepositoryId($repositoryId);
public function getRepositoryId();

/**
* Set the repository cache status.
* Enable repository cache.
*
* @param bool $status
*
* @return $this
*/
public function setCacheStatus($status);
public function enableCache($status = true);

/**
* Get the repository cache status.
* Determine if repository cache is enabled.
*
* @return bool
*/
public function getCacheStatus();
public function isCacheEnabled();

/**
* Set the repository cache clear status.
* Enable repository cache clear.
*
* @param bool $status
*
* @return $this
*/
public function setCacheClearStatus($status);
public function enableCacheClear($status);

/**
* Get the repository cache clear status.
* Determine if repository cache clear is enabled.
*
* @return bool
*/
public function getCacheClearStatus();
public function isCacheClearEnabled();

/**
* Retrieve the repository model.
Expand Down Expand Up @@ -160,7 +160,7 @@ public function findAll($columns = ['*'], $with = []);
/**
* Paginate all entities.
*
* @param int $perPage
* @param int|null $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
Expand Down
6 changes: 3 additions & 3 deletions src/Listeners/RepositoryEventListener.php
Expand Up @@ -44,7 +44,7 @@ public function entityCreated(RepositoryContract $repository, $entity)
{
$clearOn = $repository->getContainer('config')->get('rinvex.repository.cache.clear_on');

if ($repository->getCacheClearStatus() && in_array('create', $clearOn)) {
if ($repository->isCacheClearEnabled() && in_array('create', $clearOn)) {
$repository->forgetCache();
}
}
Expand All @@ -61,7 +61,7 @@ public function entityUpdated(RepositoryContract $repository, $entity)
{
$clearOn = $repository->getContainer('config')->get('rinvex.repository.cache.clear_on');

if ($repository->getCacheClearStatus() && in_array('update', $clearOn)) {
if ($repository->isCacheClearEnabled() && in_array('update', $clearOn)) {
$repository->forgetCache();
}
}
Expand All @@ -78,7 +78,7 @@ public function entityDeleted(RepositoryContract $repository, $entity)
{
$clearOn = $repository->getContainer('config')->get('rinvex.repository.cache.clear_on');

if ($repository->getCacheClearStatus() && in_array('delete', $clearOn)) {
if ($repository->isCacheClearEnabled() && in_array('delete', $clearOn)) {
$repository->forgetCache();
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/Repositories/BaseRepository.php
Expand Up @@ -43,25 +43,25 @@ abstract class BaseRepository implements RepositoryContract
protected $repositoryId;

/**
* The repository cache status.
* Indicate if the repository cache is enabled.
*
* @var bool
*/
protected $cacheEnabled = true;

/**
* The repository cache clear status.
* Indicate if the repository cache clear is enabled.
*
* @var bool
*/
protected $cacheClear = true;
protected $cacheClearEnabled = true;

/**
* Execute given callback and cache result set.
*
* @param string $class
* @param string $method
* @param string $cacheKey
* @param string $hash
* @param \Closure $closure
*
* @return mixed
Expand Down Expand Up @@ -136,51 +136,51 @@ public function getRepositoryId()
}

/**
* Set the repository cache status.
* Enable repository cache.
*
* @param bool $status
*
* @return $this
*/
public function setCacheStatus($status)
public function enableCache($status = true)
{
$this->cacheEnabled = (bool) $status;
$this->cacheEnabled = $status;

return $this;
}

/**
* Get the repository cache status.
* Determine if repository cache is enabled.
*
* @return bool
*/
public function getCacheStatus()
public function isCacheEnabled()
{
return $this->cacheEnabled;
}

/**
* Set the repository cache clear status.
* Enable repository cache clear.
*
* @param bool $status
*
* @return $this
*/
public function setCacheClearStatus($status)
public function enableCacheClear($status = true)
{
$this->cacheClear = (bool) $status;
$this->cacheClearEnabled = $status;

return $this;
}

/**
* Get the repository cache clear status.
* Determine if repository cache clear is enabled.
*
* @return bool
*/
public function getCacheClearStatus()
public function isCacheClearEnabled()
{
return $this->cacheClear;
return $this->cacheClearEnabled;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/EloquentRepository.php
Expand Up @@ -108,7 +108,7 @@ public function findAll($columns = ['*'], $with = [])
/**
* Paginate all entities.
*
* @param int $perPage
* @param int|null $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
Expand Down

0 comments on commit 4de4c2f

Please sign in to comment.