From 5727d1d4114c6cf88bc26efc31709c38e7e9e7b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sat, 8 Jul 2017 13:05:58 +0300 Subject: [PATCH 1/6] Update to modern coding standards --- .gitattributes | 2 +- .gitignore | 7 +- .php_cs | 118 ++++++++++++++++++++------ .travis.yml | 10 +-- README.md | 11 ++- apigen.neon | 12 --- composer.json | 63 +++++++++----- sami_config.php | 26 ++++++ src/Encoder/FloatEncoder.php | 4 +- src/Encoder/GMPEncoder.php | 6 +- src/Encoder/IntegerEncoder.php | 2 +- src/autoload.php | 10 ++- tests/bootstrap.php | 7 +- tests/extra/ExtendsTestMockObject.php | 2 +- tests/extra/StringObject.php | 2 +- tests/extra/TestMockObject.php | 2 +- tests/tests/EncodingTest.php | 34 ++++---- tests/tests/EncodingTestCase.php | 4 +- tests/tests/ObjectEncodingTest.php | 40 ++++++--- 19 files changed, 233 insertions(+), 129 deletions(-) delete mode 100644 apigen.neon create mode 100644 sami_config.php diff --git a/.gitattributes b/.gitattributes index ce7ef54..6a4f8d5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,5 +7,5 @@ tests export-ignore .gitignore export-ignore .php_cs export-ignore .travis.yml export-ignore -apigen.neon export-ignore phpunit.xml export-ignore +sami_config.php export-ignore diff --git a/.gitignore b/.gitignore index 23a0309..f7755b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ +build/ +vendor/ examples/dbconf.php -api -coverage -vendor -dev +composer.lock diff --git a/.php_cs b/.php_cs index 9765e7e..8c61b21 100644 --- a/.php_cs +++ b/.php_cs @@ -1,31 +1,101 @@ in(__DIR__ . '/src') ->in(__DIR__ . '/tests'); -return Symfony\CS\Config\Config::create() - ->fixers([ - 'align_double_arrow', - 'concat_with_spaces', - 'ereg_to_preg', - 'multiline_spaces_before_semicolon', - 'newline_after_open_tag', - 'ordered_use', - 'php4_constructor', - 'php_unit_construct', - 'php_unit_strict', - 'short_array_syntax', - 'strict', - 'strict_param', +return \PhpCsFixer\Config::create() + ->setRules([ + '@PSR2' => true, - '-concat_without_spaces', - '-linefeed', - '-phpdoc_no_empty_return', - '-phpdoc_params', - '-phpdoc_separation', - '-pre_increment', - '-unalign_double_arrow', - '-unary_operators_spaces', + 'array_syntax' => [ + 'syntax' => 'short' + ], + 'binary_operator_spaces' => [ + 'align_double_arrow' => null, + 'align_equals' => false, + ], + 'blank_line_after_opening_tag' => true, + 'cast_spaces' => true, + 'combine_consecutive_unsets' => true, + 'concat_space' => [ + 'spacing' => 'one' + ], + 'declare_equal_normalize' => true, + 'dir_constant' => true, + 'ereg_to_preg' => true, + 'function_to_constant' => true, + 'function_typehint_space' => true, + 'hash_to_slash_comment' => true, + 'heredoc_to_nowdoc' => true, + 'include' => true, + 'is_null' => true, + 'lowercase_cast' => true, + 'magic_constant_casing' => true, + 'method_separation' => true, + 'modernize_types_casting' => true, + 'native_function_casing' => true, + 'new_with_braces' => true, + 'no_alias_functions' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_consecutive_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_multiline_whitespace_before_semicolons' => true, + 'no_php4_constructor' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_around_offset' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unused_imports' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'non_printable_character' => true, + 'normalize_index_brace' => true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => [ + 'order' => ['use_trait', 'constant', 'property', 'construct', 'method'], + ], + 'ordered_imports' => true, + 'php_unit_construct' => true, + 'php_unit_dedicate_assert' => true, + 'php_unit_strict' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_indent' => true, + 'phpdoc_inline_tag' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_alias_tag' => true, + 'phpdoc_no_package' => true, + 'phpdoc_scalar' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => true, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'phpdoc_var_without_name' => true, + 'pow_to_exponentiation' => true, + 'psr4' => true, + 'return_type_declaration' => true, + 'self_accessor' => true, + 'short_scalar_cast' => true, + 'single_blank_line_before_namespace' => true, + 'single_quote' => true, + 'space_after_semicolon' => true, + 'standardize_not_equals' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline_array' => true, + 'trim_array_spaces' => true, + 'whitespace_after_comma_in_array' => true, ]) - ->finder($finder); + ->setFinder($finder); diff --git a/.travis.yml b/.travis.yml index b5a4572..9fe4bf3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: php sudo: false +dist: trusty php: - 5.6 - - 5.5 - - 5.4 - 7.0 + - 7.1 - hhvm cache: @@ -14,11 +14,9 @@ cache: before_install: - if [[ $TRAVIS_PHP_VERSION =~ ^7 ]]; then phpenv config-rm xdebug.ini; fi - - composer self-update install: - - composer require --no-update --no-interaction "phpunit/phpunit:*" "squizlabs/php_codesniffer:*" "fabpot/php-cs-fixer:*" - - travis_retry composer update --no-interaction --prefer-source + - travis_retry composer update --no-interaction - travis_retry wget https://scrutinizer-ci.com/ocular.phar before_script: @@ -32,7 +30,7 @@ script: vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text; fi - vendor/bin/phpcs --standard=PSR2 src tests - - vendor/bin/php-cs-fixer fix --dry-run --diff + - vendor/bin/php-cs-fixer fix -v --dry-run --allow-risky=yes --using-cache=no after_script: - > diff --git a/README.md b/README.md index 9b4b634..8c78b16 100644 --- a/README.md +++ b/README.md @@ -21,17 +21,16 @@ fits in any of your dynamically generated PHP files. The API documentation, which can be generated using Apigen, can be read online at: http://kit.riimu.net/api/phpencoder/ -[![Build Status](https://img.shields.io/travis/Riimu/Kit-PHPEncoder.svg?style=flat)](https://travis-ci.org/Riimu/Kit-PHPEncoder) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Riimu/Kit-PHPEncoder.svg?style=flat)](https://scrutinizer-ci.com/g/Riimu/Kit-PHPEncoder/) -[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/Riimu/Kit-PHPEncoder.svg?style=flat)](https://scrutinizer-ci.com/g/Riimu/Kit-PHPEncoder/) -[![HHVM Status](https://img.shields.io/hhvm/riimu/Kit-PHPEncoder.svg)](http://hhvm.h4cc.de/package/riimu/Kit-PHPEncoder) -[![PHP7 Status](https://img.shields.io/badge/PHP7-tested-brightgreen.svg)]() +[![Travis](https://img.shields.io/travis/Riimu/Kit-PHPEncoder.svg?style=flat-square)](https://travis-ci.org/Riimu/Kit-PHPEncoder) +[![Scrutinizer](https://img.shields.io/scrutinizer/g/Riimu/Kit-PHPEncoder.svg?style=flat-square)](https://scrutinizer-ci.com/g/Riimu/Kit-PHPEncoder/) +[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/Riimu/Kit-PHPEncoder.svg?style=flat-square)](https://scrutinizer-ci.com/g/Riimu/Kit-PHPEncoder/) +[![Packagist](https://img.shields.io/packagist/v/riimu/kit-phpencoder.svg?style=flat-square)](https://packagist.org/packages/riimu/kit-phpencoder) ## Requirements ## In order to use this library, the following requirements must be met: - * PHP version 5.4 + * PHP version 5.6 ## Installation ## diff --git a/apigen.neon b/apigen.neon deleted file mode 100644 index 54cbbc3..0000000 --- a/apigen.neon +++ /dev/null @@ -1,12 +0,0 @@ -source: - - src - -destination: api -charset: - - UTF-8 - -main: Riimu\Kit\PHPEncoder -title: PHPEncoder -php: true -tree: true -templateTheme: bootstrap diff --git a/composer.json b/composer.json index e1016c5..03ce079 100644 --- a/composer.json +++ b/composer.json @@ -1,26 +1,43 @@ { - "name": "riimu/kit-phpencoder", - "type": "library", - "description": "Highly customizable alternative to var_export for PHP code generation", - "homepage": "http://kit.riimu.net", - "keywords": ["variable", "export", "code", "generator", "encoder"], - "license": "MIT", - "authors": [ - { - "name": "Riikka Kalliomäki", - "email": "riikka.kalliomaki@gmail.com", - "homepage": "http://riimu.net" - } - ], - "require": { - "php": ">=5.4.0" - }, - "suggest": { - "ext-gmp" : "To convert GMP numbers into PHP code" - }, - "autoload": { - "psr-4": { - "Riimu\\Kit\\PHPEncoder\\": "src/" - } + "name": "riimu/kit-phpencoder", + "type": "library", + "description": "Highly customizable alternative to var_export for PHP code generation", + "homepage": "http://kit.riimu.net", + "keywords": [ + "variable", + "export", + "code", + "generator", + "encoder" + ], + "license": "MIT", + "authors": [ + { + "name": "Riikka Kalliomäki", + "email": "riikka.kalliomaki@gmail.com", + "homepage": "http://riimu.net" } + ], + "require": { + "php": ">=5.6.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.2", + "squizlabs/php_codesniffer": "^3.0", + "friendsofphp/php-cs-fixer": "^2.3" + }, + "suggest": { + "ext-gmp": "To convert GMP numbers into PHP code" + }, + "autoload": { + "psr-4": { + "Riimu\\Kit\\PHPEncoder\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Riimu\\Kit\\PHPEncoder\\": "tests/tests/", + "Riimu\\Kit\\PHPEncoder\\Test\\": "tests/extra/" + } + } } diff --git a/sami_config.php b/sami_config.php new file mode 100644 index 0000000..6f0b762 --- /dev/null +++ b/sami_config.php @@ -0,0 +1,26 @@ +files() + ->name('*.php') + ->in(__DIR__ . '/src'); + +$theme = getenv('SAMI_THEME'); +$settings = []; + +if ($theme) { + $settings['theme'] = basename($theme); + $settings['template_dirs'] = [dirname($theme)]; +} + +return new Sami($iterator, $settings + [ + 'title' => 'Kit PHPEncoder API', + 'build_dir' => __DIR__ . '/build/doc', + 'cache_dir' => __DIR__ . '/build/cache', + 'remote_repository' => new GitHubRemoteRepository('Riimu/Kit-PHPEncoder', __DIR__), + 'default_opened_level' => 3, +]); diff --git a/src/Encoder/FloatEncoder.php b/src/Encoder/FloatEncoder.php index 56449e7..f9a864a 100644 --- a/src/Encoder/FloatEncoder.php +++ b/src/Encoder/FloatEncoder.php @@ -96,8 +96,8 @@ private function encodeFloat($float, $precision) } // Deal with overflow that results from rounding - $log += (int) (round(abs($float) / pow(10, $log), $precision - 1) / 10); - $string = $this->formatFloat($float / pow(10, $log), $precision - 1); + $log += (int) (round(abs($float) / 10 ** $log, $precision - 1) / 10); + $string = $this->formatFloat($float / 10 ** $log, $precision - 1); return sprintf('%sE%+d', $string, $log); } diff --git a/src/Encoder/GMPEncoder.php b/src/Encoder/GMPEncoder.php index a8fb3b1..e380d51 100644 --- a/src/Encoder/GMPEncoder.php +++ b/src/Encoder/GMPEncoder.php @@ -17,11 +17,7 @@ public function getDefaultOptions() public function supports($value) { - if (version_compare(PHP_VERSION, '5.6.0', '>=')) { - return is_object($value) && get_class($value) === 'GMP'; - } - - return is_resource($value) && get_resource_type($value) === 'GMP integer'; + return is_object($value) && get_class($value) === \GMP::class; } public function encode($value, $depth, array $options, callable $encode) diff --git a/src/Encoder/IntegerEncoder.php b/src/Encoder/IntegerEncoder.php index 998a7ed..c233436 100644 --- a/src/Encoder/IntegerEncoder.php +++ b/src/Encoder/IntegerEncoder.php @@ -17,7 +17,7 @@ public function getDefaultOptions() public function supports($value) { - return is_integer($value); + return is_int($value); } public function encode($value, $depth, array $options, callable $encode) diff --git a/src/autoload.php b/src/autoload.php index c09d65b..45ca83e 100644 --- a/src/autoload.php +++ b/src/autoload.php @@ -1,10 +1,12 @@ DIRECTORY_SEPARATOR]) . '.php'; + if (file_exists($path)) { require $path; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 10119c8..d21c14d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,8 +1,3 @@ getMock('Riimu\Kit\PHPEncoder\Encoder\Encoder', ['getDefaultOptions', 'supports', 'encode']); + $mock = $this->getMockBuilder(Encoder::class) + ->setMethods(['getDefaultOptions', 'supports', 'encode']) + ->getMock(); + $mock->expects($this->any())->method('getDefaultOptions')->will($this->returnValue(['test' => false])); $mock->expects($this->any())->method('supports')->will($this->returnValue(true)); $mock->expects($this->any())->method('encode')->will($this->returnCallback( @@ -120,7 +124,7 @@ public function testNanFloat() $value = eval("return $code;"); $this->assertInternalType('float', $value); - $this->assertTrue(is_nan($value)); + $this->assertNan($value); } public function testFloatIntegers() @@ -212,19 +216,19 @@ public function testGMPEncoding() public function testInvalidOptionOnConstructor() { - $this->setExpectedException('Riimu\Kit\PHPEncoder\InvalidOptionException'); + $this->expectException(InvalidOptionException::class); new PHPEncoder(['NoSuchOption' => true]); } public function testSettingAnInvalidOption() { - $this->setExpectedException('Riimu\Kit\PHPEncoder\InvalidOptionException'); + $this->expectException(InvalidOptionException::class); (new PHPEncoder())->setOption('NoSuchOption', true); } public function testInvalidOptionOnEncode() { - $this->setExpectedException('Riimu\Kit\PHPEncoder\InvalidOptionException'); + $this->expectException(InvalidOptionException::class); (new PHPEncoder())->encode([], ['NoSuchOption' => true]); } @@ -235,45 +239,37 @@ public function testMaxDepth() $this->assertNotEmpty($encoder->encode([1, [2, 3]])); $encoder->setOption('recursion.max', 1); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $encoder->encode([1, [2, 3]]); } public function testMissingEncoder() { $encoder = new PHPEncoder([], []); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $encoder->encode(null); } public function testUnknownType() { - $fp = fopen(__FILE__, 'r'); + $fp = fopen(__FILE__, 'rb'); fclose($fp); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); (new PHPEncoder())->encode($fp); } public function testArrayRecursion() { - if (version_compare(PHP_VERSION, '5.4.5', '<')) { - $this->markTestSkipped(); - } - $foo = [1]; $foo[1] = & $foo; - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); (new PHPEncoder())->encode($foo); } public function testIgnoredArrayRecursion() { - if (version_compare(PHP_VERSION, '5.4.5', '<')) { - $this->markTestSkipped(); - } - $foo = [1]; $foo[1] = & $foo; @@ -293,7 +289,7 @@ public function testMaxDeathOnNoRecursionDetection() 'recursion.max' => 5, ]); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $encoder->encode($foo); } } diff --git a/tests/tests/EncodingTestCase.php b/tests/tests/EncodingTestCase.php index f993f0a..d4e0abb 100644 --- a/tests/tests/EncodingTestCase.php +++ b/tests/tests/EncodingTestCase.php @@ -2,7 +2,9 @@ namespace Riimu\Kit\PHPEncoder; -class EncodingTestCase extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class EncodingTestCase extends TestCase { /** * Asserts that expected code is generated and it evaluates to the expected value. diff --git a/tests/tests/ObjectEncodingTest.php b/tests/tests/ObjectEncodingTest.php index 1890eac..13b1cd4 100644 --- a/tests/tests/ObjectEncodingTest.php +++ b/tests/tests/ObjectEncodingTest.php @@ -2,12 +2,17 @@ namespace Riimu\Kit\PHPEncoder; +use PHPUnit\Framework\TestCase; +use Riimu\Kit\PHPEncoder\Test\ExtendsTestMockObject; +use Riimu\Kit\PHPEncoder\Test\StringObject; +use Riimu\Kit\PHPEncoder\Test\TestMockObject; + /** * @author Riikka Kalliomäki * @copyright Copyright (c) 2013, Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ -class ObjectEncodingTest extends \PHPUnit_Framework_TestCase +class ObjectEncodingTest extends TestCase { public function testSerialize() { @@ -34,24 +39,32 @@ public function testStringConversion() 'object.method' => false, ]); - $mock = $this->getMock('Test\StringObject', ['toPHP']); - $mock->expects($this->exactly(0))->method('toPHP'); + $mock = $this->getMockBuilder(StringObject::class) + ->setMethods(['toPHP']) + ->getMock(); + $mock->expects($this->exactly(0))->method('toPHP'); $this->assertSame('Stringed', eval('return ' . $encoder->encode($mock) . ';')); } public function testPHPValue() { + $mock = $this->getMockBuilder('FakeTestMockObjectWithPHPValue') + ->setMethods(['toPHPValue']) + ->getMock(); + $encoder = new PHPEncoder(); - $mock = $this->getMock('TestMockObjectWithPHPValue', ['toPHPValue']); $mock->expects($this->once())->method('toPHPValue')->will($this->returnValue([])); $this->assertSame([], eval('return ' . $encoder->encode($mock) . ';')); } public function testPHP() { + $mock = $this->getMockBuilder('FakeTestMockObjectWithPHP') + ->setMethods(['toPHP']) + ->getMock(); + $encoder = new PHPEncoder(); - $mock = $this->getMock('TestMockObjectWithPHP', ['toPHP']); $mock->expects($this->once())->method('toPHP')->will($this->returnValue('"Mocked"')); $this->assertSame('"Mocked"', $encoder->encode($mock)); } @@ -82,10 +95,10 @@ public function testObjectExport() 'whitespace' => false, ]); - $obj = new \Test\ExtendsTestMockObject(); + $obj = new ExtendsTestMockObject(); $obj->var = true; $this->assertSame( - "\\Test\\ExtendsTestMockObject::__set_state(['bazC'=>'E','baz'=>'C'," . + sprintf("\%s::__set_state(['bazC'=>'E','baz'=>'C',", ExtendsTestMockObject::class) . "'var'=>true,'fooC'=>'D','bar'=>'B','foo'=>'A'])", $encoder->encode($obj) ); @@ -114,13 +127,16 @@ public function testArrayCasting() $obj = new \stdClass(); $this->assertSame('[]', $encoder->encode($obj)); - $mock = new \Test\TestMockObject(); + $mock = new TestMockObject(); $this->assertSame( - '["\x00Test\\\\TestMockObject\x00foo"=>\'A\',"\x00*\x00bar"=>\'B\',\'baz\'=>\'C\']', + sprintf( + '["\x00%s\x00foo"=>\'A\',"\x00*\x00bar"=>\'B\',\'baz\'=>\'C\']', + addcslashes(TestMockObject::class, '\\') + ), $encoder->encode($mock) ); $this->assertSame( - ["\0Test\\TestMockObject\0foo" => 'A', "\0*\0bar" => 'B', 'baz' => 'C'], + [sprintf("\0%s\0foo", TestMockObject::class) => 'A', "\0*\0bar" => 'B', 'baz' => 'C'], eval('return ' . $encoder->encode($mock) . ';') ); } @@ -128,14 +144,14 @@ public function testArrayCasting() public function testInvalidFormat() { $encoder = new PHPEncoder(['object.format' => 'invalid']); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $encoder->encode(new \stdClass()); } public function testInvalidFormatValueType() { $encoder = new PHPEncoder(['object.format' => true]); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $encoder->encode(new \stdClass()); } } From a740abb3051b943b0d3e2d51daabce8d4dedc773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sat, 8 Jul 2017 13:08:22 +0300 Subject: [PATCH 2/6] Normalise copyrights --- LICENSE | 2 +- README.md | 2 +- src/Encoder/ArrayEncoder.php | 2 +- src/Encoder/BooleanEncoder.php | 2 +- src/Encoder/Encoder.php | 2 +- src/Encoder/FloatEncoder.php | 2 +- src/Encoder/GMPEncoder.php | 2 +- src/Encoder/IntegerEncoder.php | 2 +- src/Encoder/NullEncoder.php | 2 +- src/Encoder/ObjectEncoder.php | 2 +- src/Encoder/StringEncoder.php | 2 +- src/InvalidOptionException.php | 2 +- src/PHPEncoder.php | 2 +- tests/tests/ArrayEncodingTest.php | 2 +- tests/tests/EncodingTest.php | 2 +- tests/tests/EncodingTestCase.php | 5 +++++ tests/tests/ObjectEncodingTest.php | 2 +- 17 files changed, 21 insertions(+), 16 deletions(-) diff --git a/LICENSE b/LICENSE index fbb77fc..7f2594c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013 - 2015 Riikka Kalliomäki +Copyright (c) 2013-2017 Riikka Kalliomäki Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 8c78b16..0c1a373 100644 --- a/README.md +++ b/README.md @@ -264,6 +264,6 @@ on HHVM. ## Credits ## -This library is copyright 2013 - 2015 to Riikka Kalliomäki. +This library is Copyright (c) 2013-2017 Riikka Kalliomäki. See LICENSE for license and copying information. diff --git a/src/Encoder/ArrayEncoder.php b/src/Encoder/ArrayEncoder.php index 6424dcd..2597b2c 100644 --- a/src/Encoder/ArrayEncoder.php +++ b/src/Encoder/ArrayEncoder.php @@ -5,7 +5,7 @@ /** * Encoder for array values. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class ArrayEncoder implements Encoder diff --git a/src/Encoder/BooleanEncoder.php b/src/Encoder/BooleanEncoder.php index c119b29..0797818 100644 --- a/src/Encoder/BooleanEncoder.php +++ b/src/Encoder/BooleanEncoder.php @@ -5,7 +5,7 @@ /** * Encoder for boolean values. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class BooleanEncoder implements Encoder diff --git a/src/Encoder/Encoder.php b/src/Encoder/Encoder.php index 33d7e03..0456bd1 100644 --- a/src/Encoder/Encoder.php +++ b/src/Encoder/Encoder.php @@ -5,7 +5,7 @@ /** * Interface for different types of value encoders. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ interface Encoder diff --git a/src/Encoder/FloatEncoder.php b/src/Encoder/FloatEncoder.php index f9a864a..2478b58 100644 --- a/src/Encoder/FloatEncoder.php +++ b/src/Encoder/FloatEncoder.php @@ -5,7 +5,7 @@ /** * Encoder for float values. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class FloatEncoder implements Encoder diff --git a/src/Encoder/GMPEncoder.php b/src/Encoder/GMPEncoder.php index e380d51..777004e 100644 --- a/src/Encoder/GMPEncoder.php +++ b/src/Encoder/GMPEncoder.php @@ -5,7 +5,7 @@ /** * Encoder for GMP number types. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class GMPEncoder implements Encoder diff --git a/src/Encoder/IntegerEncoder.php b/src/Encoder/IntegerEncoder.php index c233436..2377b80 100644 --- a/src/Encoder/IntegerEncoder.php +++ b/src/Encoder/IntegerEncoder.php @@ -5,7 +5,7 @@ /** * Encoder for integer values. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class IntegerEncoder implements Encoder diff --git a/src/Encoder/NullEncoder.php b/src/Encoder/NullEncoder.php index 0d6f6bb..ca6201d 100644 --- a/src/Encoder/NullEncoder.php +++ b/src/Encoder/NullEncoder.php @@ -5,7 +5,7 @@ /** * Encoder for null values. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class NullEncoder implements Encoder diff --git a/src/Encoder/ObjectEncoder.php b/src/Encoder/ObjectEncoder.php index 86629f3..dad4372 100644 --- a/src/Encoder/ObjectEncoder.php +++ b/src/Encoder/ObjectEncoder.php @@ -5,7 +5,7 @@ /** * Encoder for generic objects. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class ObjectEncoder implements Encoder diff --git a/src/Encoder/StringEncoder.php b/src/Encoder/StringEncoder.php index 78b353e..b7f2492 100644 --- a/src/Encoder/StringEncoder.php +++ b/src/Encoder/StringEncoder.php @@ -5,7 +5,7 @@ /** * Encoder for string values. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class StringEncoder implements Encoder diff --git a/src/InvalidOptionException.php b/src/InvalidOptionException.php index 4dd5e49..4243378 100644 --- a/src/InvalidOptionException.php +++ b/src/InvalidOptionException.php @@ -5,7 +5,7 @@ /** * Exception that gets thrown if invalid encoder options are used. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2015, Riikka Kalliomäki + * @copyright Copyright (c) 2015-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class InvalidOptionException extends \InvalidArgumentException diff --git a/src/PHPEncoder.php b/src/PHPEncoder.php index b7668fa..dfb91f8 100644 --- a/src/PHPEncoder.php +++ b/src/PHPEncoder.php @@ -11,7 +11,7 @@ * in specific way. * * @author Riikka Kalliomäki - * @copyright Copyright (c) 2013, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class PHPEncoder diff --git a/tests/tests/ArrayEncodingTest.php b/tests/tests/ArrayEncodingTest.php index c4ea5a3..b1c726f 100644 --- a/tests/tests/ArrayEncodingTest.php +++ b/tests/tests/ArrayEncodingTest.php @@ -4,7 +4,7 @@ /** * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class ArrayEncodingTest extends EncodingTestCase diff --git a/tests/tests/EncodingTest.php b/tests/tests/EncodingTest.php index 1daa6c7..4502cf5 100644 --- a/tests/tests/EncodingTest.php +++ b/tests/tests/EncodingTest.php @@ -7,7 +7,7 @@ /** * @author Riikka Kalliomäki - * @copyright Copyright (c) 2013, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class EncodingTest extends EncodingTestCase diff --git a/tests/tests/EncodingTestCase.php b/tests/tests/EncodingTestCase.php index d4e0abb..ce5e0ba 100644 --- a/tests/tests/EncodingTestCase.php +++ b/tests/tests/EncodingTestCase.php @@ -4,6 +4,11 @@ use PHPUnit\Framework\TestCase; +/** + * @author Riikka Kalliomäki + * @copyright Copyright (c) 2015-2017 Riikka Kalliomäki + * @license http://opensource.org/licenses/mit-license.php MIT License + */ class EncodingTestCase extends TestCase { /** diff --git a/tests/tests/ObjectEncodingTest.php b/tests/tests/ObjectEncodingTest.php index 13b1cd4..55a66db 100644 --- a/tests/tests/ObjectEncodingTest.php +++ b/tests/tests/ObjectEncodingTest.php @@ -9,7 +9,7 @@ /** * @author Riikka Kalliomäki - * @copyright Copyright (c) 2013, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class ObjectEncodingTest extends TestCase From 117cf68499d49d17aacfd6ef2360c9ccdb81ba1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sat, 8 Jul 2017 13:23:48 +0300 Subject: [PATCH 3/6] Fix test autoloading issue --- .travis.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9fe4bf3..5ce9717 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,23 +12,15 @@ cache: directories: - vendor -before_install: - - if [[ $TRAVIS_PHP_VERSION =~ ^7 ]]; then phpenv config-rm xdebug.ini; fi - install: - - travis_retry composer update --no-interaction + - travis_retry composer update -a --no-interaction - travis_retry wget https://scrutinizer-ci.com/ocular.phar before_script: - if [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; then echo 'xdebug.enable = On' >> /etc/hhvm/php.ini; fi script: - - > - if [[ $TRAVIS_PHP_VERSION =~ ^7 ]]; then - phpdbg -qrr vendor/phpunit/phpunit/phpunit --coverage-clover=coverage.clover --coverage-text; - else - vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text; - fi + - vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text; - vendor/bin/phpcs --standard=PSR2 src tests - vendor/bin/php-cs-fixer fix -v --dry-run --allow-risky=yes --using-cache=no From 25234ffdf2c30d6d6e6a912c34972fff138c3462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sat, 8 Jul 2017 17:47:59 +0300 Subject: [PATCH 4/6] Use xdebug only for coverage in travis --- .travis.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5ce9717..bbabc11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,10 @@ cache: directories: - vendor +before_install: + - export XDEBUG="/home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini" + - if [[ -f "$XDEBUG" ]]; then mv "$XDEBUG" "$XDEBUG.disabled"; fi + install: - travis_retry composer update -a --no-interaction - travis_retry wget https://scrutinizer-ci.com/ocular.phar @@ -20,7 +24,10 @@ before_script: - if [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; then echo 'xdebug.enable = On' >> /etc/hhvm/php.ini; fi script: - - vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text; + - > + if [[ -f "$XDEBUG.disabled" ]]; then mv "$XDEBUG.disabled" "$XDEBUG"; fi && + vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text && + if [[ -f "$XDEBUG" ]]; then mv "$XDEBUG" "$XDEBUG.disabled"; fi - vendor/bin/phpcs --standard=PSR2 src tests - vendor/bin/php-cs-fixer fix -v --dry-run --allow-risky=yes --using-cache=no From bf88d65f03634bf7a56e634f674943d6503eb26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sat, 8 Jul 2017 18:50:59 +0300 Subject: [PATCH 5/6] Use cleaner hhvm testing in travis --- .travis.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index bbabc11..3c0f7a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,25 +14,22 @@ cache: before_install: - export XDEBUG="/home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini" - - if [[ -f "$XDEBUG" ]]; then mv "$XDEBUG" "$XDEBUG.disabled"; fi + - is_hhvm () { [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; } + - is_hhvm || mv -v "$XDEBUG" "$XDEBUG.disabled" install: - travis_retry composer update -a --no-interaction - travis_retry wget https://scrutinizer-ci.com/ocular.phar before_script: - - if [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; then echo 'xdebug.enable = On' >> /etc/hhvm/php.ini; fi + - if is_hhvm; then echo 'xdebug.enable = On' >> /etc/hhvm/php.ini; fi script: - - > - if [[ -f "$XDEBUG.disabled" ]]; then mv "$XDEBUG.disabled" "$XDEBUG"; fi && - vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text && - if [[ -f "$XDEBUG" ]]; then mv "$XDEBUG" "$XDEBUG.disabled"; fi + - is_hhvm || mv -v "$XDEBUG.disabled" "$XDEBUG" + - vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text + - is_hhvm || mv -v "$XDEBUG" "$XDEBUG.disabled" - vendor/bin/phpcs --standard=PSR2 src tests - vendor/bin/php-cs-fixer fix -v --dry-run --allow-risky=yes --using-cache=no after_script: - - > - if [[ ! $TRAVIS_PHP_VERSION =~ ^hhvm ]]; then - php ocular.phar code-coverage:upload --format=php-clover coverage.clover; - fi + - is_hhvm || php ocular.phar code-coverage:upload --format=php-clover coverage.clover From 7703cb6d959846b10a74c02ba06bbe338bb2f653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sat, 8 Jul 2017 20:56:39 +0300 Subject: [PATCH 6/6] Use more elegant travis build --- .travis.yml | 10 +++------- CHANGES.md | 7 +++++++ README.md | 12 ------------ 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3c0f7a5..599b28f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ php: cache: directories: - - vendor + - vendor before_install: - export XDEBUG="/home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini" @@ -21,15 +21,11 @@ install: - travis_retry composer update -a --no-interaction - travis_retry wget https://scrutinizer-ci.com/ocular.phar -before_script: - - if is_hhvm; then echo 'xdebug.enable = On' >> /etc/hhvm/php.ini; fi - script: - - is_hhvm || mv -v "$XDEBUG.disabled" "$XDEBUG" - - vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text - - is_hhvm || mv -v "$XDEBUG" "$XDEBUG.disabled" - vendor/bin/phpcs --standard=PSR2 src tests - vendor/bin/php-cs-fixer fix -v --dry-run --allow-risky=yes --using-cache=no + - if is_hhvm; then echo "xdebug.enable = On" >> /etc/hhvm/php.ini; else mv -v "$XDEBUG.disabled" "$XDEBUG"; fi + - vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text after_script: - is_hhvm || php ocular.phar code-coverage:upload --format=php-clover coverage.clover diff --git a/CHANGES.md b/CHANGES.md index b0242de..40b6d67 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # Changelog # +## v2.2.0 (2017-07-08) ## + + * Increase the minimum PHP version requirement to 5.6 + * Update to latest coding standards + * Update tests to work with PHPUnit 6 + * Update travis build to test for PHP 7.1 + ## v2.1.3 (2015-11-08) ## * Ensure the tests run on both HHVM and PHP7 diff --git a/README.md b/README.md index 0c1a373..5c2b315 100644 --- a/README.md +++ b/README.md @@ -244,18 +244,6 @@ apply to following calls. ## Known Issues ## -### Recursive arrays on PHP < 5.4.5 ### - -If you try to encode recursive arrays on PHP versions earlier than 5.4.5, you -may encounter the following error (due to the way array comparisons work -internally in PHP): - -`Fatal error: Nesting level too deep - recursive dependency?` - -In order to fix this, you should disable the recursive array detection by -setting the option `recursion.detect` to false and set a value for the option -`recursion.max` to prevent recursive arrays from causing an infinite loop. - ### Float precision on HHVM ### Note that HHVM does not support the ini setting `serialize_precision`. Thus,