Skip to content

Commit

Permalink
Fix: sync the develop branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
kai890707 committed Aug 10, 2023
1 parent 27bdd84 commit 680b28b
Show file tree
Hide file tree
Showing 37 changed files with 430 additions and 312 deletions.
359 changes: 102 additions & 257 deletions phpstan-baseline.php

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,9 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
// properties representing the collection elements, we need to grab
// them as an array.
if (is_object($row) && ! $row instanceof stdClass) {
$row = $this->objectToArray($row, true, true);
// For updates the index field is needed even if it is not changed.
// So set $onlyChanged to false.
$row = $this->objectToArray($row, false, true);
}

// If it's still a stdClass, go ahead and convert to
Expand All @@ -997,6 +999,13 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
// Save updateIndex for later
$updateIndex = $row[$index] ?? null;

if ($updateIndex === null) {
throw new InvalidArgumentException(
'The index ("' . $index . '") for updateBatch() is missing in the data: '
. json_encode($row)
);
}

// Must be called first so we don't
// strip out updated_at values.
$row = $this->doProtectFields($row);
Expand Down
8 changes: 8 additions & 0 deletions system/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Controller
/**
* Constructor.
*
* @return void
*
* @throws HTTPException
*/
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
Expand All @@ -96,6 +98,8 @@ public function initController(RequestInterface $request, ResponseInterface $res
* considered secure for. Only with HSTS header.
* Default value is 1 year.
*
* @return void
*
* @throws HTTPException
*/
protected function forceHTTPS(int $duration = 31_536_000)
Expand All @@ -106,6 +110,8 @@ protected function forceHTTPS(int $duration = 31_536_000)
/**
* Provides a simple way to tie into the main CodeIgniter class and
* tell it how long to cache the current page for.
*
* @return void
*/
protected function cachePage(int $time)
{
Expand All @@ -118,6 +124,8 @@ protected function cachePage(int $time)
* @deprecated Use `helper` function instead of using this method.
*
* @codeCoverageIgnore
*
* @return void
*/
protected function loadHelpers()
{
Expand Down
2 changes: 1 addition & 1 deletion system/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Cookie implements ArrayAccess, CloneableCookieInterface
protected $value;

/**
* @var int
* @var int Unix timestamp
*/
protected $expires;

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar/Collectors/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct()
* The static method used during Events to collect
* data.
*
* @internal param $ array \CodeIgniter\Database\Query
* @internal
*/
public static function collect(Query $query)
{
Expand Down
2 changes: 2 additions & 0 deletions system/Encryption/Handlers/SodiumHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public function decrypt($data, $params = null)
*
* @param array|string|null $params
*
* @return void
*
* @throws EncryptionException If key is empty
*/
protected function parseParams($params)
Expand Down
10 changes: 10 additions & 0 deletions system/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ class Entity implements JsonSerializable
* $datamap = [
* 'class_property_name' => 'db_column_name'
* ];
*
* @var array<string, string>
*/
protected $datamap = [];

/**
* The date fields.
*
* @var array<int, string>
* @phpstan-var list<string>
*/
protected $dates = [
'created_at',
'updated_at',
Expand All @@ -57,6 +65,8 @@ class Entity implements JsonSerializable
/**
* Array of field names and the type of value to cast them as when
* they are accessed.
*
* @var array<string, string>
*/
protected $casts = [];

Expand Down
7 changes: 7 additions & 0 deletions system/Files/Exceptions/FileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class FileException extends RuntimeException implements ExceptionInterface
{
use DebugTraceableTrait;

/**
* @return static
*/
public static function forUnableToMove(?string $from = null, ?string $to = null, ?string $error = null)
{
return new static(lang('Files.cannotMove', [$from, $to, $error]));
Expand All @@ -28,6 +31,8 @@ public static function forUnableToMove(?string $from = null, ?string $to = null,
* Throws when an item is expected to be a directory but is not or is missing.
*
* @param string $caller The method causing the exception
*
* @return static
*/
public static function forExpectedDirectory(string $caller)
{
Expand All @@ -38,6 +43,8 @@ public static function forExpectedDirectory(string $caller)
* Throws when an item is expected to be a file but is not or is missing.
*
* @param string $caller The method causing the exception
*
* @return static
*/
public static function forExpectedFile(string $caller)
{
Expand Down
3 changes: 3 additions & 0 deletions system/Files/Exceptions/FileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class FileNotFoundException extends RuntimeException implements ExceptionInterfa
{
use DebugTraceableTrait;

/**
* @return static
*/
public static function forFileNotFound(string $path)
{
return new static(lang('Files.fileNotFound', [$path]));
Expand Down
8 changes: 4 additions & 4 deletions system/Format/Exceptions/FormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FormatException extends RuntimeException implements ExceptionInterface
/**
* Thrown when the instantiated class does not exist.
*
* @return FormatException
* @return static
*/
public static function forInvalidFormatter(string $class)
{
Expand All @@ -38,7 +38,7 @@ public static function forInvalidFormatter(string $class)
*
* @param string $error
*
* @return FormatException
* @return static
*/
public static function forInvalidJSON(?string $error = null)
{
Expand All @@ -49,7 +49,7 @@ public static function forInvalidJSON(?string $error = null)
* Thrown when the supplied MIME type has no
* defined Formatter class.
*
* @return FormatException
* @return static
*/
public static function forInvalidMime(string $mime)
{
Expand All @@ -60,7 +60,7 @@ public static function forInvalidMime(string $mime)
* Thrown on XMLFormatter when the `simplexml` extension
* is not installed.
*
* @return FormatException
* @return static
*
* @codeCoverageIgnore
*/
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function format($data)
* @see http://www.codexworld.com/convert-array-to-xml-in-php/
*
* @param SimpleXMLElement $output
*
* @return void
*/
protected function arrayToXML(array $data, &$output)
{
Expand Down
27 changes: 14 additions & 13 deletions system/Helpers/cookie_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
* the LICENSE file that was distributed with this source code.
*/

use CodeIgniter\Cookie\Cookie;
use Config\App;
use Config\Cookie;
use Config\Cookie as CookieConfig;
use Config\Services;

// =============================================================================
Expand All @@ -24,15 +25,15 @@
* Accepts seven parameters, or you can submit an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value The value of the cookie
* @param string $expire The number of seconds until expiration
* @param string $domain For site-wide cookie. Usually: .yourdomain.com
* @param string $path The cookie path
* @param string $prefix The cookie prefix ('': the default prefix)
* @param bool|null $secure True makes the cookie secure
* @param bool|null $httpOnly True makes the cookie accessible via http(s) only (no javascript)
* @param string|null $sameSite The cookie SameSite value
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value The value of the cookie
* @param string $expire The number of seconds until expiration
* @param string $domain For site-wide cookie. Usually: .yourdomain.com
* @param string $path The cookie path
* @param string $prefix The cookie prefix ('': the default prefix)
* @param bool|null $secure True makes the cookie secure
* @param bool|null $httpOnly True makes the cookie accessible via http(s) only (no javascript)
* @param string|null $sameSite The cookie SameSite value
*
* @return void
*
Expand Down Expand Up @@ -70,11 +71,11 @@ function set_cookie(
function get_cookie($index, bool $xssClean = false, ?string $prefix = '')
{
if ($prefix === '') {
/** @var Cookie|null $cookie */
$cookie = config(Cookie::class);
/** @var CookieConfig|null $cookie */
$cookie = config(CookieConfig::class);

// @TODO Remove Config\App fallback when deprecated `App` members are removed.
$prefix = $cookie instanceof Cookie ? $cookie->prefix : config(App::class)->cookiePrefix;
$prefix = $cookie instanceof CookieConfig ? $cookie->prefix : config(App::class)->cookiePrefix;
}

$request = Services::request();
Expand Down
20 changes: 20 additions & 0 deletions system/Honeypot/Exceptions/HoneypotException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,41 @@

class HoneypotException extends ConfigException implements ExceptionInterface
{
/**
* Thrown when the template value of config is empty.
*
* @return static
*/
public static function forNoTemplate()
{
return new static(lang('Honeypot.noTemplate'));
}

/**
* Thrown when the name value of config is empty.
*
* @return static
*/
public static function forNoNameField()
{
return new static(lang('Honeypot.noNameField'));
}

/**
* Thrown when the hidden value of config is false.
*
* @return static
*/
public static function forNoHiddenValue()
{
return new static(lang('Honeypot.noHiddenValue'));
}

/**
* Thrown when there are no data in the request of honeypot field.
*
* @return static
*/
public static function isBot()
{
return new static(lang('Honeypot.theClientIsABot'));
Expand Down
4 changes: 4 additions & 0 deletions system/Honeypot/Honeypot.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function __construct(HoneypotConfig $config)

/**
* Checks the request if honeypot field has data.
*
* @return bool
*/
public function hasContent(RequestInterface $request)
{
Expand All @@ -69,6 +71,8 @@ public function hasContent(RequestInterface $request)

/**
* Attaches Honeypot template to response.
*
* @return void
*/
public function attachHoneypot(ResponseInterface $response)
{
Expand Down
4 changes: 4 additions & 0 deletions system/I18n/TimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ public function toDateTime()
* @param DateTimeInterface|self|string|null $datetime
* @param DateTimeZone|string|null $timezone
*
* @return void
*
* @throws Exception
*/
public static function setTestNow($datetime = null, $timezone = null, ?string $locale = null)
Expand Down Expand Up @@ -845,6 +847,8 @@ public function subYears(int $years)
/**
* Returns the localized value of the date in the format 'Y-m-d H:i:s'
*
* @return false|string
*
* @throws Exception
*/
public function toDateTimeString()
Expand Down
6 changes: 6 additions & 0 deletions system/Log/Exceptions/LogException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@

class LogException extends FrameworkException
{
/**
* @return static
*/
public static function forInvalidLogLevel(string $level)
{
return new static(lang('Log.invalidLogLevel', [$level]));
}

/**
* @return static
*/
public static function forInvalidMessageType(string $messageType)
{
return new static(lang('Log.invalidMessageType', [$messageType]));
Expand Down
2 changes: 2 additions & 0 deletions system/Log/Handlers/ChromeLoggerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ protected function format($object)
* Attaches the header and the content to the passed in request object.
*
* @param ResponseInterface $response
*
* @return void
*/
public function sendLogs(?ResponseInterface &$response = null)
{
Expand Down
Loading

0 comments on commit 680b28b

Please sign in to comment.