Skip to content

OpAssignShortSyntax ​

info on by default quick-fix

Group: Code style · PhpStorm name: OpAssignShortSyntaxInspection

$total = $total + $step repeats the target; the compound assignment $total += $step says the same thing more directly.

Example ​

php
<?php
function tally(int $count, string $label, array $grid, $buf) {
    $count = $count + 5;
    $count = $count - $step;
    $count = ($count % 7);
    $count = $count << 1;
    $label = $label . '-' . $count . '!';
    $count = $count * 3 * $k;
    $count = $count + ($k * 2);
    $grid[1] = $grid[1] | 4;
    $buf[0] = $buf[0] . 'z';

    $count = 5 + $count;          // reversed operands
    $count = $count - $a - $b;    // '-' cannot be regrouped
    $count = $count + $k * 2;     // fragment is a binary expression
    $count = $count ** 2;         // '**' not eligible
    $label[0] = $label[0] . 'x';  // string offset (typed string)
}
php
<?php
function tally(int $count, string $label, array $grid, $buf) {
    $count += 5;
    $count -= $step;
    $count %= 7;
    $count <<= 1;
    $label .= '-' . $count . '!';
    $count *= 3 * $k;
    $count += ($k * 2);
    $grid[1] |= 4;
    $buf[0] .= 'z';

    $count = 5 + $count;          // reversed operands
    $count = $count - $a - $b;    // '-' cannot be regrouped
    $count = $count + $k * 2;     // fragment is a binary expression
    $count = $count ** 2;         // '**' not eligible
    $label[0] = $label[0] . 'x';  // string offset (typed string)
}

Reported:

  • line 3: Use the compound form '$count += 5'.
  • line 4: Use the compound form '$count -= $step'.
  • line 5: Use the compound form '$count %= 7'.
  • line 6: Use the compound form '$count <<= 1'.
  • line 7: Use the compound form '$label .= '-' . $count . '!''.
  • line 8: Use the compound form '$count *= 3 * $k'.
  • line 9: Use the compound form '$count += ($k * 2)'.
  • line 10: Use the compound form '$grid[1] |= 4'.
  • line 11: Use the compound form '$buf[0] .= 'z''.

Configure ​

In custos.json:

json
{
  "rules": {
    "OpAssignShortSyntax": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file), either of:

php
// @custos-ignore OpAssignShortSyntax

/**
 * @noinspection OpAssignShortSyntaxInspection
 */

Released under the MIT License. Rule catalogue modelled on Php Inspections (EA Extended); independent clean-room implementation.