Skip to content

Commit

Permalink
Enforce native types for PHP 7.4+
Browse files Browse the repository at this point in the history
Incorporating changes to our tests.
  • Loading branch information
lcobucci committed Dec 5, 2019
1 parent 78c6547 commit f9d89e0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
.PHONY: test test-report test-fix

PHP_74_OR_NEWER=`php -r "echo (int) version_compare(PHP_VERSION, '7.4', '>=');"`

test: test-report test-fix

test-report: vendor
@vendor/bin/phpcs `find tests/input/* | sort` --report=summary --report-file=phpcs.log; diff tests/expected_report.txt phpcs.log

@if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply tests/php-compatibility.patch; fi
@vendor/bin/phpcs `find tests/input/* | sort` --report=summary --report-file=phpcs.log; diff tests/expected_report.txt phpcs.log; if [ $$? -ne 0 ] && [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply -R tests/php-compatibility.patch; exit 1; fi
@if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply -R tests/php-compatibility.patch; fi

test-fix: vendor
@if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply tests/php-compatibility.patch; fi
@cp -R tests/input/ tests/input2/
@vendor/bin/phpcbf tests/input2; diff tests/input2 tests/fixed; if [ $$? -ne 0 ]; then rm -rf tests/input2/; exit 1; fi
@rm -rf tests/input2/
@vendor/bin/phpcbf tests/input2; diff tests/input2 tests/fixed; if [ $$? -ne 0 ]; then rm -rf tests/input2/ && if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply -R tests/php-compatibility.patch; fi; exit 1; fi
@rm -rf tests/input2/ && if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply -R tests/php-compatibility.patch; fi

vendor: composer.json
composer update
1 change: 0 additions & 1 deletion lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<property name="enableNativeTypeHint" value="false"/>
<property name="traversableTypeHints" type="array">
<element value="Traversable"/>
<element value="Iterator"/>
Expand Down
67 changes: 67 additions & 0 deletions tests/php-compatibility.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 855edfd..5653a39 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -12,7 +12,7 @@ tests/input/constants-var.php 4 0
tests/input/doc-comment-spacing.php 10 0
tests/input/duplicate-assignment-variable.php 1 0
tests/input/EarlyReturn.php 6 0
-tests/input/example-class.php 45 0
+tests/input/example-class.php 48 0
tests/input/forbidden-comments.php 8 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 7 0
@@ -32,15 +32,15 @@ tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
tests/input/trailing_comma_on_array.php 1 0
tests/input/traits-uses.php 11 0
-tests/input/type-hints.php 4 0
+tests/input/type-hints.php 5 0
tests/input/UnusedVariables.php 1 0
tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 290 ERRORS AND 0 WARNINGS WERE FOUND IN 34 FILES
+A TOTAL OF 294 ERRORS AND 0 WARNINGS WERE FOUND IN 34 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 229 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 233 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


diff --git a/tests/fixed/example-class.php b/tests/fixed/example-class.php
index 195d963..a2ee5c8 100644
--- a/tests/fixed/example-class.php
+++ b/tests/fixed/example-class.php
@@ -24,14 +24,12 @@ class Example implements IteratorAggregate
{
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;

- /** @var int|null */
- private $foo;
+ private ?int $foo = null;

/** @var string[] */
- private $bar;
+ private array $bar;

- /** @var bool */
- private $baz;
+ private bool $baz;

/** @var ControlStructureSniff|int|string|null */
private $baxBax;
diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php
index a1b1827..fb7d406 100644
--- a/tests/fixed/type-hints.php
+++ b/tests/fixed/type-hints.php
@@ -10,7 +10,7 @@ use Traversable;
class TraversableTypeHints
{
/** @var Traversable */
- private $parameter;
+ private Traversable $parameter;

/**
* @param Iterator $iterator

0 comments on commit f9d89e0

Please sign in to comment.