123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Fixer\ReturnNotation;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer>
- */
- final class NoUselessReturnFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{0: non-empty-string, 1?: non-empty-string}>
- */
- public static function provideFixCases(): iterable
- {
- yield [
- '<?php
- function bar($baz)
- {
- if ($baz)
- return $this->baz();
- else
- return;
- }',
- ];
- yield [
- '<?php
- function bar($baz)
- {
- if ($baz)
- return $this->baz();
- elseif($a)
- return;
- }',
- ];
- yield [
- '<?php
- function bar($baz)
- {
- if ($baz)
- return $this->baz();
- else if($a)
- return;
- }',
- ];
- yield [
- '<?php
- function bar($baz)
- {
- if ($baz)
- return;
- }',
- ];
- yield [
- '<?php
- function b($b) {
- if ($b) {
- return;
- }
- /**/
- }',
- '<?php
- function b($b) {
- if ($b) {
- return;
- }
- return /**/;
- }',
- ];
- yield [
- '<?php
- class Test2
- {
- private static function a($a)
- {
- if ($a) {
- return;
- }
- $c1 = function() use ($a) {
- if ($a)
- return;
- if ($a > 1) return;
- echo $a;
- '.'
- };
- $c1();
- '.'
- '.'
- }
- private function test()
- {
- $d = function(){
- echo 123;
- '.'
- };
- $d();
- }
- }',
- '<?php
- class Test2
- {
- private static function a($a)
- {
- if ($a) {
- return;
- }
- $c1 = function() use ($a) {
- if ($a)
- return;
- if ($a > 1) return;
- echo $a;
- return;
- };
- $c1();
- return
- ;
- }
- private function test()
- {
- $d = function(){
- echo 123;
- return;
- };
- $d();
- }
- }',
- ];
- yield [
- '<?php
- function aT($a) {
- if ($a) {
- return;
- }
- '.'
- }',
- '<?php
- function aT($a) {
- if ($a) {
- return;
- }
- return ;
- }',
- ];
- yield [
- '<?php return;',
- ];
- yield [
- '<?php
- function c($c) {
- if ($c) {
- return;
- }
- //'.'
- }',
- '<?php
- function c($c) {
- if ($c) {
- return;
- }
- return;//
- }',
- ];
- yield [
- '<?php
- class Test {
- private static function d($d) {
- if ($d) {
- return;
- }
- }
- }',
- '<?php
- class Test {
- private static function d($d) {
- if ($d) {
- return;
- }
- return;}
- }',
- ];
- yield [
- '<?php
- interface FooInterface
- {
- public function fnc();
- }',
- ];
- yield [
- '<?php
- abstract class AbstractFoo
- {
- abstract public function fnc();
- abstract public function fnc1();
- static private function fn2(){}
- public function fnc3() {
- echo 1 . self::fn2();//{}
- }
- }',
- ];
- yield [
- '<?php
- function foo () { }',
- ];
- yield [
- '<?php
- $a = function() {
- /**/
- '.'
- /* a */ //
- '.'
- };
- ',
- '<?php
- $a = function() {
- return ; /**/
- return ;
- /* a */ return; //
- return;
- };
- ',
- ];
- }
- }
|