diff --git a/.bldr.yml b/.bldr.yml old mode 100644 new mode 100755 diff --git a/.coveralls.yml b/.coveralls.yml old mode 100644 new mode 100755 diff --git a/.editorconfig b/.editorconfig old mode 100644 new mode 100755 index 0df74d7..bed79c6 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,4 @@ + root = true [*] diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 6987280..51de9cc --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,12 @@ -## -# This file is part of `scr-be/shared-public-knowledge` +# +# This file is part of the `src-run/augustus-serializer-library` project. # # (c) Rob Frawley 2nd # # For the full copyright and license information, view the LICENSE.md # file distributed with this source code. -## +# # Symfony 2 /app/cache/* @@ -61,4 +61,7 @@ LICENSE README +# phpcsfixer cache +.php_cs.cache + # EOF diff --git a/.gitmodules b/.gitmodules old mode 100644 new mode 100755 diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..5a43df4 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE.md + * file that was distributed with this source code. + */ + +use SLLH\StyleCIBridge\ConfigBridge; + +require_once __DIR__.'/vendor/autoload.php'; + +$headerString = << + +For the full copyright and license information, please view the LICENSE.md +file that was distributed with this source code. +EOF; + +$headerConfig = [ 'header_comment' => [ 'header' => $headerString ] ]; + +$config = ConfigBridge::create(); +$config->setRules(array_merge($config->getRules(), $headerConfig)); + +return $config; diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..39105da --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,24 @@ +--- + +preset: symfony + +enabled: + - combine_consecutive_unsets + - linebreak_after_opening_tag + - no_short_echo_tag + - ordered_imports + - phpdoc_order + - php_unit_construct + - php_unit_dedicate_assert + - php_unit_strict + - short_array_syntax + +disabled: + - simplified_null_return + +finder: + exclude: + - 'vendor' + - 'var' + +... diff --git a/.travis.yml b/.travis.yml old mode 100644 new mode 100755 index 7e21f93..0853f59 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,24 @@ --- -## +# # This file is part of the `src-run/augustus-serializer-library` project. # # (c) Rob Frawley 2nd -# (c) Scribe Inc # # For the full copyright and license information, view the LICENSE.md # file distributed with this source code. -## +# sudo : false language : php -php : [ 5.6, 7.0 ] +php : [ 7.0, 7.1 ] git: - depth : 3 + depth: 3 -env : - global : - secure : ZUzB7VhBBIGORmgDGKeVW2RLxQkSzYaXLIXYBerplikLmpnQCdiV16NcZTPZ8JVUJ9dTYWuVF0h2yoGmAgyrawWwmxo8g3Z/KdhzzMOl/1nyDZotROwNp89Iy7RpUpnFyKBV3/Hp2WZry+11QgqqBLLAHUd++ucaRr0mtBrSoD92oiQ3scbQyFkqkVDbseSm6sxYX87tw0r4GKC8DS7A9m7zlVky3KD7oPrnPfNvGq0MPsT3m9TCHIGrSuBLwQM9wCQOZ+CeayjjzJM8ByzCOSXEF9in9DI+Qgst+BgB2b6Tp1GmG3Se+I2u7eCGL+JOv0I934LFJXaXEIrJkH4xSNGcUcOALFng5NgDGNoa1gml1oqcb4YbO7DSGTlv7vmxpBF3DWOsh7ahad9PBeYqs1epQ3WoFsk6NyYAHshBAienbz+Vm6IoAUkT94b/KFHU8PZ0s1crYddbgtn9hPAVvfpI2LbtiEzjNmZwT8UBLRd79a/AYT9hKRD/XRxRdQHYUS+scSSVrR1P9sHm0vCO3wIqsBOa2WZXOtN28TN/jweAk7HRVgOrwQqnLp2ber+u0hTfoyX1wrUAW/jiiI/XzlhC/tAZifv8BgQbPpK3Pv/SlIOIOHNiuXDfdCTxJyY+R8SFCG12Tyi0Js7W7Am5VbqohUTKNzxNhGTkJJiR5dw= +env: + global: + - secure: "ZUzB7VhBBIGORmgDGKeVW2RLxQkSzYaXLIXYBerplikLmpnQCdiV16NcZTPZ8JVUJ9dTYWuVF0h2yoGmAgyrawWwmxo8g3Z/KdhzzMOl/1nyDZotROwNp89Iy7RpUpnFyKBV3/Hp2WZry+11QgqqBLLAHUd++ucaRr0mtBrSoD92oiQ3scbQyFkqkVDbseSm6sxYX87tw0r4GKC8DS7A9m7zlVky3KD7oPrnPfNvGq0MPsT3m9TCHIGrSuBLwQM9wCQOZ+CeayjjzJM8ByzCOSXEF9in9DI+Qgst+BgB2b6Tp1GmG3Se+I2u7eCGL+JOv0I934LFJXaXEIrJkH4xSNGcUcOALFng5NgDGNoa1gml1oqcb4YbO7DSGTlv7vmxpBF3DWOsh7ahad9PBeYqs1epQ3WoFsk6NyYAHshBAienbz+Vm6IoAUkT94b/KFHU8PZ0s1crYddbgtn9hPAVvfpI2LbtiEzjNmZwT8UBLRd79a/AYT9hKRD/XRxRdQHYUS+scSSVrR1P9sHm0vCO3wIqsBOa2WZXOtN28TN/jweAk7HRVgOrwQqnLp2ber+u0hTfoyX1wrUAW/jiiI/XzlhC/tAZifv8BgQbPpK3Pv/SlIOIOHNiuXDfdCTxJyY+R8SFCG12Tyi0Js7W7Am5VbqohUTKNzxNhGTkJJiR5dw=" install : - bash .bldr/bldr -b up-env -q diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fef6a38..eefd1fb 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,99 +1,90 @@ + # Contributing -Looking to contribute a pull-request back to a **Source Consulting** -project? Great! Before sending a pull-request, ensure the following -requirements (__A__, __B__, and __C__) described below are properly met. -This will ensure your contribution is merged smoothly and quickly. +Made some local modifications that might benefit upstream and have a +motivation to contribute back to this project? Great! Before opening a +PR (pull request), though, be sure the code style requirements standards +described in this file have been met. This will expedite your PR and +ensure a seamless experience in pushing your code back upstream. ## A. Code Style -All projects in the `SR` namespace adhere to strict code-style -requirements. The expected style is guaranteed through use of the -excellent auto-code-styling project +All projects must adhere to strict code style requirements. Ensuring +your PR meets these requirements is now easier than ever thanks to +the excellent code styling auto-correcting CLI tool [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). -### Download Fixer +### Get Development Deps -__A.__ To download *PHP CS Fixer* using *curl*: +You no longer have to download PHP CS Fixer yourself or have it pre- +installed globally on your system. Instead, it's a composer development +dependency. If you don't already have the development dependencies +installed, simply run (assuming you have composer installed globally on +your system): ```bash -curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer +composer install --dev ``` -__B.__ If *curl* is unavailable, download using *wget*: - -```bash -wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer -``` +### Run PHP CS Fixer -### Install Fixer - -It is recommended to install *PHP-CS-Fixer* at a system-level, making it -available within your normal `PATH` environment variable (allowing you -to call `php-cs-fixer` from any location). After downloading: +Thanks to the recently added `.styleci.yml` (a style rule-set config +files) and `.php_cs.dist` (a php-cs-fixer bridge to read `.styleci.yml` +for its config) you do not have to provide any configuration parameters +to PHP CS Fixer. Simply enter the repository root and run: ```bash -sudo chmod a+x php-cs-fixer -sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer +bin/php-cs-fixer fix ./ ``` -### Run Fixer - -When running *PHP CS Fixer*, there are a collection of "rules" that can -be passed via the --rules command-line option. Rules are also grouped -into "rule collections" that are prefixed by an "@" (at symbol). To -disable a rule, it should be prefixed by an "-" (minus sign). - -*PHP CS Fixer* must be configured and run with the following rules: -- `@Symfony` -- `-simplified_null_return` +This ensures all code style rules are implemented and auto corrects any +inconsistencies. It also forcibly sets the PHP file-level doc-blocks, +which may remove any attributes you set if they were in the file-level +php doc-block. Don't fret: the next section describes acceptable +attribution methods (if you require such). -For example, to fix code within the `lib` directory of the current path: +## B. Attribution -```bash -php-cs-fixer fix lib/ --rules=@Symfony,-simplified_null_return -``` - -## B. New Files - -Every file must contain a file-level "doc-block" following the below -template. The placeholder `PACKAGE_NAME` must match the -[Packagist](https://packagist.org/) project name for the respective file. +Attribution for yourself is 100% optional, but in some cases people +prefer an explicit doc-block `@author` attribution for all classes or +methods they wrote entirely themselves. If this is the case, the only +acceptable places to add attribution tags is in a *class doc-block* or +a *method doc-block*. The below example show how to implement atribution +for both these cases. ```php -/* - * This file is part of the `PACKAGE_NAME` project. - * - * (c) Rob Frawley 2nd - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. +/** + * ... + * File-level doc-block goes here automatically... + * ... */ -``` - -An "end of file" comment followed by an empty new line, must be present -at the end of all files. - -```php -/* EOF */ - -``` - -## C. Attribution -Sometimes completely new classes are written by a contributor. When -this is the case, *the contributor __may__ choose (at their discretion)*, -to use a class-level "doc-block" to provide attribution using the -following template. - -```php /** - * Class ReallyCoolContributedClass. + * A description of the purpose of this class. * * @author CONTRIBUTOR_NAME */ class ReallyCoolContributedClass { // ... + + /** + * A description of the purpose of this method. + * + * @author CONTRIBUTOR_NAME + */ + public function myWonderfulMethod() + { + // ... + } + + // ... } ``` + +## C. Submit PR + +After completing the above requirements (items **A.** and **B.**) your +code is primed and ready to be accepted upstream. Go ahead and open a +PR: we appreciate your time and contribution to this project, however +small or large! diff --git a/LICENSE.md b/LICENSE.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md index 6047ef5..129cdf7 100755 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # [src-run] augustus-serializer-library -| Travis-CI | Codacy Rating | Code Coverage | Style-CI | -|:----------------------:|:-----------------------:|:-----------------------:|:-----------------------:| -| [![Travis](https://src.run/augustus-serializer-library/travis.svg)](https://src.run/augustus-serializer-library/travis) | [![Codacy](https://src.run/augustus-serializer-library/codacy.svg)](https://src.run/augustus-serializer-library/codacy) | [![Coveralls](https://src.run/augustus-serializer-library/coveralls.svg)](https://src.run/augustus-serializer-library/coveralls) | [![Coveralls](https://src.run/augustus-serializer-library/styleci.svg)](https://src.run/augustus-serializer-library/styleci) | +| Travis-CI | Codacy Rating | Code Coverage | Style-CI | Release | API Documentation | +|:----------------------:|:-----------------------:|:-----------------------:|:-----------------------:|:-----------------------:|:-----------------------:| +| [![Travis](https://src.run/augustus-serializer-library/travis.svg)](https://src.run/augustus-serializer-library/travis) | [![Codacy](https://src.run/augustus-serializer-library/codacy.svg)](https://src.run/augustus-serializer-library/codacy) | [![Coveralls](https://src.run/augustus-serializer-library/coveralls.svg)](https://src.run/augustus-serializer-library/coveralls) | [![Coveralls](https://src.run/augustus-serializer-library/styleci.svg)](https://src.run/augustus-serializer-library/styleci) | [![Packagist](https://src.run/augustus-serializer-library/packagist.svg)](https://src.run/augustus-serializer-library/packagist) | [![API Docs](https://src.run/augustus-serializer-library/api.svg)](https://src.run/augustus-serializer-library/api) | ## Overview @@ -11,7 +11,7 @@ [Welcome](https://src.run/go/readme_welcome)! The `src-run/augustus-serializer-library` package provides the following -> simple abstraction on serialize functions with support for php- json- and igbinary-based serialization +> A simple library to facilitate dumping of files to native php. ### Grouping @@ -116,5 +116,4 @@ information. | __Stable Release__ | [![Packagist](https://src.run/augustus-serializer-library/packagist.svg)](https://src.run/augustus-serializer-library/packagist) | | __Dev Release__ | [![Packagist](https://src.run/augustus-serializer-library/packagist_pre.svg)](https://src.run/augustus-serializer-library/packagist) | | __License__ | [![License](https://src.run/augustus-serializer-library/license.svg)](https://src.run/augustus-serializer-library/license) | -| __Reference__ | [![License](https://src.run/augustus-serializer-library/api.svg)](https://src.run/augustus-serializer-library/api) | diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index ef089df..4a4e9b1 --- a/composer.json +++ b/composer.json @@ -1,52 +1,60 @@ { - "name" : "src-run/augustus-serializer-library", - "license" : "MIT", - "type" : "library", - "homepage" : "https://src.run/augustus-serializer-library", - "description" : "simple abstraction on serialize functions with support for php- json- and igbinary-based serialization", - "support" : { - "email" : "rmf@src.run", - "issues" : "https://src.run/augustus-serializer-library/issues", - "source" : "https://src.run/augustus-serializer-library/git" + "name": "src-run/augustus-serializer-library", + "license": "MIT", + "type": "library", + "homepage": "https://src.run/augustus-serializer-library", + "description": "Basic serialize implementations supporting for php, json, and igbinary serializer.", + "support": { + "email": "rmf@src.run", + "issues": "https://src.run/augustus-serializer-library/issues", + "source": "https://src.run/augustus-serializer-library/git" }, - "keywords" : [ + "keywords": [ "augustus-serializer-library", "augustus", "serializer", "library", "rmf", "src-run" ], - "authors" : [ + "authors": [ { - "name" : "Rob Frawley 2nd", - "email" : "rmf@src.run", + "name": "Rob Frawley 2nd", + "email": "rmf@src.run", "homepage": "https://src.run/rmf", - "role" : "Project Lead" + "role": "Project Lead" } ], - "require" : { - "php" : "^5.6||^7.0", - "src-run/augustus-exception-library" : "^0.6" + "require": { + "php": "~7.0", + "src-run/augustus-utility-library": "~0.7" }, - "require-dev" : { - "phpunit/phpunit" : "^5.0", - "codacy/coverage" : "^1.0", - "satooshi/php-coveralls" : "^1.0" + "require-dev": { + "codacy/coverage": "~1.0", + "ext-igbinary": "*", + "friendsofphp/php-cs-fixer": "v2.0.0-alpha", + "phpunit/phpunit": "~5.4", + "satooshi/php-coveralls": "~1.0", + "sllh/php-cs-fixer-styleci-bridge": "~2.1", + "symfony/phpunit-bridge": "~3.0" }, - "autoload" : { - "psr-4" : { - "SR\\Serializer\\" : "lib/" + "suggest": { + "ext-igbinary": "Require to use igbinary serializer implementation." + }, + "autoload": { + "psr-4": { + "SR\\Serializer\\": "lib/" } }, - "autoload-dev" : { - "psr-4" : { - "SR\\Serializer\\Tests\\" : "tests/" + "autoload-dev": { + "psr-4": { + "SR\\Serializer\\Tests\\": "tests/" } }, - "minimum-stability" : "dev", - "prefer-stable" : true, + "minimum-stability": "dev", + "prefer-stable": true, "config": { - "bin-dir" : "bin" + "bin-dir": "bin", + "sort-packages": true }, "extra": { "branch-alias": { - "dev-master" : "0.6-dev" + "dev-master": "0.7-dev" } } } diff --git a/lib/Serializer.php b/lib/Serializer.php old mode 100644 new mode 100755 index 87fa440..0ff9c39 --- a/lib/Serializer.php +++ b/lib/Serializer.php @@ -1,10 +1,9 @@ - * (c) Scribe Inc * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -12,11 +11,8 @@ namespace SR\Serializer; -use SR\Serializer\Type\SerializerTypePhp; +use SR\Serializer\Type\SerializerTypeInterface; -/** - * Class Serializer. - */ class Serializer implements SerializerInterface { /** @@ -35,16 +31,22 @@ class Serializer implements SerializerInterface private static $denormalizer; /** - * @param string $type + * @param string|int $type * * @return SerializerInterface */ - final public static function create($type = self::TYPE_AUTO) + final public static function create(string $type = null) : SerializerInterface { - if ($type === static::TYPE_AUTO) { - static::createAuto(); - } else { - static::createType($type); + $serializers = static::TYPE_PRIORITY; + + if ($type !== null) { + $serializers = [$type]; + } + + foreach ($serializers as $type) { + if (static::createSerializer($type)) { + break; + } } return new static(); @@ -55,9 +57,9 @@ final public static function create($type = self::TYPE_AUTO) * * @return mixed */ - final public function serialize($data) + final public function serialize($data) : string { - return static::$serializer->serialize($data, static::$normalizer); + return $this->getSerializer()->serialize($data, static::$normalizer); } /** @@ -67,13 +69,15 @@ final public function serialize($data) */ final public function unserialize($data) { - return static::$serializer->unserialize($data, static::$denormalizer); + return $this->getSerializer()->unserialize($data, static::$denormalizer); } /** * @param null|\Closure $denormalizer + * + * @return $this */ - final public function setDenormalizer(\Closure $denormalizer = null) + final public function setDenormalizer(\Closure $denormalizer = null) : SerializerInterface { static::$denormalizer = $denormalizer; @@ -82,8 +86,10 @@ final public function setDenormalizer(\Closure $denormalizer = null) /** * @param null|\Closure $normalizer + * + * @return $this */ - final public function setNormalizer(\Closure $normalizer = null) + final public function setNormalizer(\Closure $normalizer = null) : SerializerInterface { static::$normalizer = $normalizer; @@ -93,34 +99,34 @@ final public function setNormalizer(\Closure $normalizer = null) /** * @return SerializerTypeInterface */ - final public function getSerializer() + final public function getSerializer() : SerializerTypeInterface { return static::$serializer; } /** - * @return SerializerInterface + * @param string $type + * + * @return bool */ - final private static function createAuto() + final private static function createSerializer(string $type) : bool { - foreach (self::PRIORITY as $type) { - if ($type::supported()) { - static::createType($type); + if (call_user_func([$type, 'supported'])) { + static::initializeSerializer($type); - break; - } + return true; } + + return false; } /** * @param string $type * - * @return SerializerInterface + * @return SerializerTypeInterface */ - final private static function createType($type) + final private static function initializeSerializer(string $type) : SerializerTypeInterface { - static::$serializer = class_exists($type) ? $type::create() : SerializerTypePhp::create(); + return static::$serializer = $serializer = call_user_func([$type, 'create']); } } - -/* EOF */ diff --git a/lib/SerializerInterface.php b/lib/SerializerInterface.php old mode 100644 new mode 100755 index fb2647b..f917f5b --- a/lib/SerializerInterface.php +++ b/lib/SerializerInterface.php @@ -1,10 +1,9 @@ - * (c) Scribe Inc * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -12,58 +11,50 @@ namespace SR\Serializer; -/** - * Interface SerializerInterface. - */ +use SR\Serializer\Type\SerializerTypeIgbinary; +use SR\Serializer\Type\SerializerTypeInterface; +use SR\Serializer\Type\SerializerTypeJson; +use SR\Serializer\Type\SerializerTypePhp; + interface SerializerInterface { - /** - * @var int - */ - const TYPE_AUTO = -1; - /** * @var string */ - const TYPE_PHP = 'SR\Serializer\Type\SerializerTypePhp'; + const TYPE_PHP = SerializerTypePhp::class; /** * @var string */ - const TYPE_IGBINARY = 'SR\Serializer\Type\SerializerTypeIgbinary'; + const TYPE_IGBINARY = SerializerTypeIgbinary::class; /** * @var string */ - const TYPE_JSON = 'SR\Serializer\Type\SerializerTypeJson'; - - /** - * @var string - */ - const TYPE_CALLABLE = 'SR\Serializer\Type\SerializerTypeCallable'; + const TYPE_JSON = SerializerTypeJson::class; /** * @var string[] */ - const PRIORITY = [ + const TYPE_PRIORITY = [ self::TYPE_IGBINARY, self::TYPE_PHP, self::TYPE_JSON, ]; /** - * @param string $type + * @param string|int $type * * @return SerializerInterface */ - public static function create($type = self::TYPE_AUTO); + public static function create(string $type = null) : SerializerInterface; /** * @param mixed $data * * @return mixed */ - public function serialize($data); + public function serialize($data) : string; /** * @param mixed $data @@ -75,17 +66,15 @@ public function unserialize($data); /** * @param null|\Closure $denormalizer */ - public function setDenormalizer(\Closure $denormalizer = null); + public function setDenormalizer(\Closure $denormalizer = null) : SerializerInterface; /** * @param null|\Closure $normalizer */ - public function setNormalizer(\Closure $normalizer = null); + public function setNormalizer(\Closure $normalizer = null) : SerializerInterface; /** * @return SerializerTypeInterface */ - public function getSerializer(); + public function getSerializer() : SerializerTypeInterface; } - -/* EOF */ diff --git a/lib/Type/AbstractSerializerType.php b/lib/Type/AbstractSerializerType.php old mode 100644 new mode 100755 index 5ec357a..ee230f8 --- a/lib/Type/AbstractSerializerType.php +++ b/lib/Type/AbstractSerializerType.php @@ -1,10 +1,9 @@ - * (c) Scribe Inc * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -12,25 +11,22 @@ namespace SR\Serializer\Type; -/** - * Class AbstractSerializerType. - */ abstract class AbstractSerializerType implements SerializerTypeInterface { /** * @var callable|\Closure */ - protected $serializationHandler; + protected $serializerHandler; /** * @var callable|\Closure */ - protected $unSerializationHandler; + protected $unserializerHandler; /** * @return SerializerTypeInterface */ - public static function create() + public static function create() : SerializerTypeInterface { return new static(); } @@ -41,13 +37,13 @@ public static function create() * * @return mixed */ - public function serialize($data = null, \Closure $visitor = null) + public function serialize($data = null, \Closure $visitor = null) : string { if ($visitor instanceof \Closure) { $data = $visitor($data); } - return call_user_func($this->serializationHandler, $data); + return call_user_func($this->serializerHandler, $data); } /** @@ -58,10 +54,8 @@ public function serialize($data = null, \Closure $visitor = null) */ public function unserialize($data = null, \Closure $visitor = null) { - $data = call_user_func($this->unSerializationHandler, $data); + $data = call_user_func($this->unserializerHandler, $data); return $visitor instanceof \Closure ? $visitor($data) : $data; } } - -/* EOF */ diff --git a/lib/Type/SerializerTypeIgbinary.php b/lib/Type/SerializerTypeIgbinary.php old mode 100644 new mode 100755 index e872233..c7d1e7d --- a/lib/Type/SerializerTypeIgbinary.php +++ b/lib/Type/SerializerTypeIgbinary.php @@ -1,10 +1,9 @@ - * (c) Scribe Inc * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -12,26 +11,21 @@ namespace SR\Serializer\Type; -use SR\Utility\EngineInspect; +use SR\Util\Info\EngineInfo; -/** - * Class SerializerTypeIgbinary. - */ final class SerializerTypeIgbinary extends AbstractSerializerType { public function __construct() { - $this->serializationHandler = 'igbinary_serialize'; - $this->unSerializationHandler = 'igbinary_unserialize'; + $this->serializerHandler = 'igbinary_serialize'; + $this->unserializerHandler = 'igbinary_unserialize'; } /** * @return bool */ - public static function supported() + public static function supported() : bool { - return EngineInspect::extensionLoaded('igbinary'); + return EngineInfo::extensionLoaded('igbinary'); } } - -/* EOF */ diff --git a/lib/Type/SerializerTypeInterface.php b/lib/Type/SerializerTypeInterface.php old mode 100644 new mode 100755 index 76fe60b..538e882 --- a/lib/Type/SerializerTypeInterface.php +++ b/lib/Type/SerializerTypeInterface.php @@ -1,10 +1,9 @@ - * (c) Scribe Inc * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -12,15 +11,12 @@ namespace SR\Serializer\Type; -/** - * Interface SerializerTypeInterface. - */ interface SerializerTypeInterface { /** * @return SerializerTypeInterface */ - public static function create(); + public static function create() : SerializerTypeInterface; /** * @param mixed|null $data @@ -28,7 +24,7 @@ public static function create(); * * @return mixed */ - public function serialize($data = null, \Closure $visitor = null); + public function serialize($data = null, \Closure $visitor = null) : string; /** * @param mixed|null $data @@ -41,7 +37,5 @@ public function unserialize($data = null, \Closure $visitor = null); /** * @return bool */ - public static function supported(); + public static function supported() : bool; } - -/* EOF */ diff --git a/lib/Type/SerializerTypeJson.php b/lib/Type/SerializerTypeJson.php old mode 100644 new mode 100755 index 96b9fe2..e1437ea --- a/lib/Type/SerializerTypeJson.php +++ b/lib/Type/SerializerTypeJson.php @@ -1,10 +1,9 @@ - * (c) Scribe Inc * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -12,26 +11,21 @@ namespace SR\Serializer\Type; -use SR\Utility\EngineInspect; +use SR\Util\Info\EngineInfo; -/** - * Class SerializerTypeJson. - */ class SerializerTypeJson extends AbstractSerializerType { public function __construct() { - $this->serializationHandler = 'json_encode'; - $this->unSerializationHandler = 'json_decode'; + $this->serializerHandler = 'json_encode'; + $this->unserializerHandler = 'json_decode'; } /** * @return bool */ - public static function supported() + public static function supported() : bool { - return EngineInspect::extensionLoaded('json'); + return EngineInfo::extensionLoaded('json'); } } - -/* EOF */ diff --git a/lib/Type/SerializerTypePhp.php b/lib/Type/SerializerTypePhp.php old mode 100644 new mode 100755 index 0109f23..3360eab --- a/lib/Type/SerializerTypePhp.php +++ b/lib/Type/SerializerTypePhp.php @@ -1,10 +1,9 @@ - * (c) Scribe Inc * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -12,24 +11,19 @@ namespace SR\Serializer\Type; -/** - * Class SerializerTypePhp. - */ class SerializerTypePhp extends AbstractSerializerType { public function __construct() { - $this->serializationHandler = 'serialize'; - $this->unSerializationHandler = 'unserialize'; + $this->serializerHandler = 'serialize'; + $this->unserializerHandler = 'unserialize'; } /** * @return bool */ - public static function supported() + public static function supported() : bool { return true; } } - -/* EOF */ diff --git a/phpunit.xml.dist b/phpunit.xml.dist old mode 100644 new mode 100755 index d763ee3..f479882 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ + * + * For the full copyright and license information, please view the LICENSE.md + * file that was distributed with this source code. + */ + +namespace SR\Serializer\Tests\Fixture; + +use SR\Serializer\Type\AbstractSerializerType; + +class SerializerTypeNotSupported extends AbstractSerializerType +{ + /** + * @return bool + */ + public static function supported() : bool + { + return false; + } +} diff --git a/tests/SerializerFactoryTest.php b/tests/SerializerFactoryTest.php old mode 100644 new mode 100755 index bd0fca8..dbdadfc --- a/tests/SerializerFactoryTest.php +++ b/tests/SerializerFactoryTest.php @@ -1,10 +1,9 @@ - * (c) Scribe Inc * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. @@ -13,10 +12,8 @@ namespace SR\Serializer\Tests; use SR\Serializer\Serializer; +use SR\Serializer\Tests\Fixture\SerializerTypeNotSupported; -/** - * Class SerializerFactoryTest. - */ class SerializerFactoryTest extends \PHPUnit_Framework_TestCase { public function testCreateTypes() @@ -42,7 +39,7 @@ public function testAutoTypeWithIgbinary() if (extension_loaded('igbinary')) { $this->assertInstanceOf( 'SR\Serializer\Type\SerializerTypeIgbinary', - Serializer::create(Serializer::TYPE_AUTO)->getSerializer() + Serializer::create()->getSerializer() ); } } @@ -153,6 +150,11 @@ public function testSupported() $serializer::supported() ); } + + public function testNotSupported() + { + $serializer = Serializer::create(SerializerTypeNotSupported::class); + } } /* EOF */