| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Yoast\WP\SEO\Surfaces; |
| 4 | 4 | |
| 5 | +use Yoast\WP\SEO\Exceptions\Forbidden_Property_Mutation_Exception; | |
| 5 | 6 | use Yoast\WP\SEO\Helpers\Schema; |
| 6 | 7 | use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface; |
| 7 | 8 | |
| 8 | 9 | /** |
| @@ -56,12 +57,41 @@ | ||
| 56 | 57 | * Magic isset for ensuring helper exists. |
| 57 | 58 | * |
| 58 | 59 | * @param string $helper The helper to get. |
| 59 | 60 | * |
| 60 | - * @return bool The helper class. | |
| 61 | + * @return bool Whether the helper exists. | |
| 61 | 62 | */ |
| 62 | 63 | public function __isset( $helper ) { |
| 63 | 64 | return $this->container->has( $this->get_helper_class( $helper ) ); |
| 65 | + } | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * Prevents setting dynamic properties and unsetting declared properties | |
| 69 | + * from an inaccessible context. | |
| 70 | + * | |
| 71 | + * @param string $name The property name. | |
| 72 | + * @param mixed $value The property value. | |
| 73 | + * | |
| 74 | + * @return void | |
| 75 | + * | |
| 76 | + * @throws Forbidden_Property_Mutation_Exception Set is never meant to be called. | |
| 77 | + */ | |
| 78 | + public function __set( $name, $value ) { // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- __set must have a name and value - PHPCS #3715. | |
| 79 | + throw Forbidden_Property_Mutation_Exception::cannot_set_because_property_is_immutable( $name ); | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Prevents unsetting dynamic properties and unsetting declared properties | |
| 84 | + * from an inaccessible context. | |
| 85 | + * | |
| 86 | + * @param string $name The property name. | |
| 87 | + * | |
| 88 | + * @return void | |
| 89 | + * | |
| 90 | + * @throws Forbidden_Property_Mutation_Exception Unset is never meant to be called. | |
| 91 | + */ | |
| 92 | + public function __unset( $name ) { | |
| 93 | + throw Forbidden_Property_Mutation_Exception::cannot_unset_because_property_is_immutable( $name ); | |
| 64 | 94 | } |
| 65 | 95 | |
| 66 | 96 | /** |
| 67 | 97 | * Get the class name from a helper slug |