-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from Fabccc/main
feature: support null coalescing expression and array assignment
- Loading branch information
Showing
11 changed files
with
326 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class IncrementArrayInMethod { | ||
|
||
private array $counter = []; | ||
|
||
private function __construct(private bool $debug = false) { | ||
} | ||
|
||
public function incrementCounter(): void { | ||
$this->counter[1]++; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/rules/examples/e12/read_array_null_coalescing_or_array.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class ReadArrayNullCoalescingOrArray | ||
{ | ||
private array $variablesSet1 = [ | ||
'var1' => 'test1', | ||
]; | ||
|
||
private array $variablesSet2 = [ | ||
'var2' => 'test2', | ||
]; | ||
|
||
public function getVariable(string $key): string | ||
{ | ||
return $this->variablesSet1[$key] ?? $this->variablesSet2[$key]; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/rules/examples/e12/read_array_null_coalescing_or_null.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class ReadArrayNullCoalescingOrNull | ||
{ | ||
private array $variables = [ | ||
'var1' => 'test1', | ||
'var2' => 'test2', | ||
]; | ||
|
||
public function getVariable(string $key): ?string | ||
{ | ||
return $this->variables[$key] ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class ReadArrayNullCoalescingOrThrow | ||
{ | ||
public function __construct(private ?string $guid = null) | ||
{ | ||
} | ||
|
||
public function getGuidNotNull(): string | ||
{ | ||
return $this->guid ?? throw new \RuntimeException('Missing guid'); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/rules/examples/e12/read_static_array_null_coalescing_or_array.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class ReadArrayNullCoalescingOrArray | ||
{ | ||
private array $variablesSet1 = [ | ||
'var1' => 'test1', | ||
]; | ||
|
||
private array $variablesSet2 = [ | ||
'var2' => 'test2', | ||
]; | ||
|
||
public static function getVariable(string $key): string | ||
{ | ||
return self::$variablesSet1[$key] ?? self::$variablesSet2[$key]; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/rules/examples/e12/read_static_array_null_coalescing_or_null.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class ReadStaticArrayNullCoalescingOrNull | ||
{ | ||
private array $variables = [ | ||
'var1' => 'test1', | ||
'var2' => 'test2', | ||
]; | ||
|
||
public static function getVariable(string $key): ?string | ||
{ | ||
return self::$variables[$key] ?? null; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/rules/examples/e12/read_static_null_coalescing_or_throw.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class ReadArrayNullCoalescingOrThrow | ||
{ | ||
private static ?string $guid = null; | ||
|
||
public function __construct() | ||
{ | ||
} | ||
|
||
public static function getGuidNotNull(): string | ||
{ | ||
return self::$guid ?? throw new \RuntimeException('Missing static guid'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class SetArrayInMethod { | ||
|
||
private array $counter = []; | ||
|
||
public function setCounter(int $key, int $val): void { | ||
$this->counter[$key] = $val; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class SetArrayInNullCoalescing { | ||
|
||
private array $counter = []; | ||
|
||
public function process(int $key, int $val): int { | ||
return $this->counter[$key] ?? $this->counter[$key] = $val; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Service\e12; | ||
|
||
class SetInNullCoalescing { | ||
|
||
private int $counter; | ||
|
||
public function process(int $value): int { | ||
return $this->counter ?? $this->counter = $value; | ||
} | ||
} |