X Tutup
Skip to content

Refactor to not have required parameters following an optional parameter#40303

Merged
phil-davis merged 1 commit intomasterfrom
refactor-php-code-20220818
Aug 18, 2022
Merged

Refactor to not have required parameters following an optional parameter#40303
phil-davis merged 1 commit intomasterfrom
refactor-php-code-20220818

Conversation

@phil-davis
Copy link
Contributor

@phil-davis phil-davis commented Aug 18, 2022

Description

All required parameters should be listed first in PHP functions. Adjust the code to meet this rule.

I noticed this when running PHPstan in a different environment, and it told me about these existing invalid/not-useful parameter lists.

How Has This Been Tested?

CI

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:
  • Changelog item, see TEMPLATE

@phil-davis phil-davis self-assigned this Aug 18, 2022
@phil-davis phil-davis force-pushed the refactor-php-code-20220818 branch from 381de90 to 2284c7b Compare August 18, 2022 10:46
@phil-davis phil-davis changed the title Refactor PHP code reported by phpstan Refactor to not have required parameters following an optional parameter Aug 18, 2022
@owncloud owncloud deleted a comment from update-docs bot Aug 18, 2022
@owncloud owncloud deleted a comment from ownclouders Aug 18, 2022
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@owncloud owncloud deleted a comment from ownclouders Aug 18, 2022
@phil-davis phil-davis marked this pull request as ready for review August 18, 2022 11:36
* @return Result
*/
private function getSharedWithMe($node = null, $includeTags, $requestedShareTypes, $stateFilter = 0) {
private function getSharedWithMe($node, $includeTags, $requestedShareTypes, $stateFilter = 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only caller of this method calls it with $node specified. The default value is never used, so I removed it.

* @since 10.0.10
*/
public function __construct($message = "", $code, \Exception $previous = null) {
public function __construct($message = "", $code = 0, \Exception $previous = null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other exceptions that extend this, specify a default of 0 for $code so I did the same here.

@jvillafanez
Copy link
Member

Quoting the documentation:

Note that any optional arguments should be specified after any required arguments, otherwise they cannot be omitted from calls.

If I understand it correctly, those parameters aren't optional any longer and must be provided. That's why the "damage" is pretty limited, otherwise we get an error with the argument count.

@phil-davis phil-davis merged commit 1558148 into master Aug 18, 2022
@delete-merged-branch delete-merged-branch bot deleted the refactor-php-code-20220818 branch August 18, 2022 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup