-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #31194 [PropertyAccess] Improve errors when trying to find a …
…writable property (pierredup) This PR was submitted for the master branch but it was merged into the 4.4 branch instead (closes #31194). Discussion ---------- [PropertyAccess] Improve errors when trying to find a writable property | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17907 | License | MIT | Doc PR | N/A When setting a property using an adder/remove, the error message is very generic if the methods don't fit the exact requirements (both the adder and remover need to be defined and accept at least one argument). This can be confusing when you already have the methods `addFoo()` and `removeFoo()` defined (but without any parameters in the signature), but the error message states that the method doesn't exist or don't have public access. So this PR tries to improve the error message if a property isn't writable by doing the following: * If only one of the add/remove methods is implemented, indicate that the other method is needed as well. * If any of the adder/remover, setter or magic methods (`__call` or `__set`) don't have the required number of parameters, make it clear that the methods need to define the correct number of parameter. * The any of the access methods were found, but don't have public access, make it clear that the method needs to be defined as public, ```php class Foo { public function addBar($value) { } public function removeBar() { } } ``` **Before:** ``` Neither the property "bar" nor one of the methods "addBar()/removeBar()", "setBar()", "bar()", "__set()" or "__call()" exist and have public access in class "Foo". ``` **After:** ``` The method "removeBar" requires at least "1" parameters, "0" found. ``` Commits ------- f90a9fd Improve errors when trying to find a writable property
- Loading branch information
Showing
6 changed files
with
194 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...Symfony/Component/PropertyAccess/Tests/Fixtures/TestAdderRemoverInvalidArgumentLength.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\PropertyAccess\Tests\Fixtures; | ||
|
||
class TestAdderRemoverInvalidArgumentLength | ||
{ | ||
public function addFoo() | ||
{ | ||
} | ||
|
||
public function removeFoo($var1, $var2) | ||
{ | ||
} | ||
|
||
public function setBar($var1, $var2) | ||
{ | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestAdderRemoverInvalidMethods.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\PropertyAccess\Tests\Fixtures; | ||
|
||
class TestAdderRemoverInvalidMethods | ||
{ | ||
public function addFoo($foo) | ||
{ | ||
} | ||
|
||
public function removeBar($foo) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,8 @@ public function __construct($value) | |
{ | ||
$this->value = $value; | ||
} | ||
|
||
private function setFoo() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters