Skip to content

Commit a1f4712

Browse files
authored
Merge pull request #21 from liip/jms-type-name-nullable
jms type annotation is nullable
2 parents 878fd71 + 4edef3b commit a1f4712

File tree

5 files changed

+51
-45
lines changed

5 files changed

+51
-45
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
tags:
8+
- '[0-9].[0-9]+'
9+
pull_request:
10+
11+
jobs:
12+
test:
13+
name: "PHPUnit"
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
php-version: ['7.2', '7.3', '7.4', '8.0']
18+
include:
19+
- php-version: '7.2'
20+
composer-flags: '--prefer-stable --prefer-lowest'
21+
steps:
22+
- name: Check out code into the workspace
23+
uses: actions/checkout@v2
24+
- name: Setup PHP ${{ matrix.php-version }}
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php-version }}
28+
- name: Validate composer.json
29+
run: composer validate --strict --no-check-lock
30+
- name: Composer cache
31+
uses: actions/cache@v2
32+
with:
33+
path: ${{ env.HOME }}/.composer/cache
34+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
35+
- name: Install dependencies
36+
run: composer update ${{ matrix.composer-flags }} --prefer-dist --no-interaction
37+
- name: PHPStan
38+
if: ${{ matrix.php-version == '8.0' }}
39+
run: composer phpstan-all
40+
- name: Run tests
41+
run: composer phpunit

.travis.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/Exception/ParseException.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ final class ParseException extends SchemaException
1010
private const CLASS_ERROR = 'Class "%s" couldn\'t be parsed because of an error: %s';
1111
private const PROPERTY_ERROR = 'Property "%s::%s" couldn\'t be parsed because of an error: %s';
1212
private const PROPERTY_TYPE_ERROR = 'Property "%s::%s" has an invalid type which results in: %s';
13+
private const PROPERTY_TYPE_NAME_NULL = 'Property "%s::%s" has an invalid type annotation. [Type Error] Attribute "name" of @JMS\Type may not be null.';
1314
private const PROPERTY_TYPE_CONFLICT = 'Property "%s::%s" has different type definitions which conflict: %s != %s';
1415
private const UNSUPPORTED_CLASS_ANNOTATION = 'Class "%s" has an unsupported annotation "%s"';
1516
private const UNSUPPORTED_PROPERTY_ANNOTATION = 'Property "%s::%s" has an unsupported annotation "%s"';
@@ -54,6 +55,11 @@ public static function propertyTypeError(string $className, string $propertyName
5455
);
5556
}
5657

58+
public static function propertyTypeNameNull(string $className, string $propertyName): self
59+
{
60+
return new self(sprintf(self::PROPERTY_TYPE_NAME_NULL, $className, $propertyName));
61+
}
62+
5763
public static function propertyTypeConflict(string $className, string $propertyName, string $typeA, string $typeB, \Exception $previousException): self
5864
{
5965
return new self(

src/ModelParser/JMSParser.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ private function parsePropertyAnnotations(RawClassMetadata $classMetadata, Prope
222222
foreach ($annotations as $annotation) {
223223
switch (true) {
224224
case $annotation instanceof Type:
225+
if (null === $annotation->name) {
226+
throw ParseException::propertyTypeNameNull((string) $classMetadata, (string) $property);
227+
}
225228
try {
226229
$type = $this->jmsTypeParser->parse($annotation->name);
227230
} catch (InvalidTypeException $e) {

tests/ModelParser/JMSParserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ public function testVirtualPropertyWithInvalidReturnDocBlock(): void
870870
*/
871871
public function getFoo()
872872
{
873+
return fopen(__FILE__, 'rb');
873874
}
874875
};
875876

0 commit comments

Comments
 (0)