Skip to content

Commit dff8bf8

Browse files
committed
cleanup
1 parent 3ef3a5e commit dff8bf8

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

README.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,23 @@ class Box
8585
/**
8686
* @param T $value
8787
*/
88-
public function __construct($value)
88+
public function __construct(private mixed $value)
8989
{
90-
$this->value = $value;
9190
}
9291
}
9392
```
9493

94+
Small **ad break** for [Scala](https://www.scala-lang.org/). The same code in Scala 3 looks like this:
95+
```scala
96+
case class Box[T](value: T)
97+
```
98+
/ad-break
99+
95100
The `@template T` annotation tells PHPStan that the class is generic and that the type of the value is T.
96101
In the constructor, we use the $value parameter with the type T,
97102
and the type of the Box is automatically reverse engineered from the input.
98103

99-
Small **ad break** for [Scala](https://www.scala-lang.org/). The ENTIRE above code in Scala 3 looks like this:
100-
```scala
101-
class Box[T](value: T)
102-
```
103-
To add insult to injury, Scala has extension methods that you can add to any class on the fly. So no Box class
104-
is needed. You can just write:
105-
```scala
106-
import scala.util.chaining.*
107-
108-
"Hello World"
109-
.toCharArray
110-
.map(_.toInt)
111-
.sum
112-
.pipe(n => s"The number is $n")
113-
.tap(println) // prints "The number is 1052"
114-
```
115-
/ad-break
104+
116105

117106
Examples:
118107
- `Box::of(5)` will be of type `Box<int>`

src/Box.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
*/
1414
class Box
1515
{
16-
/**
17-
* @var T
18-
*/
19-
private $value;
20-
2116
/**
2217
* @template U
2318
* @param U $value
@@ -31,9 +26,8 @@ public static function of($value): Box
3126
/**
3227
* @param T $value
3328
*/
34-
public function __construct($value)
29+
public function __construct(private mixed $value)
3530
{
36-
$this->value = $value;
3731
}
3832

3933
/**

0 commit comments

Comments
 (0)