Add PHP-CS-Fixer to linting process and Travis.

This commit is contained in:
michaelachrisco 2017-03-31 11:28:20 -07:00
parent 07453dad8e
commit 5a43121592
5 changed files with 67 additions and 44 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ composer.phar
composer.lock composer.lock
.DS_Store .DS_Store
/.idea /.idea
.php_cs.cache

View file

@ -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/

View file

@ -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"
} }
} }

View file

@ -1,5 +1,6 @@
<?php <?php
namespace MichaelAChrisco\ReadOnly; namespace MichaelAChrisco\ReadOnly;
use RuntimeException;
class ReadOnlyException extends RuntimeException{} class ReadOnlyException extends \RuntimeException
{
}

View file

@ -1,13 +1,15 @@
<?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
{
static function readOnly($class){ public static function readOnly($class)
throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}"); {
} throw new ReadOnlyException("Not allowed to persist changes in read-only model {$class}");
}
/** /**
* throws ReadOnlyException on create * throws ReadOnlyException on create
@ -15,8 +17,9 @@ trait ReadOnlyTrait {
* @param array $attributes * @param array $attributes
* *
*/ */
static function create(array $attributes = []){ public static function create(array $attributes = [])
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -25,8 +28,9 @@ trait ReadOnlyTrait {
* @param array $attributes * @param array $attributes
* *
*/ */
static function forceCreate(array $attributes){ public static function forceCreate(array $attributes)
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -35,8 +39,9 @@ trait ReadOnlyTrait {
* @param array $options * @param array $options
* *
*/ */
public function save(array $options = []){ public function save(array $options = [])
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -46,8 +51,9 @@ trait ReadOnlyTrait {
* @param $options * @param $options
* *
*/ */
public function update(array $attributes = [], array $options = []){ public function update(array $attributes = [], array $options = [])
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -56,8 +62,9 @@ trait ReadOnlyTrait {
* @param array $arr * @param array $arr
* *
*/ */
static function firstOrCreate(array $arr){ public static function firstOrCreate(array $arr)
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -66,8 +73,9 @@ trait ReadOnlyTrait {
* @param array $arr * @param array $arr
* *
*/ */
static function firstOrNew(array $arr){ public static function firstOrNew(array $arr)
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -75,8 +83,9 @@ trait ReadOnlyTrait {
* @method delete * @method delete
* *
*/ */
public function delete(){ public function delete()
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -85,8 +94,9 @@ trait ReadOnlyTrait {
* @param mixed $ids * @param mixed $ids
* *
*/ */
static function destroy($ids){ public static function destroy($ids)
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -94,8 +104,9 @@ trait ReadOnlyTrait {
* @method restore * @method restore
* *
*/ */
public function restore(){ public function restore()
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -103,8 +114,9 @@ trait ReadOnlyTrait {
* @method forceDelete * @method forceDelete
* *
*/ */
public function forceDelete(){ public function forceDelete()
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -112,8 +124,9 @@ trait ReadOnlyTrait {
* @method performDeleteOnModel * @method performDeleteOnModel
* *
*/ */
public function performDeleteOnModel(){ public function performDeleteOnModel()
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -121,8 +134,9 @@ trait ReadOnlyTrait {
* @method push * @method push
* *
*/ */
public function push(){ public function push()
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -130,8 +144,9 @@ trait ReadOnlyTrait {
* @method finishSave * @method finishSave
* *
*/ */
public function finishSave(array $options){ public function finishSave(array $options)
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -139,8 +154,9 @@ trait ReadOnlyTrait {
* @method performUpdate * @method performUpdate
* *
*/ */
public function performUpdate(Builder $query, array $options = []){ public function performUpdate(Builder $query, array $options = [])
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -148,8 +164,9 @@ trait ReadOnlyTrait {
* @method touch * @method touch
* *
*/ */
public function touch(){ public function touch()
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -157,8 +174,9 @@ trait ReadOnlyTrait {
* @method insert * @method insert
* *
*/ */
public function insert(){ public function insert()
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
/** /**
@ -166,7 +184,8 @@ trait ReadOnlyTrait {
* @method truncate * @method truncate
* *
*/ */
public function truncate(){ public function truncate()
ReadOnlyTrait::readOnly(get_called_class()); {
ReadOnlyTrait::readOnly(get_called_class());
} }
} }