Skip to content

Commit

Permalink
Fixes yoda style moving variables
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Sep 6, 2023
1 parent 957d290 commit 03431ca
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
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 ($this->guard === $guard && (int) $this->user_id === $userId) {
//
}

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

0 comments on commit 03431ca

Please sign in to comment.