Skip to content

Commit de206f7

Browse files
committed
fix - superequals - #91
1 parent 508a276 commit de206f7

13 files changed

Lines changed: 298 additions & 0 deletions

fmt.stub.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7552,6 +7552,28 @@ public function format($source) {
75527552
$blockCountEquals[$blockCounter] = 0;
75537553
}
75547554
break;
7555+
case T_WHILE:
7556+
case T_FOR:
7557+
case T_FOREACH:
7558+
case T_IF:
7559+
case T_ELSEIF:
7560+
case T_ELSE:
7561+
case T_SWITCH:
7562+
case T_TRY:
7563+
case T_CATCH:
7564+
case T_FINALLY:
7565+
case T_FUNCTION:
7566+
case T_CLASS:
7567+
case ST_CURLY_OPEN:
7568+
// Start a new block when entering control structures
7569+
$blockCounter++;
7570+
$blockCountEquals[$blockCounter] = 0;
7571+
break;
7572+
case ST_CURLY_CLOSE:
7573+
// Start a new block when exiting control structures
7574+
$blockCounter++;
7575+
$blockCountEquals[$blockCounter] = 0;
7576+
break;
75557577
case ST_EQUAL:
75567578
case T_PLUS_EQUAL:
75577579
case T_MINUS_EQUAL:
@@ -7590,18 +7612,43 @@ public function format($source) {
75907612
}
75917613
$this->appendCode($text);
75927614
break;
7615+
case T_WHILE:
7616+
case T_FOR:
7617+
case T_FOREACH:
7618+
case T_IF:
7619+
case T_ELSEIF:
7620+
case T_ELSE:
7621+
case T_SWITCH:
7622+
case T_TRY:
7623+
case T_CATCH:
7624+
case T_FINALLY:
7625+
// Start a new block when entering control structures
7626+
$blockCounter++;
7627+
$this->appendCode($text);
7628+
break;
75937629
case T_FUNCTION:
75947630
++$contextCounter;
7631+
// Start a new block when entering function
7632+
$blockCounter++;
7633+
$this->appendCode($text);
7634+
break;
7635+
case T_CLASS:
7636+
// Start a new block when entering class
7637+
$blockCounter++;
75957638
$this->appendCode($text);
75967639
break;
75977640

75987641
case ST_CURLY_OPEN:
7642+
// Start a new block when entering curly block
7643+
$blockCounter++;
75997644
$this->appendCode($text);
76007645
$block = $this->walkAndAccumulateCurlyBlock($this->tkns);
76017646
$aligner = new self();
76027647
$this->appendCode(
76037648
str_replace(self::OPEN_TAG, '', $aligner->format(self::OPEN_TAG . $block))
76047649
);
7650+
// Start a new block when exiting curly block
7651+
$blockCounter++;
76057652
break;
76067653

