annotations
annotations copied to clipboard
Parser does not distinguish between annotated arrays and repeated annotations
The current version of the annotation-parser does not tell between a single JSON-array and multiple simple annotations. But it should!
$parser = new \Minime\Annotations\Parser;
$this->assertNotSame(
$parser->parse('@foo 1 @foo 2 @foo 3'),
$parser->parse('@foo [1, 2, 3]')
); // FAIL. Parser errorneously gives the same result for both strings
$this->assertSame(
['foo' => [1, 2, 3]],
$parser->parse('@foo 1 @foo 2 @foo 3')
); // PASS. Parser works correctly on this
$this->assertSame(
['foo' => [[1, 2, 3]]],
$parser->parse('@foo [1, 2, 3]')
); // FAIL. Parser fails to preserve the array annotated with @foo
Hi!
That was actually intentional from the very beginning to consider, by default, that repeated annotations form an array of values and arrays are merged if identified with the same identifier.
It's totally possible to introduce a new Parser featuring the distinction, or even add an optional parameter into the existing default parser.
Pull requests are welcome!
On v4 this could be adopted as a default behavior. I agree that it would be more intuitive and less ambiguous.