Skip to content

Commit 89d1b65

Browse files
committed
feature #23617 [PropertyInfo] Add hassers for accessors prefixes (sebdec)
This PR was submitted for the 3.3 branch but it was squashed and merged into the 4.1-dev branch instead (closes #23617). Discussion ---------- [PropertyInfo] Add hassers for accessors prefixes | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | None | License | MIT | Doc PR | - In the component PropertyInfo In the class ReflectionExtractor Add hassers in the accessors prefixes Because I think it's common to have readable properties with method like this: hasChildren() Commits ------- 03bce5e [PropertyInfo] Add hassers for accessors prefixes
2 parents c44a894 + 03bce5e commit 89d1b65

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
3434
/**
3535
* @internal
3636
*/
37-
public static $defaultAccessorPrefixes = array('is', 'can', 'get');
37+
public static $defaultAccessorPrefixes = array('is', 'can', 'get', 'has');
3838

3939
/**
4040
* @internal
@@ -178,7 +178,7 @@ private function extractFromAccessor(string $class, string $property): ?array
178178
return array($this->extractFromReflectionType($reflectionType));
179179
}
180180

181-
if (in_array($prefix, array('is', 'can'))) {
181+
if (in_array($prefix, array('is', 'can', 'has'))) {
182182
return array(new Type(Type::BUILTIN_TYPE_BOOL));
183183
}
184184

src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public function typesProvider()
8888
array('d', array(new Type(Type::BUILTIN_TYPE_BOOL)), null, null),
8989
array('e', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_RESOURCE))), null, null),
9090
array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime'))), null, null),
91-
array('g', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)), 'Nullable array.', null),
91+
array('g', array(new Type(Type::BUILTIN_TYPE_BOOL, true)), null, null),
92+
array('array', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)), 'Nullable array.', null),
9293
array('donotexist', null, null, null),
9394
array('staticGetter', null, null, null),
9495
array('staticSetter', null, null, null),

src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testGetProperties()
4040
'collection',
4141
'B',
4242
'Guid',
43-
'g',
43+
'array',
4444
'emptyVar',
4545
'foo',
4646
'foo2',
@@ -56,6 +56,7 @@ public function testGetProperties()
5656
'd',
5757
'e',
5858
'f',
59+
'g',
5960
),
6061
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
6162
);
@@ -196,10 +197,12 @@ public function getReadableProperties()
196197
array('d', true),
197198
array('e', false),
198199
array('f', false),
200+
array('g', true),
199201
array('Id', true),
200202
array('id', true),
201203
array('Guid', true),
202204
array('guid', false),
205+
array('guid', false),
203206
);
204207
}
205208

@@ -226,6 +229,7 @@ public function getWritableProperties()
226229
array('d', false),
227230
array('e', true),
228231
array('f', true),
232+
array('g', false),
229233
array('Id', false),
230234
array('Guid', true),
231235
array('guid', false),

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Dummy extends ParentDummy
6666
*
6767
* @var array|null
6868
*/
69-
public $g;
69+
public $array;
7070

7171
/**
7272
* This should not be removed.

src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php

+7
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,11 @@ public function addE($e)
7575
public function removeF(\DateTime $f)
7676
{
7777
}
78+
79+
/**
80+
* @return bool|null
81+
*/
82+
public function hasG()
83+
{
84+
}
7885
}

0 commit comments

Comments
 (0)