mirror of
https://github.com/michaelachrisco/ReadOnlyTraitLaravel.git
synced 2024-11-01 05:43:22 -07:00
Merge pull request #17 from michaelachrisco/lint
Add PHP-CS-Fixer to linting process and Travis. Refactor thrown class into its own method.
This commit is contained in:
commit
ebffb0b7f9
5 changed files with 69 additions and 60 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ composer.phar
|
||||||
composer.lock
|
composer.lock
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/.idea
|
/.idea
|
||||||
|
.php_cs.cache
|
||||||
|
|
|
@ -5,7 +5,6 @@ php:
|
||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
- 7.1
|
- 7.1
|
||||||
- hhvm
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
|
@ -22,4 +21,6 @@ install:
|
||||||
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-stable; fi
|
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-stable; fi
|
||||||
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-lowest --prefer-stable; fi
|
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-source --no-interaction --prefer-lowest --prefer-stable; fi
|
||||||
|
|
||||||
script: ./vendor/bin/kahlan -reporter=verbose
|
script:
|
||||||
|
- ./vendor/bin/kahlan -reporter=verbose
|
||||||
|
- ./vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix src/
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"kahlan/kahlan": "^2.4",
|
"kahlan/kahlan": "^2.4",
|
||||||
"illuminate/database": ">=5.2.0"
|
"illuminate/database": ">=5.2.0",
|
||||||
|
"friendsofphp/php-cs-fixer": "^2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace MichaelAChrisco\ReadOnly;
|
namespace MichaelAChrisco\ReadOnly;
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
class ReadOnlyException extends RuntimeException{
|
|
||||||
|
|
||||||
|
class ReadOnlyException extends \RuntimeException
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
namespace MichaelAChrisco\ReadOnly;
|
namespace MichaelAChrisco\ReadOnly;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use MichaelAChrisco\ReadOnly\ReadOnlyException;
|
use MichaelAChrisco\ReadOnly\ReadOnlyException;
|
||||||
|
|
||||||
trait ReadOnlyTrait {
|
trait ReadOnlyTrait
|
||||||
|
{
|
||||||
|
public static function readOnly($class)
|
||||||
|
{
|
||||||
|
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* throws ReadOnlyException on create
|
* throws ReadOnlyException on create
|
||||||
* @method create
|
* @method create
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static function create(array $attributes = []){
|
public static function create(array $attributes = [])
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,9 +28,9 @@ trait ReadOnlyTrait {
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static function forceCreate(array $attributes){
|
public static function forceCreate(array $attributes)
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,9 +39,9 @@ trait ReadOnlyTrait {
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function save(array $options = []){
|
public function save(array $options = [])
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,9 +51,9 @@ trait ReadOnlyTrait {
|
||||||
* @param $options
|
* @param $options
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function update(array $attributes = [], array $options = []){
|
public function update(array $attributes = [], array $options = [])
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,9 +62,9 @@ trait ReadOnlyTrait {
|
||||||
* @param array $arr
|
* @param array $arr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static function firstOrCreate(array $arr){
|
public static function firstOrCreate(array $arr)
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,9 +73,9 @@ trait ReadOnlyTrait {
|
||||||
* @param array $arr
|
* @param array $arr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static function firstOrNew(array $arr){
|
public static function firstOrNew(array $arr)
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,9 +83,9 @@ trait ReadOnlyTrait {
|
||||||
* @method delete
|
* @method delete
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function delete(){
|
public function delete()
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,9 +94,9 @@ trait ReadOnlyTrait {
|
||||||
* @param mixed $ids
|
* @param mixed $ids
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static function destroy($ids){
|
public static function destroy($ids)
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,9 +104,9 @@ trait ReadOnlyTrait {
|
||||||
* @method restore
|
* @method restore
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function restore(){
|
public function restore()
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,9 +114,9 @@ trait ReadOnlyTrait {
|
||||||
* @method forceDelete
|
* @method forceDelete
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function forceDelete(){
|
public function forceDelete()
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,9 +124,9 @@ trait ReadOnlyTrait {
|
||||||
* @method performDeleteOnModel
|
* @method performDeleteOnModel
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function performDeleteOnModel(){
|
public function performDeleteOnModel()
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,9 +134,9 @@ trait ReadOnlyTrait {
|
||||||
* @method push
|
* @method push
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function push(){
|
public function push()
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,9 +144,9 @@ trait ReadOnlyTrait {
|
||||||
* @method finishSave
|
* @method finishSave
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function finishSave(array $options){
|
public function finishSave(array $options)
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,9 +154,9 @@ trait ReadOnlyTrait {
|
||||||
* @method performUpdate
|
* @method performUpdate
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function performUpdate(Builder $query, array $options = []){
|
public function performUpdate(Builder $query, array $options = [])
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,9 +164,9 @@ trait ReadOnlyTrait {
|
||||||
* @method touch
|
* @method touch
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function touch(){
|
public function touch()
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,9 +174,9 @@ trait ReadOnlyTrait {
|
||||||
* @method insert
|
* @method insert
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function insert(){
|
public function insert()
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,8 +184,8 @@ trait ReadOnlyTrait {
|
||||||
* @method truncate
|
* @method truncate
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function truncate(){
|
public function truncate()
|
||||||
$class = get_called_class();
|
{
|
||||||
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
|
ReadOnlyTrait::readOnly(get_called_class());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue