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

Expose hasPrimaryKey method in Table object #1979

Merged
merged 1 commit into from
Jun 2, 2021
Merged
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
13 changes: 13 additions & 0 deletions src/Phinx/Db/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ public function changePrimaryKey($columns)
return $this;
}

/**
* Checks to see if a primary key exists.
*
* @param string|string[] $columns Column(s)
* @param string|null $constraint Constraint names
*
* @return bool
*/
public function hasPrimaryKey($columns, $constraint = null)
Copy link
Member

Choose a reason for hiding this comment

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

You could add a type for the 2nd param it seems. Same for return value

Copy link
Member Author

Choose a reason for hiding this comment

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

I would not want to add type hinting to just one function in this file for fear of overall consistency. Perhaps on a release of 0.13, could do a quick release of 0.14 which just adds type hints where possible across the entire codebase, and then going forward type hints are always used?

Could also land such work in 0.13, but I'd almost at this point just say I'll get back to and land #1962 and then release instead of having it drag out too much longer.

Copy link
Member

Choose a reason for hiding this comment

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

Consistency sure is a point.
But this is a new public API method that is added.
And I think the benefits of types in place weigh higher than the consistency argument (from user perspective anyway).
I agree that any 0.13 semantic major release would need to clean up all possible types.

{
return $this->getAdapter()->hasPrimaryKey($this->getName(), $columns, $constraint);
}

/**
* Changes the comment of the database table.
*
Expand Down