Skip to content

Commit

Permalink
[PropertyInfo] Add hassers for accessors prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdec authored and fabpot committed Feb 7, 2018
1 parent c44a894 commit 03bce5e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
Expand Up @@ -34,7 +34,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
/**
* @internal
*/
public static $defaultAccessorPrefixes = array('is', 'can', 'get');
public static $defaultAccessorPrefixes = array('is', 'can', 'get', 'has');

/**
* @internal
Expand Down Expand Up @@ -178,7 +178,7 @@ private function extractFromAccessor(string $class, string $property): ?array
return array($this->extractFromReflectionType($reflectionType));
}

if (in_array($prefix, array('is', 'can'))) {
if (in_array($prefix, array('is', 'can', 'has'))) {
return array(new Type(Type::BUILTIN_TYPE_BOOL));
}

Expand Down
Expand Up @@ -88,7 +88,8 @@ public function typesProvider()
array('d', array(new Type(Type::BUILTIN_TYPE_BOOL)), null, null),
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),
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),
array('g', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)), 'Nullable array.', null),
array('g', array(new Type(Type::BUILTIN_TYPE_BOOL, true)), null, null),
array('array', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)), 'Nullable array.', null),
array('donotexist', null, null, null),
array('staticGetter', null, null, null),
array('staticSetter', null, null, null),
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function testGetProperties()
'collection',
'B',
'Guid',
'g',
'array',
'emptyVar',
'foo',
'foo2',
Expand All @@ -56,6 +56,7 @@ public function testGetProperties()
'd',
'e',
'f',
'g',
),
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
);
Expand Down Expand Up @@ -196,10 +197,12 @@ public function getReadableProperties()
array('d', true),
array('e', false),
array('f', false),
array('g', true),
array('Id', true),
array('id', true),
array('Guid', true),
array('guid', false),
array('guid', false),
);
}

Expand All @@ -226,6 +229,7 @@ public function getWritableProperties()
array('d', false),
array('e', true),
array('f', true),
array('g', false),
array('Id', false),
array('Guid', true),
array('guid', false),
Expand Down
Expand Up @@ -66,7 +66,7 @@ class Dummy extends ParentDummy
*
* @var array|null
*/
public $g;
public $array;

/**
* This should not be removed.
Expand Down
Expand Up @@ -75,4 +75,11 @@ public function addE($e)
public function removeF(\DateTime $f)
{
}

/**
* @return bool|null
*/
public function hasG()
{
}
}

0 comments on commit 03bce5e

Please sign in to comment.