Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backfill Parameters #3938

Merged
merged 1 commit into from
Nov 28, 2020
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
7 changes: 6 additions & 1 deletion system/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ class Database
* @return mixed
* @internal param bool $useBuilder
*/
public function load(array $params = [], string $alias)
public function load(array $params = [], string $alias = '')
{
if (empty($alias))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (empty($alias))
if ($alias === '')

{
throw new InvalidArgumentException('You must supply the parameter: alias.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new InvalidArgumentException('You must supply the parameter: alias.');
throw new InvalidArgumentException('You must supply the parameter: alias.'); // @codeCoverageIgnore

}

// Handle universal DSN connection string
if (! empty($params['DSN']) && strpos($params['DSN'], '://') !== false)
{
Expand Down
8 changes: 7 additions & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\HTTP\Files\UploadedFile;
use Config\App;
use Config\Services;
use InvalidArgumentException;
use Locale;

/**
Expand Down Expand Up @@ -128,8 +129,13 @@ class IncomingRequest extends Request
* @param string|null $body
* @param UserAgent $userAgent
*/
public function __construct($config, URI $uri = null, $body = 'php://input', UserAgent $userAgent)
public function __construct($config, URI $uri = null, $body = 'php://input', UserAgent $userAgent = null)
{
if (empty($uri) || empty($userAgent))
{
throw new InvalidArgumentException('You must supply the parameters: uri, userAgent.');
}
Comment on lines +134 to +137
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (empty($uri) || empty($userAgent))
{
throw new InvalidArgumentException('You must supply the parameters: uri, userAgent.');
}
if ($uri === null || $userAgent === null)
{
throw new InvalidArgumentException('You must supply the parameters: uri, userAgent.'); // @codeCoverageIgnore
}


// Get our body from php://input
if ($body === 'php://input')
{
Expand Down
8 changes: 7 additions & 1 deletion system/Images/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use CodeIgniter\Images\Image;
use CodeIgniter\Images\ImageHandlerInterface;
use Config\Images;
use InvalidArgumentException;

/**
* Base image handling implementation
Expand Down Expand Up @@ -662,8 +663,13 @@ public function fit(int $width, int $height = null, string $position = 'center')
*
* @return array
*/
protected function calcAspectRatio($width, $height = null, $origWidth, $origHeight): array
protected function calcAspectRatio($width, $height = null, $origWidth = 0, $origHeight = 0): array
{
if (empty($origWidth) || empty($origHeight))
{
throw new InvalidArgumentException('You must supply the parameters: origWidth, origHeight.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new InvalidArgumentException('You must supply the parameters: origWidth, origHeight.');
throw new InvalidArgumentException('You must supply the parameters: origWidth, origHeight.'); // @codeCoverageIgnore

}

// If $height is null, then we have it easy.
// Calc based on full image size and be done.
if (is_null($height))
Expand Down
2 changes: 1 addition & 1 deletion system/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public function determineFile(): array
];

// Generate Backtrace info
$trace = \debug_backtrace(false);
$trace = \debug_backtrace(0);

// So we search from the bottom (earliest) of the stack frames
$stackFrames = \array_reverse($trace);
Expand Down
8 changes: 7 additions & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CodeIgniter\Router\Exceptions\RouterException;
use Config\Modules;
use Config\Services;
use InvalidArgumentException;

/**
* Class RouteCollection
Expand Down Expand Up @@ -988,8 +989,13 @@ public function presenter(string $name, array $options = null): RouteCollectionI
*
* @return RouteCollectionInterface
*/
public function match(array $verbs = [], string $from, $to, array $options = null): RouteCollectionInterface
public function match(array $verbs = [], string $from = '', $to = '', array $options = null): RouteCollectionInterface
{
if (empty($from) || empty($to))
{
throw new InvalidArgumentException('You must supply the parameters: from, to.');
}

foreach ($verbs as $verb)
{
$verb = strtolower($verb);
Expand Down
19 changes: 15 additions & 4 deletions system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CodeIgniter\Validation;

use Config\Database;
use InvalidArgumentException;

/**
* Validation Rules.
Expand Down Expand Up @@ -352,13 +353,18 @@ public function required($str = null): bool
* required_with[password]
*
* @param string|null $str
* @param string $fields List of fields that we should check if present
* @param string|null $fields List of fields that we should check if present
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param string|null $fields List of fields that we should check if present
* @param string $fields List of fields that we should check if present

* @param array $data Complete list of fields from the form
*
* @return boolean
*/
public function required_with($str = null, string $fields, array $data): bool
public function required_with($str = null, string $fields = null, array $data = []): bool
{
if (is_null($fields) || empty($data))
{
throw new InvalidArgumentException('You must supply the parameters: fields, data.');
}
Comment on lines +361 to +366
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function required_with($str = null, string $fields = null, array $data = []): bool
{
if (is_null($fields) || empty($data))
{
throw new InvalidArgumentException('You must supply the parameters: fields, data.');
}
public function required_with($str = null, string $fields = '', array $data = []): bool
{
if ($fields === '' || $data === [])
{
throw new InvalidArgumentException('You must supply the parameters: fields, data.'); // @codeCoverageIgnore
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as below, $fields is allowed to be an empty string so we need to add the null option. This could probably be addressed on calling classes but it is also possible that someone is calling this directly (though I really hope not).


$fields = explode(',', $fields);

// If the field is present we can safely assume that
Expand Down Expand Up @@ -404,13 +410,18 @@ public function required_with($str = null, string $fields, array $data): bool
* required_without[id,email]
*
* @param string|null $str
* @param string $fields
* @param string|null $fields
* @param array $data
*
* @return boolean
*/
public function required_without($str = null, string $fields, array $data): bool
public function required_without($str = null, string $fields = null, array $data = []): bool
{
if (is_null($fields) || empty($data))
{
throw new InvalidArgumentException('You must supply the parameters: fields, data.');
}

Comment on lines +413 to +424
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment with required_with

$fields = explode(',', $fields);

// If the field is present we can safely assume that
Expand Down
7 changes: 6 additions & 1 deletion system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ public function check($value, string $rule, array $errors = []): bool
*
* @return boolean
*/
protected function processRules(string $field, string $label = null, $value, $rules = null, array $data): bool
protected function processRules(string $field, string $label = null, $value, $rules = null, array $data = null): bool
{
if (is_null($data))
{
throw new InvalidArgumentException('You must supply the parameter: data.');
}

Comment on lines +209 to +215
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function processRules(string $field, string $label = null, $value, $rules = null, array $data = null): bool
{
if (is_null($data))
{
throw new InvalidArgumentException('You must supply the parameter: data.');
}
protected function processRules(string $field, string $label = null, $value, $rules = null, array $data = []): bool
{
if ($data === [])
{
throw new InvalidArgumentException('You must supply the parameter: data.'); // @codeCoverageIgnore
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has to add null as an input option because [] is actually valid input and we're trying to catch cases where the parameter was not supplied at all.

// If the if_exist rule is defined...
if (in_array('if_exist', $rules, true))
{
Expand Down