| @@ -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\Twitter; |
| 6 | 7 | use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface; |
| 7 | 8 | |
| 8 | 9 | /** |
| @@ -45,12 +46,41 @@ | ||
| 45 | 46 | * Magic isset for ensuring helper exists. |
| 46 | 47 | * |
| 47 | 48 | * @param string $helper The helper to get. |
| 48 | 49 | * |
| 49 | - * @return bool The helper class. | |
| 50 | + * @return bool Whether the helper exists. | |
| 50 | 51 | */ |
| 51 | 52 | public function __isset( $helper ) { |
| 52 | 53 | return $this->container->has( $this->get_helper_class( $helper ) ); |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Prevents setting dynamic properties and unsetting declared properties | |
| 58 | + * from an inaccessible context. | |
| 59 | + * | |
| 60 | + * @param string $name The property name. | |
| 61 | + * @param mixed $value The property value. | |
| 62 | + * | |
| 63 | + * @return void | |
| 64 | + * | |
| 65 | + * @throws Forbidden_Property_Mutation_Exception Set is never meant to be called. | |
| 66 | + */ | |
| 67 | + public function __set( $name, $value ) { // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- __set must have a name and value - PHPCS #3715. | |
| 68 | + throw Forbidden_Property_Mutation_Exception::cannot_set_because_property_is_immutable( $name ); | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Prevents unsetting dynamic properties and unsetting declared properties | |
| 73 | + * from an inaccessible context. | |
| 74 | + * | |
| 75 | + * @param string $name The property name. | |
| 76 | + * | |
| 77 | + * @return void | |
| 78 | + * | |
| 79 | + * @throws Forbidden_Property_Mutation_Exception Unset is never meant to be called. | |
| 80 | + */ | |
| 81 | + public function __unset( $name ) { | |
| 82 | + throw Forbidden_Property_Mutation_Exception::cannot_unset_because_property_is_immutable( $name ); | |
| 53 | 83 | } |
| 54 | 84 | |
| 55 | 85 | /** |
| 56 | 86 | * Get the class name from a helper slug |