Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Config/Mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,14 @@ public static function guessExtensionFromType(string $type, string $proposedExte

$proposedExtension = trim(strtolower($proposedExtension));

if ($proposedExtension !== '' && array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension]))
if ($proposedExtension !== '' && array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true))
{
return $proposedExtension;
}

foreach (static::$mimes as $ext => $types)
{
if ((is_string($types) && $types === $type) || (is_array($types) && in_array($type, $types)))
if ((is_string($types) && $types === $type) || (is_array($types) && in_array($type, $types, true)))
{
return $ext;
}
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ parameters:
- '#Return type \(bool\) of method CodeIgniter\\HTTP\\Files\\UploadedFile::move\(\) should be compatible with return type \(CodeIgniter\\Files\\File\) of method CodeIgniter\\Files\\File::move\(\)#'
- '#Return type \(bool\) of method CodeIgniter\\Test\\TestLogger::log\(\) should be compatible with return type \(null\) of method Psr\\Log\\LoggerInterface::log\(\)#'
- '#Unsafe usage of new static\(\)*#'
- '#Access to an undefined property CodeIgniter\\Config\\BaseConfig::\$key#'
parallel:
processTimeout: 300.0
scanDirectories:
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector;
use Rector\SOLID\Rector\If_\RemoveAlwaysElseRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;

return static function (ContainerConfigurator $containerConfigurator): void {
Expand Down Expand Up @@ -40,4 +41,5 @@
$services->set(UnderscoreToCamelCaseVariableNameRector::class);
$services->set(SimplifyUselessVariableRector::class);
$services->set(RemoveAlwaysElseRector::class);
$services->set(PassStrictParameterToFunctionParameterRector::class);
};
2 changes: 1 addition & 1 deletion system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ function helper($filenames)
}

// Check if this helper has already been loaded
if (in_array($filename, $loaded))
if (in_array($filename, $loaded, true))
{
continue;
}
Expand Down
1 change: 1 addition & 0 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public static function email($config = null, bool $getShared = true)
return static::getSharedInstance('email', $config);
}

// @phpstan-ignore-next-line
if (empty($config) || ! (is_array($config) || $config instanceof EmailConfig))
{
$config = config('Email');
Expand Down
4 changes: 2 additions & 2 deletions system/Database/Sqlsrv/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ protected function _processForeignKeys(string $table): string
. ' FOREIGN KEY (' . $this->db->escapeIdentifiers($field) . ') '
. ' REFERENCES ' . $this->db->escapeIdentifiers($this->db->getPrefix() . $fkey['table']) . ' (' . $this->db->escapeIdentifiers($fkey['field']) . ')';

if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions))
if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions, true))
{
$sql .= ' ON DELETE ' . $fkey['onDelete'];
}

if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions))
if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions, true))
{
$sql .= ' ON UPDATE ' . $fkey['onUpdate'];
}
Expand Down
2 changes: 1 addition & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ private function checkSubdomains($subdomains): bool

// Routes can be limited to any sub-domain. In that case, though,
// it does require a sub-domain to be present.
if (! empty($this->currentSubdomain) && in_array('*', $subdomains))
if (! empty($this->currentSubdomain) && in_array('*', $subdomains, true))
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected function processRules(string $field, string $label = null, $value, $ru
$rules = array_diff($rules, ['if_exist']);
}

if (in_array('permit_empty', $rules))
if (in_array('permit_empty', $rules, true))
{
if (! in_array('required', $rules, true) && (is_array($value) ? empty($value) : (trim($value) === '')))
{
Expand Down
1 change: 1 addition & 0 deletions system/View/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function makeColumns($array = [], $columnLimit = 0)
}
while (count($array) > 0);

// @phpstan-ignore-next-line
return $new;
}

Expand Down
80 changes: 80 additions & 0 deletions utils/Rector/PassStrictParameterToFunctionParameterRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace Utils\Rector;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;

/**
* Pass strict to function parameter on specific position argument when no value provided
*/
final class PassStrictParameterToFunctionParameterRector extends AbstractRector
{
private const FUNCTION_WITH_ARG_POSITION = [
// position start from 0
'in_array' => 2,
];
Comment thread
paulbalandan marked this conversation as resolved.

public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Pass strict to function parameter on specific position argument when no value provided', [
new CodeSample(
<<<'CODE_SAMPLE'
in_array('a', $array);
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
in_array('a', $array, true);
CODE_SAMPLE
),
]);
}

/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}

/**
* @param FuncCall $node
*/
public function refactor(Node $node): ?Node
{
$name = $node->name;
if (! method_exists($name, 'toString'))
{
return null;
}

$functions = array_keys(self::FUNCTION_WITH_ARG_POSITION);
$currentFunctionName = $name->toString();

if (! in_array($currentFunctionName, $functions, true))
{
return null;
}

$position = self::FUNCTION_WITH_ARG_POSITION[$currentFunctionName];

if (isset($node->args[$position]))
{
return null;
}

$name = new Name('true');
$node->args[$position] = new Arg(new ConstFetch($name));

return $node;
}
}