-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rector: CQ - SimplifyIfReturnBoolRector #4152
Changes from 15 commits
3d7eaf6
53ee2f8
89cc37c
e939180
35c91ef
a7fe45c
c7d6aeb
30fb790
3904b0f
f76521e
14468be
e788ea7
28f12c8
3fd569d
954fcdd
4fe6c68
392d0a8
f4c7890
b094298
79cd0e9
333d3f8
ba7e439
fb3621a
e20935e
1fb4750
b3cdb0a
fce8547
575046a
ea44e92
030a69c
1a84a3b
2db67c9
1a5704e
005833e
ae0df9e
5696be4
6110b0d
488acc8
7f09ae1
0fc002f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ jobs: | |
**phpcs** | ||
**php-cs-fixer** | ||
**phpstan** | ||
rector.php | ||
dev/tests/ | ||
dev/phpunit* | ||
dev/sonar* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Rector | ||
|
||
on: | ||
workflow_call: | ||
# Allow manually triggering the workflow. | ||
workflow_dispatch: | ||
|
||
jobs: | ||
rector: | ||
name: Validation | ||
runs-on: [ubuntu-latest] | ||
|
||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 7.4 | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get composer cache directory | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
|
||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-* | ||
|
||
- name: Rector | ||
run: php vendor/bin/rector process --dry-run |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -562,10 +562,7 @@ public function canShipPartially($order = null) | |||||||||||||
$order = Mage::registry('current_shipment')->getOrder(); | ||||||||||||||
} | ||||||||||||||
$value = $order->getCanShipPartially(); | ||||||||||||||
if (!is_null($value) && !$value) { | ||||||||||||||
return false; | ||||||||||||||
} | ||||||||||||||
return true; | ||||||||||||||
return !(!is_null($value) && !$value); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DeMorgan's Law
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -580,17 +577,11 @@ public function canShipPartiallyItem($order = null) | |||||||||||||
$order = Mage::registry('current_shipment')->getOrder(); | ||||||||||||||
} | ||||||||||||||
$value = $order->getCanShipPartiallyItem(); | ||||||||||||||
if (!is_null($value) && !$value) { | ||||||||||||||
return false; | ||||||||||||||
} | ||||||||||||||
return true; | ||||||||||||||
return !(!is_null($value) && !$value); | ||||||||||||||
Comment on lines
-577
to
+574
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DeMorgan's Law
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public function isShipmentRegular() | ||||||||||||||
{ | ||||||||||||||
if (!$this->canShipPartiallyItem() || !$this->canShipPartially()) { | ||||||||||||||
return false; | ||||||||||||||
} | ||||||||||||||
return true; | ||||||||||||||
return !(!$this->canShipPartiallyItem() || !$this->canShipPartially()); | ||||||||||||||
Comment on lines
-585
to
+579
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply DeMorgan's Law:
Suggested change
|
||||||||||||||
} | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -102,10 +102,7 @@ public function hasInvoiceShipmentTypeMismatch() | |||||||||||||
public function canShipPartiallyItem() | ||||||||||||||
{ | ||||||||||||||
$value = $this->getOrder()->getCanShipPartiallyItem(); | ||||||||||||||
if (!is_null($value) && !$value) { | ||||||||||||||
return false; | ||||||||||||||
} | ||||||||||||||
return true; | ||||||||||||||
return !(!is_null($value) && !$value); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DeMorgan's Law
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify with DeMorgan's Law
!(A && B) == (!A || !B)
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step by step ... :)
https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#simplifydemorganbinaryrector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh...so rector rules cannot be chained? It has to be worst before better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With rulessets (chained rules) the PRs would grow to large. Mhhh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhhh .... https://getrector.com/demo/ec03b365-db13-4e75-8ecd-d3773ae96870
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue: rectorphp/rector#8781