Repository: spatie/data-transfer-object (php)

Issue:
Setting `#[Strict]` on parent is not applied on children
```php
#[Strict]
abstract class DtoBase {}

final class Dto extends DtoBase {}
```

then `Dto` is not strict because `DataTransferObjectClass::isStrict()` reads attributes only for current instance but not its parents. 

Is it intended or a bug? Thanks!

Pull request:
Read `#[Strict]` also from parent classes
Fixes #238

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad3a13f..76614fb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
 
 All notable changes to `data-transfer-object` will be documented in this file
 
+## Unreleased
+
+- `#[Strict]` is passed down the inheritance chain so children are strict when parent is strict (#239)
+
 ## 3.7.1 - 2021-09-09
 
 - Cast properties with self or parent type (#236)
diff --git a/src/Reflection/DataTransferObjectClass.php b/src/Reflection/DataTransferObjectClass.php
index 7f712ce..1171f1e 100644
--- a/src/Reflection/DataTransferObjectClass.php
+++ b/src/Reflection/DataTransferObjectClass.php
@@ -2,6 +2,7 @@
 
 namespace Spatie\DataTransferObject\Reflection;
 
+use ReflectionAttribute;
 use ReflectionClass;
 use ReflectionProperty;
 use Spatie\DataTransferObject\Attributes\Strict;
@@ -66,6 +67,19 @@ class DataTransferObjectClass
 
     public function isStrict(): bool
     {
-        return $this->isStrict ??= ! empty($this->reflectionClass->getAttributes(Strict::class));
+        if (!isset($this->isStrict)) {
+            $attribute = null;
+
+            $reflectionClass = $this->reflectionClass;
+            while ($attribute === null && $reflectionClass !== false) {
+                $attribute = $reflectionClass->getAttributes(Strict::class)[0] ?? null;
+
+                $reflectionClass = $reflectionClass->getParentClass();
+            }
+
+            $this->isStrict = $attribute !== null;
+        }
+
+        return $this->isStrict;
     }
 }


Test patch:
diff --git a/tests/StrictDtoTest.php b/tests/StrictDtoTest.php
index 3fbd355..7d6d8a6 100644
--- a/tests/StrictDtoTest.php
+++ b/tests/StrictDtoTest.php
@@ -25,6 +25,17 @@ class StrictDtoTest extends TestCase
         $this->expectException(UnknownProperties::class);
 
         $dto = new StrictDto(
+            name:    'name',
+            unknown: 'unknown'
+        );
+    }
+
+    /** @test */
+    public function strict_child_test()
+    {
+        $this->expectException(UnknownProperties::class);
+
+        $dto = new ChildStrictDto(
             name: 'name',
             unknown: 'unknown'
         );
@@ -37,6 +48,9 @@ class StrictDto extends DataTransferObject
     public string $name;
 }
 
+final class ChildStrictDto extends StrictDto {}
+
+
 class NonStrictDto extends DataTransferObject
 {
     public string $name;