Skip to content

Commit

Permalink
Trailing whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell committed Nov 19, 2024
1 parent 1217979 commit 2d5cf99
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions language/oop5/property-hooks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ print $example->foo;
</para>
<para>
The <literal>set</literal> hook additionally allows specifying the type and name of an incoming value,
using the same syntax as a method. The type must be either the same as the type of the property,
using the same syntax as a method. The type must be either the same as the type of the property,
or <link linkend="language.oop5.variance.contravariance">contravariant</link> (wider) to it.
For instance, a property of type <type>string</type> could
have a <literal>set</literal> hook that accepts <type>string|Stringable</type>,
Expand All @@ -81,7 +81,7 @@ print $example->foo;
<para>
At least one of the hooks references <code>$this->foo</code>, the property itself. That means
the property wll be "backed." When calling <code>$example->foo = 'changed'</code>,
the provided string will be first cast to lowercase, then saved to the backing value.
the provided string will be first cast to lowercase, then saved to the backing value.
When reading from the property, the previously saved value may conditionally be appended
with additional text.
</para>
Expand All @@ -103,7 +103,7 @@ class Example
public string $foo = 'default value' {
get => $this->foo . ($this->modified ? ' (modified)' : '');
set(string $value) {
$this->foo = strtolower($value);
$this->modified = true;
Expand All @@ -118,7 +118,7 @@ class Example
This example is equivalent to the previous.
</para>
<para>
If the <literal>set</literal> hook's parameter type is the same as the property type (which is typical),
If the <literal>set</literal> hook's parameter type is the same as the property type (which is typical),
it may be omitted. In that case, the value to set is automatically given the name <varname>$value</varname>.
</para>
<example>
Expand All @@ -132,7 +132,7 @@ class Example
public string $foo = 'default value' {
get => $this->foo . ($this->modified ? ' (modified)' : '');
set {
$this->foo = strtolower($value);
$this->modified = true;
Expand Down Expand Up @@ -258,11 +258,11 @@ class Person {
public string $phone {
set => $this->sanitizePhone($value);
}
private function sanitizePhone(string $value): string {
$value = ltrim($value, '+');
$value = ltrim($value, '1');
if (!preg_match('/\d\d\d\-\d\d\d\-\d\d\d\d/', $value)) {
throw new \InvalidArgumentException();
}
Expand Down

0 comments on commit 2d5cf99

Please sign in to comment.