Skip to content

Commit

Permalink
[Rector] Enable AddDefaultValueForUndefinedVariableRector
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 11, 2023
1 parent c58f45d commit a35714c
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 36 deletions.
24 changes: 0 additions & 24 deletions phpstan-baseline.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ parameters:
count: 1
path: system/Cache/Handlers/MemcachedHandler.php

-
message: "#^Variable \\$data might not be defined\\.$#"
count: 1
path: system/Cache/Handlers/MemcachedHandler.php

-
message: "#^Property CodeIgniter\\\\Cache\\\\Handlers\\\\RedisHandler\\:\\:\\$redis \\(Redis\\) in isset\\(\\) is not nullable\\.$#"
Expand Down Expand Up @@ -200,11 +196,6 @@ parameters:
count: 1
path: system/Helpers/number_helper.php

-
message: "#^Variable \\$count might not be defined\\.$#"
count: 1
path: system/Helpers/url_helper.php

-
message: "#^Property CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:\\$image \\(CodeIgniter\\\\Images\\\\Image\\) in empty\\(\\) is not falsy\\.$#"
count: 1
Expand All @@ -230,21 +221,6 @@ parameters:
count: 4
path: system/Images/Handlers/ImageMagickHandler.php

-
message: "#^Variable \\$gravity might not be defined\\.$#"
count: 1
path: system/Images/Handlers/ImageMagickHandler.php

-
message: "#^Variable \\$xAxis might not be defined\\.$#"
count: 1
path: system/Images/Handlers/ImageMagickHandler.php

-
message: "#^Variable \\$yAxis might not be defined\\.$#"
count: 1
path: system/Images/Handlers/ImageMagickHandler.php

-
message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getDefaultNamespace\\(\\)\\.$#"
count: 3
Expand Down
4 changes: 0 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
use Rector\Php70\Rector\FuncCall\RandomFunctionRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
Expand Down Expand Up @@ -106,9 +105,6 @@
// sometime too detail
CountOnNullRector::class,

// may not be unitialized on purpose
AddDefaultValueForUndefinedVariableRector::class,

// use mt_rand instead of random_int on purpose on non-cryptographically random
RandomFunctionRector::class,

Expand Down
3 changes: 2 additions & 1 deletion system/Cache/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public function initialize()
*/
public function get(string $key)
{
$key = static::validateKey($key, $this->prefix);
$data = [];
$key = static::validateKey($key, $this->prefix);

if ($this->memcached instanceof Memcached) {
$data = $this->memcached->get($key);
Expand Down
1 change: 1 addition & 0 deletions system/Commands/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function run(array $params)
*/
protected function prepare(string $class): string
{
$data = [];
$data['session'] = false;

if ($this->getOption('session')) {
Expand Down
1 change: 1 addition & 0 deletions system/Commands/Generators/SessionMigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function run(array $params)
*/
protected function prepare(string $class): string
{
$data = [];
$data['session'] = true;
$data['table'] = $this->getOption('t');
$data['DBGroup'] = $this->getOption('g');
Expand Down
1 change: 1 addition & 0 deletions system/Commands/Utilities/FilterCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class FilterCheck extends BaseCommand
*/
public function run(array $params)
{
$tbody = [];
if (! isset($params[0], $params[1])) {
CLI::error('You must specify a HTTP verb and a route.');
CLI::write(' Usage: ' . $this->usage);
Expand Down
1 change: 1 addition & 0 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ public function orHaving($key, $value = null, ?bool $escape = null)
*/
public function orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
{
$qbOrderBy = [];
if (empty($orderBy)) {
return $this;
}
Expand Down
1 change: 1 addition & 0 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ public function getPlatform(): string
*/
public function getVersion(): string
{
$info = [];
if (isset($this->dataCache['version'])) {
return $this->dataCache['version'];
}
Expand Down
1 change: 1 addition & 0 deletions system/Debug/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function __construct(ToolbarConfig $config)
*/
public function run(float $startTime, float $totalTime, RequestInterface $request, ResponseInterface $response): string
{
$data = [];
// Data items used within the view.
$data['url'] = current_url();
$data['method'] = strtoupper($request->getMethod());
Expand Down
1 change: 1 addition & 0 deletions system/Debug/Toolbar/Collectors/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ protected function formatTimelineData(): array
*/
public function display(): array
{
$data = [];
$data['queries'] = array_map(static function (array $query) {
$isDuplicate = $query['duplicate'] === true;

Expand Down
1 change: 1 addition & 0 deletions system/Helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ function link_tag(
bool $indexPage = false,
string $hreflang = ''
): string {
$attributes = [];
// extract fields if needed
if (is_array($href)) {
$rel = $href['rel'] ?? $rel;
Expand Down
11 changes: 5 additions & 6 deletions system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ function _get_uri(string $relativePath = '', ?App $config = null): URI
// Build the full URL based on $config and $relativePath
$request = Services::request();

if ($request instanceof CLIRequest) {
/** @var App $config */
$url = rtrim($config->baseURL, '/ ') . '/';
} else {
$url = $request->getUri()->getBaseURL();
}
/** @var App $config */
$url = $request instanceof CLIRequest
? rtrim($config->baseURL, '/ ') . '/'
: $request->getUri()->getBaseURL();

// Check for an index page
if ($config->indexPage !== '') {
Expand Down Expand Up @@ -329,6 +327,7 @@ function mailto(string $email, string $title = '', $attributes = ''): string
*/
function safe_mailto(string $email, string $title = '', $attributes = ''): string
{
$count = 0;
if (trim($title) === '') {
$title = $email;
}
Expand Down
5 changes: 4 additions & 1 deletion system/Images/Handlers/ImageMagickHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ protected function supportedFormatCheck()
*/
protected function _text(string $text, array $options = [])
{
$cmd = '';
$xAxis = 0;
$yAxis = 0;
$gravity = '';
$cmd = '';

// Reverse the vertical offset
// When the image is positioned at the bottom
Expand Down
1 change: 1 addition & 0 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ protected function doUpdateBatch(?array $set = null, ?string $index = null, int
*/
protected function doDelete($id = null, bool $purge = false)
{
$set = [];
$builder = $this->builder();

if ($id) {
Expand Down
2 changes: 2 additions & 0 deletions tests/system/Database/Live/MetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public function testListTablesConstrainedByPrefixReturnsOnlyTablesWithMatchingPr

public function testListTablesConstrainedByExtraneousPrefixReturnsOnlyTheExtraneousTable()
{
$oldPrefix = '';

try {
$this->createExtraneousTable();

Expand Down
1 change: 1 addition & 0 deletions tests/system/Validation/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public function testClosureRuleWithLabel(): void
*/
public function testCanValidatetArrayData($value, bool $expected): void
{
$data = [];
$this->validation->setRules(['arr' => 'is_array']);

$data['arr'] = $value;
Expand Down

0 comments on commit a35714c

Please sign in to comment.