mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge remote-tracking branch 'upstream/develop' into 4.6
This commit is contained in:
commit
c91b48e268
10
rector.php
10
rector.php
@ -18,7 +18,6 @@ use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
|
||||
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
|
||||
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector;
|
||||
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
|
||||
@ -36,7 +35,6 @@ use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
|
||||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
|
||||
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
|
||||
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
|
||||
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
|
||||
@ -107,11 +105,6 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
|
||||
YieldDataProviderRector::class,
|
||||
|
||||
RemoveUnusedPromotedPropertyRector::class => [
|
||||
// Bug in rector 1.0.0. See https://github.com/rectorphp/rector-src/pull/5573
|
||||
__DIR__ . '/tests/_support/Entity/CustomUser.php',
|
||||
],
|
||||
|
||||
RemoveUnusedPrivateMethodRector::class => [
|
||||
// private method called via getPrivateMethodInvoker
|
||||
__DIR__ . '/tests/system/Test/ReflectionHelperTest.php',
|
||||
@ -155,8 +148,6 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
// use mt_rand instead of random_int on purpose on non-cryptographically random
|
||||
RandomFunctionRector::class,
|
||||
|
||||
SimplifyRegexPatternRector::class,
|
||||
|
||||
// PHP 8.0 features but cause breaking changes
|
||||
ClassPropertyAssignToConstructorPromotionRector::class => [
|
||||
__DIR__ . '/system/Database/BaseResult.php',
|
||||
@ -221,7 +212,6 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
|
||||
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
|
||||
$rectorConfig->rule(RemoveErrorSuppressInTryCatchStmtsRector::class);
|
||||
$rectorConfig->rule(SimplifyRegexPatternRector::class);
|
||||
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
|
||||
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
|
||||
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
|
||||
|
@ -174,7 +174,7 @@ class Model extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the row of database from $this->table with a primary key
|
||||
* Fetches the row(s) of database from $this->table with a primary key
|
||||
* matching $id.
|
||||
* This method works only with dbCalls.
|
||||
*
|
||||
@ -198,8 +198,11 @@ class Model extends BaseModel
|
||||
$builder->where($this->table . '.' . $this->deletedField, null);
|
||||
}
|
||||
|
||||
$row = null;
|
||||
$rows = [];
|
||||
|
||||
if (is_array($id)) {
|
||||
$row = $builder->whereIn($this->table . '.' . $this->primaryKey, $id)
|
||||
$rows = $builder->whereIn($this->table . '.' . $this->primaryKey, $id)
|
||||
->get()
|
||||
->getResult($this->tempReturnType);
|
||||
} elseif ($singleton) {
|
||||
@ -207,16 +210,32 @@ class Model extends BaseModel
|
||||
->get()
|
||||
->getFirstRow($this->tempReturnType);
|
||||
} else {
|
||||
$row = $builder->get()->getResult($this->tempReturnType);
|
||||
$rows = $builder->get()->getResult($this->tempReturnType);
|
||||
}
|
||||
|
||||
if ($useCast && $row !== null) {
|
||||
$row = $this->convertToReturnType($row, $returnType);
|
||||
|
||||
if ($useCast) {
|
||||
$this->tempReturnType = $returnType;
|
||||
|
||||
if ($singleton) {
|
||||
if ($row === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->convertToReturnType($row, $returnType);
|
||||
}
|
||||
|
||||
foreach ($rows as $i => $row) {
|
||||
$rows[$i] = $this->convertToReturnType($row, $returnType);
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
return $row;
|
||||
if ($singleton) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,15 +249,7 @@ class Model extends BaseModel
|
||||
*/
|
||||
protected function doFindColumn(string $columnName)
|
||||
{
|
||||
$results = $this->select($columnName)->asArray()->find();
|
||||
|
||||
if ($this->useCasts()) {
|
||||
foreach ($results as $i => $row) {
|
||||
$results[$i] = $this->converter->fromDataSource($row);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
return $this->select($columnName)->asArray()->find();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,6 +100,28 @@ final class DataConverterModelTest extends LiveModelTestCase
|
||||
$this->assertInstanceOf(Time::class, $user->created_at);
|
||||
}
|
||||
|
||||
public function testFindArrayAsEntity(): void
|
||||
{
|
||||
$id = $this->prepareOneRecord();
|
||||
|
||||
$users = $this->model->asObject(User::class)->find([$id, 999]);
|
||||
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertIsInt($users[0]->id);
|
||||
$this->assertInstanceOf(Time::class, $users[0]->created_at);
|
||||
}
|
||||
|
||||
public function testFindNullAsEntity(): void
|
||||
{
|
||||
$this->prepareOneRecord();
|
||||
|
||||
$users = $this->model->asObject(User::class)->find();
|
||||
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertIsInt($users[0]->id);
|
||||
$this->assertInstanceOf(Time::class, $users[0]->created_at);
|
||||
}
|
||||
|
||||
public function testFindAllAsArray(): void
|
||||
{
|
||||
$this->prepareTwoRecords();
|
||||
|
@ -19,8 +19,8 @@ Using Exceptions
|
||||
|
||||
This section is a quick overview for newer programmers, or for developers who are not experienced with using exceptions.
|
||||
|
||||
What is Exceptions
|
||||
------------------
|
||||
What are Exceptions
|
||||
-------------------
|
||||
|
||||
Exceptions are simply events that happen when the exception is "thrown". This halts the current flow of the script, and
|
||||
execution is then sent to the error handler which displays the appropriate error page:
|
||||
|
@ -142,7 +142,7 @@ Creating Custom Collectors
|
||||
Creating custom collectors is a straightforward task. You create a new class, fully-namespaced so that the autoloader
|
||||
can locate it, that extends ``CodeIgniter\Debug\Toolbar\Collectors\BaseCollector``. This provides a number of methods
|
||||
that you can override, and has four required class properties that you must correctly set depending on how you want
|
||||
the Collector to work
|
||||
the Collector to work:
|
||||
|
||||
.. literalinclude:: debugging/004.php
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user