mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
[Rector] Apply Rector: SimplifyIfElseToTernaryRector
This commit is contained in:
parent
9c6746bf54
commit
46cabd4efd
@ -5,6 +5,7 @@ use Rector\CodeQuality\Rector\For_\ForToForeachRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
|
||||
use Rector\CodeQuality\Rector\If_\CombineIfRector;
|
||||
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
|
||||
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
|
||||
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
|
||||
use Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector;
|
||||
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
|
||||
@ -48,7 +49,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
|
||||
$parameters->set(Option::ENABLE_CACHE, true);
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
|
||||
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan.neon.dist');
|
||||
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan.neon.dist');
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(UnderscoreToCamelCaseVariableNameRector::class);
|
||||
@ -68,4 +69,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services->set(PreparedValueToEarlyReturnRector::class);
|
||||
$services->set(ShortenElseIfRector::class);
|
||||
$services->set(RemoveUnusedForeachKeyRector::class);
|
||||
$services->set(SimplifyIfElseToTernaryRector::class);
|
||||
};
|
||||
|
@ -476,14 +476,7 @@ if (! function_exists('esc'))
|
||||
throw new InvalidArgumentException('Invalid escape context provided.');
|
||||
}
|
||||
|
||||
if ($context === 'attr')
|
||||
{
|
||||
$method = 'escapeHtmlAttr';
|
||||
}
|
||||
else
|
||||
{
|
||||
$method = 'escape' . ucfirst($context);
|
||||
}
|
||||
$method = $context === 'attr' ? 'escapeHtmlAttr' : 'escape' . ucfirst($context);
|
||||
|
||||
static $escaper;
|
||||
if (! $escaper)
|
||||
|
@ -254,16 +254,11 @@ class Factories
|
||||
return self::$options[$component];
|
||||
}
|
||||
|
||||
// Handle Config as a special case to prevent logic loops
|
||||
if ($component === 'config')
|
||||
{
|
||||
$values = self::$configOptions;
|
||||
}
|
||||
// Load values from the best Factory configuration (will include Registrars)
|
||||
else
|
||||
{
|
||||
$values = config('Factory')->$component ?? [];
|
||||
}
|
||||
$values = $component === 'config'
|
||||
// Handle Config as a special case to prevent logic loops
|
||||
? self::$configOptions
|
||||
// Load values from the best Factory configuration (will include Registrars)
|
||||
: config('Factory')->$component ?? [];
|
||||
|
||||
return self::setOptions($component, $values);
|
||||
}
|
||||
|
@ -545,14 +545,7 @@ class Connection extends BaseConnection
|
||||
}
|
||||
elseif ($index['Non_unique'])
|
||||
{
|
||||
if ($index['Index_type'] === 'SPATIAL')
|
||||
{
|
||||
$type = 'SPATIAL';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = 'INDEX';
|
||||
}
|
||||
$type = $index['Index_type'] === 'SPATIAL' ? 'SPATIAL' : 'INDEX';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -352,14 +352,7 @@ class Query implements QueryInterface
|
||||
// We'll need marker length later
|
||||
$ml = strlen($this->bindMarker);
|
||||
|
||||
if ($hasNamedBinds)
|
||||
{
|
||||
$sql = $this->matchNamedBinds($sql, $binds);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = $this->matchSimpleBinds($sql, $binds, $bindCount, $ml);
|
||||
}
|
||||
$sql = $hasNamedBinds ? $this->matchNamedBinds($sql, $binds) : $this->matchSimpleBinds($sql, $binds, $bindCount, $ml);
|
||||
|
||||
$this->finalQueryString = $sql;
|
||||
}
|
||||
|
@ -606,15 +606,8 @@ class Builder extends BaseBuilder
|
||||
if (empty($this->QBSelect) && ! empty($this->QBGroupBy) && is_array($this->QBGroupBy))
|
||||
{
|
||||
foreach ($this->QBGroupBy as $field)
|
||||
{
|
||||
if (is_array($field))
|
||||
{
|
||||
$this->QBSelect[] = $field['field'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->QBSelect[] = $field;
|
||||
}
|
||||
{
|
||||
$this->QBSelect[] = is_array($field) ? $field['field'] : $field;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,15 +301,10 @@ class Table
|
||||
|
||||
foreach ($this->fields as $name => $details)
|
||||
{
|
||||
// Are we modifying the column?
|
||||
if (isset($details['new_name']))
|
||||
{
|
||||
$newFields[] = $details['new_name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$newFields[] = $name;
|
||||
}
|
||||
$newFields[] = isset($details['new_name'])
|
||||
// Are we modifying the column?
|
||||
? $details['new_name']
|
||||
: $name;
|
||||
|
||||
$exFields[] = $name;
|
||||
}
|
||||
|
@ -1947,14 +1947,7 @@ class Email
|
||||
// so this needs to be assigned to a variable
|
||||
$from = $this->cleanEmail($this->headers['From']);
|
||||
|
||||
if ($this->validateEmailForShell($from))
|
||||
{
|
||||
$from = '-f ' . $from;
|
||||
}
|
||||
else
|
||||
{
|
||||
$from = '';
|
||||
}
|
||||
$from = $this->validateEmailForShell($from) ? '-f ' . $from : '';
|
||||
|
||||
// is popen() enabled?
|
||||
if (! function_usable('popen') || false === ($fp = @popen($this->mailPath . ' -oi ' . $from . ' -t', 'w')))
|
||||
|
@ -47,14 +47,7 @@ class OpenSSLHandler extends BaseHandler
|
||||
// Allow key override
|
||||
if ($params)
|
||||
{
|
||||
if (is_array($params) && isset($params['key']))
|
||||
{
|
||||
$this->key = $params['key'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->key = $params;
|
||||
}
|
||||
$this->key = is_array($params) && isset($params['key']) ? $params['key'] : $params;
|
||||
}
|
||||
|
||||
if (empty($this->key))
|
||||
@ -90,14 +83,7 @@ class OpenSSLHandler extends BaseHandler
|
||||
// Allow key override
|
||||
if ($params)
|
||||
{
|
||||
if (is_array($params) && isset($params['key']))
|
||||
{
|
||||
$this->key = $params['key'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->key = $params;
|
||||
}
|
||||
$this->key = is_array($params) && isset($params['key']) ? $params['key'] : $params;
|
||||
}
|
||||
|
||||
if (empty($this->key))
|
||||
|
@ -158,14 +158,7 @@ trait ResponseTrait
|
||||
|
||||
$this->statusCode = $code;
|
||||
|
||||
if (! empty($reason))
|
||||
{
|
||||
$this->reason = $reason;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->reason = static::$statusCodes[$code];
|
||||
}
|
||||
$this->reason = ! empty($reason) ? $reason : static::$statusCodes[$code];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -556,14 +556,7 @@ if (! function_exists('source'))
|
||||
{
|
||||
if (! _has_protocol($src))
|
||||
{
|
||||
if ($indexPage === true)
|
||||
{
|
||||
$src = site_url($src);
|
||||
}
|
||||
else
|
||||
{
|
||||
$src = slash_item('baseURL') . $src;
|
||||
}
|
||||
$src = $indexPage === true ? site_url($src) : slash_item('baseURL') . $src;
|
||||
}
|
||||
|
||||
$source = '<source src="' . $src
|
||||
@ -628,14 +621,7 @@ if (! function_exists('object'))
|
||||
{
|
||||
if (! _has_protocol($data))
|
||||
{
|
||||
if ($indexPage === true)
|
||||
{
|
||||
$data = site_url($data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = slash_item('baseURL') . $data;
|
||||
}
|
||||
$data = $indexPage === true ? site_url($data) : slash_item('baseURL') . $data;
|
||||
}
|
||||
|
||||
$object = '<object data="' . $data . '" '
|
||||
@ -701,14 +687,7 @@ if (! function_exists('embed'))
|
||||
{
|
||||
if (! _has_protocol($src))
|
||||
{
|
||||
if ($indexPage === true)
|
||||
{
|
||||
$src = site_url($src);
|
||||
}
|
||||
else
|
||||
{
|
||||
$src = slash_item('baseURL') . $src;
|
||||
}
|
||||
$src = $indexPage === true ? site_url($src) : slash_item('baseURL') . $src;
|
||||
}
|
||||
|
||||
return '<embed src="' . $src
|
||||
|
@ -99,7 +99,9 @@ class Model extends BaseModel
|
||||
{
|
||||
parent::__construct($validation);
|
||||
|
||||
/** @var BaseConnection $db */
|
||||
/**
|
||||
* @var BaseConnection $db
|
||||
*/
|
||||
$db = $db ?? Database::connect($this->DBGroup);
|
||||
|
||||
$this->db = &$db;
|
||||
@ -258,14 +260,7 @@ class Model extends BaseModel
|
||||
// If insertion succeeded then save the insert ID
|
||||
if ($result)
|
||||
{
|
||||
if (! $this->useAutoIncrement)
|
||||
{
|
||||
$this->insertID = $data[$this->primaryKey];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->insertID = $this->db->insertID();
|
||||
}
|
||||
$this->insertID = ! $this->useAutoIncrement ? $data[$this->primaryKey] : $this->db->insertID();
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -434,16 +434,11 @@ class Fabricator
|
||||
{
|
||||
$result = $this->model->fake($this->faker);
|
||||
|
||||
// This should cover entities
|
||||
if (is_object($result) && method_exists($result, 'toArray'))
|
||||
{
|
||||
$result = $result->toArray();
|
||||
}
|
||||
// Try to cast it
|
||||
else
|
||||
{
|
||||
$result = (array) $result;
|
||||
}
|
||||
$result = is_object($result) && method_exists($result, 'toArray')
|
||||
// This should cover entities
|
||||
? $result->toArray()
|
||||
// Try to cast it
|
||||
: (array) $result;
|
||||
}
|
||||
// Nothing left to do but give up
|
||||
else
|
||||
|
@ -55,14 +55,7 @@ trait ReflectionHelper
|
||||
*/
|
||||
private static function getAccessibleRefProperty($obj, $property)
|
||||
{
|
||||
if (is_object($obj))
|
||||
{
|
||||
$refClass = new ReflectionObject($obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
$refClass = new ReflectionClass($obj);
|
||||
}
|
||||
$refClass = is_object($obj) ? new ReflectionObject($obj) : new ReflectionClass($obj);
|
||||
|
||||
$refProperty = $refClass->getProperty($property);
|
||||
$refProperty->setAccessible(true);
|
||||
|
@ -37,14 +37,7 @@ final class CommonSingleServiceTest extends CIUnitTestCase
|
||||
$params = [];
|
||||
$method = new ReflectionMethod(Services::class, $service);
|
||||
|
||||
if ($method->getNumberOfParameters() === 1)
|
||||
{
|
||||
$params[] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$params[] = $method->getParameters()[0]->getDefaultValue();
|
||||
}
|
||||
$params[] = $method->getNumberOfParameters() === 1 ? true : $method->getParameters()[0]->getDefaultValue();
|
||||
|
||||
$service1 = single_service($service, ...$params);
|
||||
$service2 = single_service($service, ...$params);
|
||||
|
@ -1412,14 +1412,7 @@ class URLHelperTest extends CIUnitTestCase
|
||||
|
||||
public function urlToProvider()
|
||||
{
|
||||
if (config('App')->indexPage !== '')
|
||||
{
|
||||
$page = config('App')->indexPage . '/';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page = '';
|
||||
}
|
||||
$page = config('App')->indexPage !== '' ? config('App')->indexPage . '/' : '';
|
||||
|
||||
return [
|
||||
[
|
||||
|
Loading…
x
Reference in New Issue
Block a user