Skip to content

Corrected fieldValidation annotation#380

Merged
markstory merged 1 commit intocakephp:masterfrom
dmromanov:feature/fix-annotations
Nov 23, 2017
Merged

Corrected fieldValidation annotation#380
markstory merged 1 commit intocakephp:masterfrom
dmromanov:feature/fix-annotations

Conversation

@dmromanov
Copy link
Copy Markdown
Contributor

No description provided.

* @param string $fieldName Name of field to be validated.
* @param array $metaData metadata for field
* @param string $primaryKey The primary key field
* @param array $primaryKey The primary key field
Copy link
Copy Markdown
Member

@dereuromark dereuromark Nov 23, 2017

Choose a reason for hiding this comment

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

Can't primary key also be a string?
Maybe we should do string|array and cast inside the in_array() call?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see the cast is happening before calling this method: $primaryKey = (array)$schema->primaryKey();
Then you can just add the array typehint in the signature IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@dmromanov dmromanov force-pushed the feature/fix-annotations branch from 434f2e5 to a62abd4 Compare November 23, 2017 14:15
@codecov-io
Copy link
Copy Markdown

codecov-io commented Nov 23, 2017

Codecov Report

Merging #380 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #380   +/-   ##
=========================================
  Coverage     92.12%   92.12%           
  Complexity      664      664           
=========================================
  Files            25       25           
  Lines          2184     2184           
=========================================
  Hits           2012     2012           
  Misses          172      172
Impacted Files Coverage Δ Complexity Δ
src/Shell/Task/ModelTask.php 94.96% <100%> (ø) 154 <22> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c3c512...a62abd4. Read the comment docs.

@markstory markstory added this to the 1.5.x milestone Nov 23, 2017
@markstory markstory self-assigned this Nov 23, 2017
@markstory markstory merged commit 076639a into cakephp:master Nov 23, 2017
* @return array Array of validation for the field.
*/
public function fieldValidation($schema, $fieldName, array $metaData, $primaryKey)
public function fieldValidation($schema, $fieldName, array $metaData, array $primaryKey)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is a backwards compatible change. Type hint change for $primaryKey var will cause error if method is overridden in an extending class with old signature.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In this case this is probably fair enough as it was always internally expected to be an array (or crash).
See code. This just puts the error more clearly to the beginning of the method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even if one is correctly passing an array he would still get an error due to method signature mismatch in child class, which shouldn't happen.

@ADmad ADmad mentioned this pull request Nov 24, 2017
@dmromanov dmromanov deleted the feature/fix-annotations branch August 19, 2018 22:35
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.

5 participants