Skip to content

[PropertyAccess] Added isReadable() and isWritable() #10570

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

Merged
merged 6 commits into from
Mar 31, 2014

Conversation

webmozart
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets #8659
License MIT
Doc PR symfony/symfony-docs#3729

This PR introduces BC breaks that are described in detail in the UPGRADE file. The BC breaks conform to our policy. They shouldn't affect many people, so I think we can safely do them.

PropertyAccess
--------------

* The methods `isReadable()` and `isWritable()` were added to
Copy link
Member

Choose a reason for hiding this comment

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

missing [BC Break] prefix

Copy link
Member

Choose a reason for hiding this comment

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

hmm, sorry, no. This file documents only BC breaks, so not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We never have this prefix in the UPGRADE file.

@webmozart
Copy link
Contributor Author

TODO before merging this, I'll see whether the $value argument can be removed from isWritable() for forward compatibility.

if (is_string($propertyPath)) {
$propertyPath = new PropertyPath($propertyPath);
} elseif (!$propertyPath instanceof PropertyPathInterface) {
throw new UnexpectedTypeException($propertyPath, 'string or Symfony\Component\PropertyAccess\PropertyPathInterface');
Copy link
Contributor

Choose a reason for hiding this comment

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

Imho UnexpectedTypeException is not semantically correct because its defined as RuntimeException but here it is clearly a LogicException. UnexpectedTypeException is correctly used for checks whether value in path is array or object. But we should destringuish these two cases.
So for this case here, we should instead throw a InvalidPropertyPathException and it should extend LogicException instead.
Currently all methods in AccessorInterface are missing phpdoc for InvalidPropertyPathException anyway which can be raised by new PropertyPath($propertyPath).

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently isReadable and isWriteable phpdoc are missing UnexpectedTypeException and InvalidPropertyPathException. With my suggestion above, only InvalidPropertyPathException could be raised.

To keep isWritable() and setValue() consistent, the exception thrown when only
an adder was present, but no remover (or vice versa), was removed.
@webmozart
Copy link
Contributor Author

I removed the $value argument now. An InvalidArgumentException is thrown when an invalid property path is given.

@Tobion
Copy link
Contributor

Tobion commented Mar 30, 2014

InvalidPropertyPathException should extend InvalidArgumentException (which is a tiny bc break). But otherwise we would need to add InvalidPropertyPathException too all phpdoc because InvalidPropertyPathException would not be convered since it extends a RuntimeException.

* @throws Exception\UnexpectedTypeException If a value within the path is neither object
* nor array
* @throws Exception\InvalidArgumentException If the property path is invalid
* @throws Exception\NoSuchPropertyException If a property does not exist or is not public.
Copy link
Contributor

Choose a reason for hiding this comment

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

phpdocs of these methods are missing NoSuchIndexException. I would simply document the parent class of both: AccessException

@webmozart
Copy link
Contributor Author

But otherwise we would need to add InvalidPropertyPathException too all phpdoc because InvalidPropertyPathException would not be convered since it extends a RuntimeException.

Since strings can be constructed at runtime, it is indeed a RuntimeException. As such, I think it's fine not to document it.

This should be ready to merge now.

@Tobion
Copy link
Contributor

Tobion commented Mar 31, 2014

Huh, why not document it?
Everything could be constructed at runtime. The point is, that property path have a well-defined grammar, and errors could theoretically be detected at compile time. This is why I would say it's a logic exception.

@webmozart
Copy link
Contributor Author

You're right, but

errors could theoretically be detected at compile time

is not true:

new PropertyPath('path.'.$someDynamicValue);

The caller can't enforce that a property path (string) is correct (except by passing a PropertyPath instance), so this case is different than, for example, type errors, that can be prevented by using type checks or casting.

@Tobion
Copy link
Contributor

Tobion commented Mar 31, 2014

One can see it both ways. But it still needs to be documented.

fabpot added a commit that referenced this pull request Mar 31, 2014
…webmozart)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[PropertyAccess] Added isReadable() and isWritable()

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8659
| License       | MIT
| Doc PR        | symfony/symfony-docs#3729

This PR introduces BC breaks that are described in detail in the UPGRADE file. The BC breaks conform to our policy. They shouldn't affect many people, so I think we can safely do them.

Commits
-------

f7fb855 [PropertyAccess] Added missing exceptions to phpdoc
9aee2ad [PropertyAccess] Removed the argument $value from isWritable()
4262707 [PropertyAccess] Fixed CS and added missing documentation
6d2af21 [PropertyAccess] Added isReadable() and isWritable()
20e6bf8 [PropertyAccess] Refactored PropertyAccessorCollectionTest
0488389 [PropertyAccess] Refactored PropertyAccessorTest
@fabpot fabpot merged commit f7fb855 into symfony:master Mar 31, 2014
*/
private function findAdderAndRemover(\ReflectionClass $reflClass, array $singulars)
{
$exception = null;
Copy link
Member

Choose a reason for hiding this comment

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

this looks like a dead assignment

@webmozart webmozart deleted the issue8659 branch April 2, 2014 13:51
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Apr 12, 2014
…dable() and isWritable() methods (webmozart)

This PR was merged into the master branch.

Discussion
----------

Added documentation for the new PropertyAccessor::isReadable() and isWritable() methods

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#10570)
| Applies to    | 2.5+
| Fixed tickets | -

Commits
-------

bb8e3ed Added documentation for the new PropertyAccessor::isReadable() and isWritable() methods
weaverryan added a commit to symfony/symfony-docs that referenced this pull request May 6, 2014
This PR was merged into the master branch.

Discussion
----------

Property access tweaks

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.5+
| Fixed tickets | #3729

Hi guys!

This follows after #3729 - it includes several small suggestions made by @wouterj and @xabbuh.

Additionally, this removes the 3rd argument to `isWritable`, which was removed in the orignal PR (symfony/symfony#10570) and didn't make it into the final feature.

Thanks!

Commits
-------

fb9fe99 [#3729] Removing 3rd argument to isWritable - this doesn't exist in the final merged item
319bf29 [#3729] Making minor changes thansk to @wouterj and @xabbuh.
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.

4 participants