Skip to content

Avoid having optional parameters before required in method signatures #213

Closed
@aik099

Description

@aik099

Currently, I'm getting a bunch of deprecations about methods having optional parameters declared before required ones ( see https://github.com/console-helpers/jira-api-restclient/actions/runs/12379854881/job/34554938237 ).

Related to ClientInterface itself and classes implementing it

  1. PHP Deprecated: Optional parameter $data declared before required parameter $credential is implicitly treated as a required parameter in .../src/Jira/Api/Client/ClientInterface.php on line 53
// ClientInterface interface
public function sendRequest(
		$method,
		$url,
		$data = array(),
		$endpoint,
		AuthenticationInterface $credential,
		$is_file = false,
		$debug = false
	);
  1. PHP Deprecated: Optional parameter $data declared before required parameter $credential is implicitly treated as a required parameter in .../src/Jira/Api/Client/CurlClient.php on line 62
// CurlClient class
public function sendRequest(
		$method,
		$url,
		$data = array(),
		$endpoint,
		AuthenticationInterface $credential,
		$is_file = false,
		$debug = false
	) {
  1. PHP Deprecated: Optional parameter $data declared before required parameter $credential is implicitly treated as a required parameter in .../src/Jira/Api/Client/PHPClient.php on line 95
// PHPClient class
	public function sendRequest(
		$method,
		$url,
		$data = array(),
		$endpoint,
		AuthenticationInterface $credential,
		$is_file = false,
		$debug = false
	) {

Related to the Api class

  1. PHP Deprecated: Optional parameter $method declared before required parameter $url is implicitly treated as a required parameter in .../src/Jira/Api.php on line 711
// Api class
public function api(
		$method = self::REQUEST_GET,
		$url,
		$data = array(),
		$return_as_array = false,
		$is_file = false,
		$debug = false
	) {

The @royarisse suggested some interesting ideas (see #205) about fixing:

  1. remove the default value for the ClientInterface::sendRequest method's $data parameter
  2. remove the default value for the Api::api method's $method parameter

I completely agree with 1st item (interface change) and I dare to remove default values from all parameters in the ClientInterface::sendRequest method signature, because:

  1. when the Api class calls the class implementing the ClientInterface interface it will provide all parameters in each call
  2. we're breaking BC anyway with the 2.0.0 release

I also agree with 2nd item, because the current library users (who use the master branch) are forced to specify the request method anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions