Skip to content

Commit

Permalink
Merge remote-tracking branch 'github.com/main' into feature/scalar-to…
Browse files Browse the repository at this point in the history
…-constfetch
  • Loading branch information
peterfox committed Aug 12, 2024
2 parents 30ffc3a + fa0d8d8 commit 1edc74c
Show file tree
Hide file tree
Showing 34 changed files with 513 additions and 164 deletions.
6 changes: 0 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;

return RectorConfig::configure()
->withPreparedSets(
Expand Down Expand Up @@ -50,11 +49,6 @@
// keep configs untouched, as the classes are just strings
UseClassKeywordForClassNameResolutionRector::class => [__DIR__ . '/config', '*/config/*'],

// race condition with stmts aware patch and PHPStan type
AddMethodCallBasedStrictParamTypeRector::class => [
__DIR__ . '/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php',
],

RemovePhpVersionIdCheckRector::class => [
__DIR__ . '/src/Util/FileHasher.php',
__DIR__ . '/src/Configuration/RectorConfigBuilder.php',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeNowAddSub
{
public function run()
{
$addSeconds = new \DateTime('+5 seconds');
$addMinutes = new \DateTime('+5 minutes');
$addHours = new \DateTime('+5 hours');
$addDays = new \DateTime('+5 days');
$addWeeks = new \DateTime('+5 weeks');
$addMonths = new \DateTime('+5 months');
$addYears = new \DateTime('+5 years');

$subSeconds = new \DateTime('-5 seconds');
$subMinuts = new \DateTime('-5 minutes');
$subHours = new \DateTime('-5 hours');
$subDays = new \DateTime('-5 days');
$subWeeks = new \DateTime('-5 weeks');
$subMonths = new \DateTime('-5 months');
$subYears = new \DateTime('-5 years');
}
}

?>
-----
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeNowAddSub
{
public function run()
{
$addSeconds = \Carbon\Carbon::now()->addSeconds(5);
$addMinutes = \Carbon\Carbon::now()->addMinutes(5);
$addHours = \Carbon\Carbon::now()->addHours(5);
$addDays = \Carbon\Carbon::now()->addDays(5);
$addWeeks = \Carbon\Carbon::now()->addWeeks(5);
$addMonths = \Carbon\Carbon::now()->addMonths(5);
$addYears = \Carbon\Carbon::now()->addYears(5);

$subSeconds = \Carbon\Carbon::now()->subSeconds(5);
$subMinuts = \Carbon\Carbon::now()->subMinutes(5);
$subHours = \Carbon\Carbon::now()->subHours(5);
$subDays = \Carbon\Carbon::now()->subDays(5);
$subWeeks = \Carbon\Carbon::now()->subWeeks(5);
$subMonths = \Carbon\Carbon::now()->subMonths(5);
$subYears = \Carbon\Carbon::now()->subYears(5);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeParse
{
public function run()
{
$date = new \DateTime('next week');
$exactDate = new \DateTime('2024-07-25');
$textualDate = new \DateTime('2 days ago');
}
}

?>
-----
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeParse
{
public function run()
{
$date = \Carbon\Carbon::parse('next week');
$exactDate = \Carbon\Carbon::parse('2024-07-25');
$textualDate = \Carbon\Carbon::parse('2 days ago');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeWithMonths
final class DateTimeToday
{
public function run()
{
$date = new \DateTime('+ 2 months');
$date = new \DateTime('today');
}
}

Expand All @@ -16,11 +16,11 @@ final class DateTimeWithMonths

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeWithMonths
final class DateTimeToday
{
public function run()
{
$date = \Carbon\Carbon::now()->addMonths(2);
$date = \Carbon\Carbon::today();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeNow
final class DateTimeTomorrow
{
public function run()
{
$date = new \DateTime('now');
$date = new \DateTime('tomorrow');
}
}

Expand All @@ -16,11 +16,11 @@ final class DateTimeNow

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeNow
final class DateTimeTomorrow
{
public function run()
{
$date = \Carbon\Carbon::now();
$date = \Carbon\Carbon::tomorrow();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeWithDateTime
{
public function run()
{
$date = new \DateTime('2024-07-30');
$time = new \DateTime('11:12:13');
$datetime = new \DateTime('2024-07-30 11:12:13');

$tomorrowTime = new \DateTime('tomorrow 12:00');
$yesterdayTime = new \DateTime('yesterday 12:00');

$dateNoon = new \DateTime('2024-07-30 noon');
$restStringToParse = new \DateTime('tomorrow noon');

$fullDate = new \DateTime('2024-07-30T11:12:13.000Z');
}
}

?>
-----
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeWithDateTime
{
public function run()
{
$date = \Carbon\Carbon::parse('2024-07-30');
$time = \Carbon\Carbon::parse('11:12:13');
$datetime = \Carbon\Carbon::parse('2024-07-30 11:12:13');

$tomorrowTime = \Carbon\Carbon::parse('12:00 tomorrow');
$yesterdayTime = \Carbon\Carbon::parse('12:00 yesterday');

$dateNoon = \Carbon\Carbon::parse('2024-07-30 noon');
$restStringToParse = \Carbon\Carbon::parse('noon tomorrow');

$fullDate = \Carbon\Carbon::parse('2024-07-30T11:12:13.000Z');
}
}

?>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeYesterday
{
public function run()
{
$date = new \DateTime('yesterday');
}
}

?>
-----
<?php

namespace Rector\Tests\Carbon\Rector\New_\DateTimeInstanceToCarbonRector\Fixture;

final class DateTimeYesterday
{
public function run()
{
$date = \Carbon\Carbon::yesterday();
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

final class SkipAssignOp
{
private string $name;
private int $count;

public function __construct(string $name, bool $flag = false)
{
$this->name = $name;

if ($flag) {
$this->name .= 'changed';
}

$this->count = 0;
if ($flag) {
++$this->count;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Fixture;

use Rector\Symfony\CodeQuality\Rector\ClassMethod\ResponseReturnTypeControllerActionRector;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;

final class IncludeResponseOutsideController
{
public function create()
{
return new JsonResponse();
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Fixture;

use Rector\Symfony\CodeQuality\Rector\ClassMethod\ResponseReturnTypeControllerActionRector;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;

final class IncludeResponseOutsideController
{
public function create(): \Symfony\Component\HttpFoundation\JsonResponse
{
return new JsonResponse();
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Fixture;

use Rector\Symfony\CodeQuality\Rector\ClassMethod\ResponseReturnTypeControllerActionRector;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
* Handled in another rule, @see ResponseReturnTypeControllerActionRector
*/
class SkipResponse extends Controller
{
public function create()
{
return new JsonResponse();
}
}
Loading

0 comments on commit 1edc74c

Please sign in to comment.