Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can access the field of a object through same name method #149

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ClosureExpressionVisitor extends ExpressionVisitor
{
/**
* Accesses the field of a given object. This field has to be public
* directly or indirectly (through an accessor get*, is*, or a magic
* directly or indirectly (through an accessor get*, is*, *, or a magic
* method, __get, __call).
*
* @param object|array $object
Expand All @@ -36,7 +36,7 @@ public static function getObjectFieldValue($object, $field)
return $object[$field];
}

$accessors = ['get', 'is'];
$accessors = ['get', 'is', ''];

foreach ($accessors as $accessor) {
$accessor .= $field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public function testGetObjectFieldValueMagicCallMethod() : void
self::assertEquals(3, $this->visitor->getObjectFieldValue($object, 'qux'));
}

public function testGetObjectFieldValueSameNameMethod() : void
{
$object = new TestObject(1, 2, true, 3, 4);

self::assertEquals(4, $this->visitor->getObjectFieldValue($object, 'kat'));
}

public function testWalkEqualsComparison() : void
{
$closure = $this->visitor->walkComparison($this->builder->eq('foo', 1));
Expand Down Expand Up @@ -270,12 +277,16 @@ class TestObject
/** @var mixed */
private $qux;

public function __construct($foo = null, $bar = null, $baz = null, $qux = null)
/** @var mixed */
private $kat;

public function __construct($foo = null, $bar = null, $baz = null, $qux = null, $kat = null)
{
$this->foo = $foo;
$this->bar = $bar;
$this->baz = $baz;
$this->qux = $qux;
$this->kat = $kat;
}

public function __call(string $name, array $arguments)
Expand All @@ -299,6 +310,11 @@ public function isBaz()
{
return $this->baz;
}

public function kat()
{
return $this->kat;
}
}

class TestObjectNotCamelCase
Expand Down