76077654
case ST_PARENTHESES_OPEN:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
$salted = '';
3+
$dx = '';
4+
while (strlen($salted) < 48) {
5+
$dx = md5($dx . $passphrase . $salt, true);
6+
$salted .= $dx;
7+
}
8+
$key = substr($salted, 0, 32);
9+
$iv = substr($salted, 32, 16);
10+
return [$key, $iv];
11+
//passes:AlignSuperEquals
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
$salted = '';
3+
$dx = '';
4+
while (strlen($salted) < 48) {
5+
$dx = md5($dx . $passphrase . $salt, true);
6+
$salted .= $dx;
7+
}
8+
$key = substr($salted, 0, 32);
9+
$iv = substr($salted, 32, 16);
10+
return [$key, $iv];
11+
//passes:AlignSuperEquals
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
// Test multiple control structures with different assignment operators
3+
$a = 1;
4+
$bb += 2;
5+
$ccc *= 3;
6+
7+
if ($condition) {
8+
$x = 'short';
9+
$longer_var .= 'concatenation';
10+
$y /= 10;
11+
}
12+
13+
for ($i = 0; $i < 10; $i++) {
14+
$counter = $i;
15+
$result >>= 1;
16+
}
17+
18+
$final = 'end';
19+
$another_final &= 'bitwise';
20+
//passes:AlignSuperEquals
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
// Test multiple control structures with different assignment operators
3+
$a = 1;
4+
$bb += 2;
5+
$ccc *= 3;
6+
7+
if ($condition) {
8+
$x = 'short';
9+
$longer_var .= 'concatenation';
10+
$y /= 10;
11+
}
12+
13+
for ($i = 0; $i < 10; $i++) {
14+
$counter = $i;
15+
$result >>= 1;
16+
}
17+
18+
$final = 'end';
19+
$another_final &= 'bitwise';
20+
//passes:AlignSuperEquals
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
// Test nested blocks and complex structures
3+
class TestClass {
4+
public function method() {
5+
$a = 1;
6+
$bb = 2;
7+
8+
switch ($value) {
9+
case 1:
10+
$x = 'one';
11+
$longer_name .= 'test';
12+
break;
13+
case 2:
14+
$y = 'two';
15+
$z *= 3;
16+
break;
17+
}
18+
19+
$result = 'final';
20+
$other_result += 10;
21+
}
22+
}
23+
24+
$global = 'outside';
25+
$another_global *= 5;
26+
//passes:AlignSuperEquals
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
// Test nested blocks and complex structures
3+
class TestClass {
4+
public function method() {
5+
$a = 1;
6+
$bb = 2;
7+
8+
switch ($value) {
9+
case 1:
10+
$x = 'one';
11+
$longer_name .= 'test';
12+
break;
13+
case 2:
14+
$y = 'two';
15+
$z *= 3;
16+
break;
17+
}
18+
19+
$result = 'final';
20+
$other_result += 10;
21+
}
22+
}
23+
24+
$global = 'outside';
25+
$another_global *= 5;
26+
//passes:AlignSuperEquals
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
// Test try-catch blocks and exception handling
3+
$start = 'begin';
4+
$config .= 'settings';
5+
6+
try {
7+
$connection = new PDO($dsn);
8+
$prepared_stmt <<= $query;
9+
$result_set = $prepared_stmt->execute();
10+
} catch (Exception $e) {
11+
$error = $e->getMessage();
12+
$log_entry .= $error;
13+
$retry_count += 1;
14+
} finally {
15+
$cleanup = true;
16+
$memory_freed *= 0;
17+
}
18+
19+
$end = 'finished';
20+
$summary .= 'completed';
21+
//passes:AlignSuperEquals
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
// Test try-catch blocks and exception handling
3+
$start = 'begin';
4+
$config .= 'settings';
5+
6+
try {
7+
$connection = new PDO($dsn);
8+
$prepared_stmt <<= $query;
9+
$result_set = $prepared_stmt->execute();
10+
} catch (Exception $e) {
11+
$error = $e->getMessage();
12+
$log_entry .= $error;
13+
$retry_count += 1;
14+
} finally {
15+
$cleanup = true;
16+
$memory_freed *= 0;
17+
}
18+
19+
$end = 'finished';
20+
$summary .= 'completed';
21+
//passes:AlignSuperEquals
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
// Test foreach and other loop structures
3+
$items = ['a', 'b', 'c'];
4+
$total_count = 0;
5+
6+
foreach ($items as $key => $value) {
7+
$processed = strtoupper($value);
8+
$key_length += strlen($key);
9+
$processed_items[] = $processed;
10+
}
11+
12+
while ($condition) {
13+
$iterator = next($array);
14+
$check_value .= $iterator;
15+
if ($break_condition) {
16+
break;
17+
}
18+
}
19+
20+
do {
21+
$attempt = try_operation();
22+
$attempts_made += 1;
23+
} while (!$attempt);
24+
25+
$final_result = 'done';
26+
$statistics .= 'complete';
27+
//passes:AlignSuperEquals

0 commit comments

Comments
 (0)