Comments (2)
Thanks for the report. @wengooooo this should be fixed with #497.
What is "weird" is needing to use the @param tag on the function phpDoc, else the mapper will recognize the array definition as array and fail. Using @var above the parameter will not work. A working example would have SomeClass defined like this.
@hollow3464 this behavior is intended, using @var
works on properties, or when a constructor's parameter is also a promoted property:
// NOT OK:
final class Foo
{
public array $values;
public function __construct(
/** @var array<string> */
array $values
) {
$this->values = $values;
}
}
// OK:
final class Foo
{
public array $values;
/**
* @param array<string> $values
*/
public function __construct(
array $values
) {
$this->values = $values;
}
}
// OK:
final class Foo
{
public function __construct(
/** @var array<string> */
public array $values
) {}
}
from valinor.
You can only create readonly properties through a constructor.
If you remove the readonly statement it will work. It will also work if you write a constructor that does the property assignments properly.
When using a constructor, every property must me initialized or will remain uninitialized as the mapper will only use the constructor for variable assigment. Please refer to the language docs for usage on readonly props usage.
What is "weird" is needing to use the @param
tag on the function phpDoc, else the mapper will recognize the array definition as array<mixed>
and fail. Using @var
above the parameter will not work. A working example would have SomeClass
defined like this.
final class SomeClass
{
public readonly string $description;
/** @var array<Identifier> */
public array $identifier;
/**
* @param array<Identifier> $identifier
*/
public function __construct(
string $description,
array $identifier,
) {
$this->description = $description;
$this->identifier = $identifier;
}
}
from valinor.
Related Issues (20)
- Conflict in array shapes with namespaces HOT 2
- Use valinor for a assert() function use case HOT 2
- `enableFlexibleCasting` but just for scalars HOT 1
- Is it possible to infer class union (without interface) HOT 1
- How can I teach Valinor to understand generics of \Ds\Set? HOT 3
- [BUG]: FlexibleCastin with Union types HOT 1
- Issue with variadic parameter contains generics HOT 4
- Custom value casters?
- Fix phpstan error with Symfony Uuid in MapperBuilder class and registerConstructor method
- Crash / Infinite loop when target class constructor accepts `self`
- `JsonNormalizer` creates array JSON when object is passed HOT 3
- Potential Bug in Class Name Resolution
- Static Analysis: psalm errors on model classes even with the plugin enabled
- Make the `Class with a single value` behavior an explicit option HOT 1
- Psalm static analysis fails on MapperBuilder::registerTransformer HOT 1
- Class "Money\Money\Currency" does not exist HOT 9
- Missing `DateTimeZone` is formatted as `?`
- Generate JSON Schema for PHP classes / objects
- Interface resolver HOT 1
- Mapper internal state breaks mapping BackedEnum HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from valinor.