Skip to content

Commit

Permalink
Version 2.0 (#22)
Browse files Browse the repository at this point in the history
* updated composer dependencies to support PHP 7.2 and Laravel 6.0

* removed author annotation (email is defunct)

* Fixed test suite, added additional typehints

* applied PSR-2 styling

* updated travis php build versions
  • Loading branch information
frasmage committed Sep 13, 2019
1 parent 414aa37 commit d4b29b2
Show file tree
Hide file tree
Showing 31 changed files with 233 additions and 212 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor/
/composer.lock
/coverage/
/.idea/
.phpunit.result.cache
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php
php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
env:
matrix:
- PREFER_LOWEST="--prefer-lowest"
Expand All @@ -12,7 +12,7 @@ script:
- mkdir -p build/logs
- phpunit --coverage-clover build/logs/clover.xml
after_script:
- php vendor/bin/coveralls -v
- php vendor/bin/php-coveralls -v
branches:
only:
- master
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

# 2.0.0
- Moved minimum requirements to PHP 7.2 and Laravel 5.6+
- Added a number of missing return types.

## 1.1.0 - 2018-05-15
- Added `whereDoesntHaveMeta()` query scope (Thanks @tormjens!)

## 1.0.4 - 2017-08-20
- Added Laravel 5.5 package autodiscovery
- Meta keys are now correctly case sensitive throughout the package (Thanks @Luukvdo!)
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
}
},
"require": {
"php": ">=7.0.0",
"illuminate/support": "~5.2",
"illuminate/database": "~5.2"
"php": ">=7.2.0",
"ext-json": "*",
"illuminate/support": "^5.6|^6.0",
"illuminate/database": "^5.6|^6.0"
},
"require-dev": {
"orchestra/testbench": "~3.2",
"phpunit/phpunit": "~5.7",
"satooshi/php-coveralls": "^1.0.1"
"orchestra/testbench": "^3.3|^4.0",
"phpunit/phpunit": "^8.0",
"php-coveralls/php-coveralls": "^2.1"
},
"autoload-dev":{
"classmap": ["tests/"]
Expand Down
1 change: 1 addition & 0 deletions migrations/2017_01_01_000000_create_meta_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMetaTable extends Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSampleClassesTables extends Migration
{
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
8 changes: 3 additions & 5 deletions src/DataType/ArrayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,29 @@

/**
* Handle serialization of arrays.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class ArrayHandler implements HandlerInterface
{
/**
* {@inheritdoc}
*/
public function getDataType() : string
public function getDataType(): string
{
return 'array';
}

/**
* {@inheritdoc}
*/
public function canHandleValue($value) : bool
public function canHandleValue($value): bool
{
return is_array($value);
}

/**
* {@inheritdoc}
*/
public function serializeValue($value) : string
public function serializeValue($value): string
{
return json_encode($value);
}
Expand Down
2 changes: 0 additions & 2 deletions src/DataType/BooleanHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Handle serialization of booleans.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class BooleanHandler extends ScalarHandler
{
Expand Down
8 changes: 3 additions & 5 deletions src/DataType/DateTimeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Handle serialization of DateTimeInterface objects.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class DateTimeHandler implements HandlerInterface
{
Expand All @@ -22,23 +20,23 @@ class DateTimeHandler implements HandlerInterface
/**
* {@inheritdoc}
*/
public function getDataType() : string
public function getDataType(): string
{
return 'datetime';
}

/**
* {@inheritdoc}
*/
public function canHandleValue($value) : bool
public function canHandleValue($value): bool
{
return $value instanceof DateTimeInterface;
}

/**
* {@inheritdoc}
*/
public function serializeValue($value) : string
public function serializeValue($value): string
{
return $value->format($this->format);
}
Expand Down
4 changes: 1 addition & 3 deletions src/DataType/FloatHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Handle serialization of floats.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class FloatHandler extends ScalarHandler
{
Expand All @@ -17,7 +15,7 @@ class FloatHandler extends ScalarHandler
/**
* {@inheritdoc}
*/
public function getDataType() : string
public function getDataType(): string
{
return 'float';
}
Expand Down
8 changes: 3 additions & 5 deletions src/DataType/HandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Provides means to serialize and unserialize values of different data types.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
interface HandlerInterface
{
Expand All @@ -14,7 +12,7 @@ interface HandlerInterface
*
* @return string
*/
public function getDataType() : string;
public function getDataType(): string;

/**
* Determine if the value is of the correct type for this handler.
Expand All @@ -23,7 +21,7 @@ public function getDataType() : string;
*
* @return bool
*/
public function canHandleValue($value) : bool;
public function canHandleValue($value): bool;

/**
* Convert the value to a string, so that it can be stored in the database.
Expand All @@ -32,7 +30,7 @@ public function canHandleValue($value) : bool;
*
* @return string
*/
public function serializeValue($value) : string;
public function serializeValue($value): string;

/**
* Convert a serialized string back to its original value.
Expand Down
2 changes: 0 additions & 2 deletions src/DataType/IntegerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Handle serialization of integers.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class IntegerHandler extends ScalarHandler
{
Expand Down
12 changes: 5 additions & 7 deletions src/DataType/ModelCollectionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,39 @@

/**
* Handle serialization of Eloquent collections.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class ModelCollectionHandler implements HandlerInterface
{
/**
* {@inheritdoc}
*/
public function getDataType() : string
public function getDataType(): string
{
return 'collection';
}

/**
* {@inheritdoc}
*/
public function canHandleValue($value) : bool
public function canHandleValue($value): bool
{
return $value instanceof Collection;
}

/**
* {@inheritdoc}
*/
public function serializeValue($value) : string
public function serializeValue($value): string
{
$items = [];
foreach ($value as $key => $model) {
$items[$key] = [
'class' => get_class($model),
'key' => $model->exists ? $model->getKey() : null,
'key' => $model->exists ? $model->getKey() : null,
];
}

return json_encode(['class'=> get_class($value), 'items' => $items]);
return json_encode(['class' => get_class($value), 'items' => $items]);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/DataType/ModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,32 @@

/**
* Handle serialization of Eloquent Models.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class ModelHandler implements HandlerInterface
{
/**
* {@inheritdoc}
*/
public function getDataType() : string
public function getDataType(): string
{
return 'model';
}

/**
* {@inheritdoc}
*/
public function canHandleValue($value) : bool
public function canHandleValue($value): bool
{
return $value instanceof Model;
}

/**
* {@inheritdoc}
*/
public function serializeValue($value) : string
public function serializeValue($value): string
{
if ($value->exists) {
return get_class($value).'#'.$value->getKey();
return get_class($value) . '#' . $value->getKey();
}

return get_class($value);
Expand Down
4 changes: 1 addition & 3 deletions src/DataType/NullHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Handle serialization of null values.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class NullHandler extends ScalarHandler
{
Expand All @@ -17,7 +15,7 @@ class NullHandler extends ScalarHandler
/**
* {@inheritdoc}
*/
public function getDataType() : string
public function getDataType(): string
{
return 'null';
}
Expand Down
8 changes: 3 additions & 5 deletions src/DataType/ObjectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,29 @@

/**
* Handle serialization of plain objects.
*
* @author Sean Fraser <sean@plankdesign.com>
*/
class ObjectHandler implements HandlerInterface
{
/**
* {@inheritdoc}
*/
public function getDataType() : string
public function getDataType(): string
{
return 'object';
}

/**
* {@inheritdoc}
*/
public function canHandleValue($value) : bool
public function canHandleValue($value): bool
{
return is_object($value);
}

/**
* {@inheritdoc}
*/
public function serializeValue($value) : string
public function serializeValue($value): string
{
return json_encode($value);
}
Expand Down

0 comments on commit d4b29b2

Please sign in to comment.