Skip to content

Commit

Permalink
Merge pull request #213 from laravel/fix/non-yoda-style-moving-variables
Browse files Browse the repository at this point in the history
[1.x] Fixes non yoda style moving variables
  • Loading branch information
nunomaduro authored Sep 6, 2023
2 parents 957d290 + 08957b8 commit c5c2e3c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Actions/ElaborateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function execute($totalFiles, $changes)
$totalFiles,
0,
0,
OutputInterface::VERBOSITY_VERBOSE <= $this->output->getVerbosity(),
$this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE,
$this->input->getOption('test'),
$this->output->isDecorated()
);
Expand Down
2 changes: 1 addition & 1 deletion resources/presets/laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
],
'whitespace_after_comma_in_array' => true,
'yoda_style' => [
'always_move_variable' => true,
'always_move_variable' => false,
'equal' => false,
'identical' => false,
'less_and_greater' => false,
Expand Down
21 changes: 21 additions & 0 deletions tests/Feature/Fixers/YodaStyleFixerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => base_path('tests/Fixtures/fixers/yoda_style.php'),
'--preset' => 'laravel',
]);

expect($statusCode)->toBe(1)
->and($output)
->toContain('')
->toContain('@@ -20,6 +20,6 @@')
->toContain(
<<<'EOF'
-if (null === $int) {
+if ($int === null) {
//
}
EOF,
);
});
25 changes: 25 additions & 0 deletions tests/Fixtures/fixers/yoda_style.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$int = 1;
$array = [];
$object = new stdClass();

if (count($array) === (count($array) - intval(isset($array['a'])))) {
//
}

if ($object->count() === $int) {
//
}

if (array_values($array) !== $array) {
//
}

if ($object->int === $int && (int) $object->int === $int) {
//
}

if (null === $int) {
//
}

0 comments on commit c5c2e3c

Please sign in to comment.