diff --git a/.travis.yml b/.travis.yml index d67b6911..f48ac6af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,18 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm matrix: allow_failures: + - php: 7.0 - php: hhvm + include: + - php: 5.6 + env: dependencies="--prefer-lowest --prefer-stable" + script: - vendor/bin/tester tests -s -p php - php code-checker/src/code-checker.php @@ -20,5 +26,11 @@ after_failure: before_script: # Install Nette Tester & Code Checker - - composer install --no-interaction --dev --prefer-source - - composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source + - travis_retry composer update --no-interaction --prefer-dist $dependencies + - travis_retry composer create-project nette/code-checker code-checker ~2.5 --no-interaction + +sudo: false + +cache: + directories: + - $HOME/.composer/cache diff --git a/composer.json b/composer.json index a61bd64a..fc8a21f8 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "nette/utils": "~2.2" }, "require-dev": { - "nette/tester": "~1.0" + "nette/tester": "~1.4" }, "conflict": { "nette/nette": "<2.2" @@ -26,10 +26,5 @@ "autoload": { "classmap": ["src/"] }, - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - } + "minimum-stability": "dev" } diff --git a/readme.md b/readme.md index a34ac641..eb02b060 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ Nette PHP Generator =================== [![Downloads this Month](https://img.shields.io/packagist/dm/nette/php-generator.svg)](https://packagist.org/packages/nette/php-generator) -[![Build Status](https://travis-ci.org/nette/php-generator.svg?branch=master)](https://travis-ci.org/nette/php-generator) +[![Build Status](https://travis-ci.org/nette/php-generator.svg?branch=v2.3)](https://travis-ci.org/nette/php-generator) Generate PHP code with a simple programmatical API. diff --git a/src/PhpGenerator/ClassType.php b/src/PhpGenerator/ClassType.php index 43939a9a..6dfb54cb 100644 --- a/src/PhpGenerator/ClassType.php +++ b/src/PhpGenerator/ClassType.php @@ -7,14 +7,12 @@ namespace Nette\PhpGenerator; -use Nette, - Nette\Utils\Strings; +use Nette; +use Nette\Utils\Strings; /** * Class/Interface/Trait description. - * - * @author David Grudl */ class ClassType extends Nette\Object { diff --git a/src/PhpGenerator/Helpers.php b/src/PhpGenerator/Helpers.php index eb4e5798..4c198df8 100644 --- a/src/PhpGenerator/Helpers.php +++ b/src/PhpGenerator/Helpers.php @@ -12,8 +12,6 @@ /** * PHP code generator utils. - * - * @author David Grudl */ class Helpers { @@ -114,7 +112,7 @@ private static function _dump(& $var, $level = 0) } foreach ($arr as $k => & $v) { if (!isset($props) || isset($props[$k])) { - $out .= "$space\t" . self::_dump($k, $level + 1) . " => " . self::_dump($v, $level + 1) . ",\n"; + $out .= "$space\t" . self::_dump($k, $level + 1) . ' => ' . self::_dump($v, $level + 1) . ",\n"; } } array_pop($list); @@ -189,7 +187,7 @@ public static function formatMember($name) { return $name instanceof PhpLiteral || !self::isIdentifier($name) ? '{' . self::_dump($name) . '}' - : $name ; + : $name; } diff --git a/src/PhpGenerator/Method.php b/src/PhpGenerator/Method.php index 3823391a..83fadcdf 100644 --- a/src/PhpGenerator/Method.php +++ b/src/PhpGenerator/Method.php @@ -12,8 +12,6 @@ /** * Class method description. - * - * @author David Grudl */ class Method extends Nette\Object { diff --git a/src/PhpGenerator/Parameter.php b/src/PhpGenerator/Parameter.php index a70d72e7..77870991 100644 --- a/src/PhpGenerator/Parameter.php +++ b/src/PhpGenerator/Parameter.php @@ -12,8 +12,6 @@ /** * Method parameter description. - * - * @author David Grudl */ class Parameter extends Nette\Object { @@ -54,7 +52,7 @@ public static function from(\ReflectionParameter $from) $param->defaultValue = (PHP_VERSION_ID === 50316 ? $from->isOptional() : $from->isDefaultValueAvailable()) ? $from->getDefaultValue() : NULL; $namespace = $from->getDeclaringClass()->getNamespaceName(); - $namespace = $namespace ? "\\$namespace\\" : "\\"; + $namespace = $namespace ? "\\$namespace\\" : '\\'; if (Nette\Utils\Strings::startsWith($param->typeHint, $namespace)) { $param->typeHint = substr($param->typeHint, strlen($namespace)); } diff --git a/src/PhpGenerator/PhpFile.php b/src/PhpGenerator/PhpFile.php index a210eb67..bf0976ee 100644 --- a/src/PhpGenerator/PhpFile.php +++ b/src/PhpGenerator/PhpFile.php @@ -18,8 +18,6 @@ * - opening tag ( */ class PhpFile extends Object { diff --git a/src/PhpGenerator/PhpLiteral.php b/src/PhpGenerator/PhpLiteral.php index 19f23c92..be8a2463 100644 --- a/src/PhpGenerator/PhpLiteral.php +++ b/src/PhpGenerator/PhpLiteral.php @@ -7,13 +7,9 @@ namespace Nette\PhpGenerator; -use Nette; - /** * PHP literal value. - * - * @author David Grudl */ class PhpLiteral { diff --git a/src/PhpGenerator/PhpNamespace.php b/src/PhpGenerator/PhpNamespace.php index b6dfd4e1..db3d3798 100644 --- a/src/PhpGenerator/PhpNamespace.php +++ b/src/PhpGenerator/PhpNamespace.php @@ -19,8 +19,6 @@ * - namespace statement * - variable amount of use statements * - one or more class declarations - * - * @author Jakub Kulhan */ class PhpNamespace extends Object { diff --git a/src/PhpGenerator/Property.php b/src/PhpGenerator/Property.php index 558eb6b8..4761d0a2 100644 --- a/src/PhpGenerator/Property.php +++ b/src/PhpGenerator/Property.php @@ -12,8 +12,6 @@ /** * Class property description. - * - * @author David Grudl */ class Property extends Nette\Object { diff --git a/tests/PhpGenerator/ClassType.from.phpt b/tests/PhpGenerator/ClassType.from.phpt index bd440d3f..77337b43 100644 --- a/tests/PhpGenerator/ClassType.from.phpt +++ b/tests/PhpGenerator/ClassType.from.phpt @@ -6,9 +6,9 @@ namespace Abc; -use Nette\PhpGenerator\ClassType, - ReflectionClass, - Tester\Assert; +use Nette\PhpGenerator\ClassType; +use ReflectionClass; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/PhpGenerator/ClassType.from.trait.phpt b/tests/PhpGenerator/ClassType.from.trait.phpt index 1c2f1f75..cb5539f6 100644 --- a/tests/PhpGenerator/ClassType.from.trait.phpt +++ b/tests/PhpGenerator/ClassType.from.trait.phpt @@ -5,8 +5,8 @@ * @phpversion 5.4 */ -use Nette\PhpGenerator\ClassType, - Tester\Assert; +use Nette\PhpGenerator\ClassType; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/PhpGenerator/ClassType.inheritance.phpt b/tests/PhpGenerator/ClassType.inheritance.phpt index 93441050..3aad1bfc 100644 --- a/tests/PhpGenerator/ClassType.inheritance.phpt +++ b/tests/PhpGenerator/ClassType.inheritance.phpt @@ -1,8 +1,8 @@ 'b', 'c', '9a' => 'd', 'e')", Helpers::dump(array('a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e')) ); -Assert::same( "array(\n\tarray(\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooong',\n\t),\n)", Helpers::dump(array(array('a', 'loooooooooooooooooooooooooooooooooong'))) ); -Assert::same( "array('a' => 1, array(\"\\r\" => \"\\r\", 2), 3)", Helpers::dump(array('a' => 1, array("\r" => "\r", 2), 3)) ); +Assert::same('array(1, 2, 3)', Helpers::dump(array(1, 2, 3))); +Assert::same("array('a', 7 => 'b', 'c', '9a' => 'd', 'e')", Helpers::dump(array('a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e'))); +Assert::same("array(\n\tarray(\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooong',\n\t),\n)", Helpers::dump(array(array('a', 'loooooooooooooooooooooooooooooooooong')))); +Assert::same("array('a' => 1, array(\"\\r\" => \"\\r\", 2), 3)", Helpers::dump(array('a' => 1, array("\r" => "\r", 2), 3))); -Assert::same( "(object) array(\n\t'a' => 1,\n\t'b' => 2,\n)", Helpers::dump((object) array('a' => 1, 'b' => 2)) ); -Assert::same( "(object) array(\n\t'a' => (object) array(\n\t\t'b' => 2,\n\t),\n)" , Helpers::dump((object) array('a' => (object) array('b' => 2))) ); +Assert::same("(object) array(\n\t'a' => 1,\n\t'b' => 2,\n)", Helpers::dump((object) array('a' => 1, 'b' => 2))); +Assert::same("(object) array(\n\t'a' => (object) array(\n\t\t'b' => 2,\n\t),\n)", Helpers::dump((object) array('a' => (object) array('b' => 2)))); class Test @@ -44,8 +44,8 @@ class Test private $c = 3; } -Assert::same( "Nette\\PhpGenerator\\Helpers::createObject('Test', array(\n\t'a' => 1,\n\t\"\\x00*\\x00b\" => 2,\n\t\"\\x00Test\\x00c\" => 3,\n))", Helpers::dump(new Test) ); -Assert::equal( new Test, eval('return ' . Helpers::dump(new Test) . ';') ); +Assert::same("Nette\\PhpGenerator\\Helpers::createObject('Test', array(\n\t'a' => 1,\n\t\"\\x00*\\x00b\" => 2,\n\t\"\\x00Test\\x00c\" => 3,\n))", Helpers::dump(new Test)); +Assert::equal(new Test, eval('return ' . Helpers::dump(new Test) . ';')); class Test2 extends Test @@ -63,8 +63,8 @@ class Test2 extends Test } } -Assert::same( "Nette\\PhpGenerator\\Helpers::createObject('Test2', array(\n\t\"\\x00Test2\\x00c\" => 4,\n\t'a' => 1,\n\t\"\\x00*\\x00b\" => 2,\n))", Helpers::dump(new Test2) ); -Assert::equal( new Test2, eval('return ' . Helpers::dump(new Test2) . ';') ); +Assert::same("Nette\\PhpGenerator\\Helpers::createObject('Test2', array(\n\t\"\\x00Test2\\x00c\" => 4,\n\t'a' => 1,\n\t\"\\x00*\\x00b\" => 2,\n))", Helpers::dump(new Test2)); +Assert::equal(new Test2, eval('return ' . Helpers::dump(new Test2) . ';')); class Test3 implements Serializable @@ -81,5 +81,5 @@ class Test3 implements Serializable } } -Assert::same( 'unserialize(\'C:5:"Test3":0:{}\')', Helpers::dump(new Test3) ); -Assert::equal( new Test3, eval('return ' . Helpers::dump(new Test3) . ';') ); +Assert::same('unserialize(\'C:5:"Test3":0:{}\')', Helpers::dump(new Test3)); +Assert::equal(new Test3, eval('return ' . Helpers::dump(new Test3) . ';')); diff --git a/tests/PhpGenerator/Helpers.format.phpt b/tests/PhpGenerator/Helpers.format.phpt index a08a8a2f..440e8007 100644 --- a/tests/PhpGenerator/Helpers.format.phpt +++ b/tests/PhpGenerator/Helpers.format.phpt @@ -4,40 +4,40 @@ * Test: Nette\PhpGenerator\Helpers::format() & formatArgs() */ -use Nette\PhpGenerator\Helpers, - Tester\Assert; +use Nette\PhpGenerator\Helpers; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Assert::same( 'func', Helpers::format('func') ); -Assert::same( 'func(1)', Helpers::format('func(?)', 1, 2) ); +Assert::same('func', Helpers::format('func')); +Assert::same('func(1)', Helpers::format('func(?)', 1, 2)); -Assert::same( 'func', Helpers::formatArgs('func', array(1, 2)) ); -Assert::same( 'func(1)', Helpers::formatArgs('func(?)', array(1, 2)) ); -Assert::same( "func(array(1, 2))", Helpers::formatArgs('func(?)', array(array(1, 2))) ); -Assert::same( 'func(1, 2)', Helpers::formatArgs('func(?*)', array(array(1, 2))) ); +Assert::same('func', Helpers::formatArgs('func', array(1, 2))); +Assert::same('func(1)', Helpers::formatArgs('func(?)', array(1, 2))); +Assert::same('func(array(1, 2))', Helpers::formatArgs('func(?)', array(array(1, 2)))); +Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', array(array(1, 2)))); Assert::same( "func(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,\n\t35, 36, 37, 38, 39, 40)", Helpers::formatArgs('func(?*)', array(range(10, 40))) ); -Assert::exception(function() { +Assert::exception(function () { Helpers::formatArgs('func(?*)', array(1, 2)); }, 'Nette\InvalidArgumentException', 'Argument must be an array.'); -Assert::exception(function() { +Assert::exception(function () { Helpers::formatArgs('func(?, ?, ?)', array(1, 2)); }, 'Nette\InvalidArgumentException', 'Insufficient number of arguments.'); -Assert::same( '$a = 2', Helpers::formatArgs('$? = ?', array('a', 2)) ); -Assert::same( '$obj->a = 2', Helpers::formatArgs('$obj->? = ?', array('a', 2)) ); -Assert::same( '$obj->{1} = 2', Helpers::formatArgs('$obj->? = ?', array(1, 2)) ); -Assert::same( '$obj->{\' \'} = 2', Helpers::formatArgs('$obj->? = ?', array(' ', 2)) ); +Assert::same('$a = 2', Helpers::formatArgs('$? = ?', array('a', 2))); +Assert::same('$obj->a = 2', Helpers::formatArgs('$obj->? = ?', array('a', 2))); +Assert::same('$obj->{1} = 2', Helpers::formatArgs('$obj->? = ?', array(1, 2))); +Assert::same('$obj->{\' \'} = 2', Helpers::formatArgs('$obj->? = ?', array(' ', 2))); -Assert::same( "Item", Helpers::formatMember('Item') ); -Assert::same( "{'0Item'}", Helpers::formatMember('0Item') ); +Assert::same('Item', Helpers::formatMember('Item')); +Assert::same("{'0Item'}", Helpers::formatMember('0Item')); -Assert::true( Helpers::isIdentifier('Item') ); -Assert::false( Helpers::isIdentifier('0Item') ); +Assert::true(Helpers::isIdentifier('Item')); +Assert::false(Helpers::isIdentifier('0Item')); diff --git a/tests/PhpGenerator/Method.closure.phpt b/tests/PhpGenerator/Method.closure.phpt index 35310426..32989bb1 100644 --- a/tests/PhpGenerator/Method.closure.phpt +++ b/tests/PhpGenerator/Method.closure.phpt @@ -4,8 +4,8 @@ * Test: Nette\PhpGenerator & closure. */ -use Nette\PhpGenerator\Method, - Tester\Assert; +use Nette\PhpGenerator\Method; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/PhpGenerator/Method.variadics.phpt b/tests/PhpGenerator/Method.variadics.phpt index 147e81a4..2d6450c7 100644 --- a/tests/PhpGenerator/Method.variadics.phpt +++ b/tests/PhpGenerator/Method.variadics.phpt @@ -5,9 +5,9 @@ * @phpversion 5.6 */ -use Nette\PhpGenerator\Method, - Nette\PhpGenerator\Parameter, - Tester\Assert; +use Nette\PhpGenerator\Method; +use Nette\PhpGenerator\Parameter; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; diff --git a/tests/PhpGenerator/PhpNamespace.phpt b/tests/PhpGenerator/PhpNamespace.phpt index 51c36eb0..781cafd9 100644 --- a/tests/PhpGenerator/PhpNamespace.phpt +++ b/tests/PhpGenerator/PhpNamespace.phpt @@ -28,7 +28,7 @@ Assert::same($namespace, $classA->getNamespace()); $interfaceB = $namespace->addInterface('B'); Assert::same($namespace, $interfaceB->getNamespace()); -Assert::exception(function() use ($namespace) { +Assert::exception(function () use ($namespace) { $traitC = $namespace->addTrait('C'); Assert::same($namespace, $traitC->getNamespace()); }, 'Nette\InvalidStateException', "Alias 'C' used already for 'Bar\\C', cannot use for 'Foo\\C'."); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5e83a184..7335ebe1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,7 +4,7 @@ // invoked through the command: ../vendor/bin/tester . if (@!include __DIR__ . '/../vendor/autoload.php') { - echo 'Install Nette Tester using `composer update --dev`'; + echo 'Install Nette Tester using `composer install`'; exit(1); }