From f4520ae3c5eae2e3237302f3400d3b96f5dcb43d Mon Sep 17 00:00:00 2001 From: crynobone Date: Fri, 20 Dec 2013 00:10:51 +0800 Subject: [PATCH] PHP classes should not use magic methods. Closes #8. Signed-off-by: crynobone --- src/Orchestra/Widget/Drivers/Driver.php | 16 ---------------- tests/Drivers/DriverTest.php | 11 ----------- 2 files changed, 27 deletions(-) diff --git a/src/Orchestra/Widget/Drivers/Driver.php b/src/Orchestra/Widget/Drivers/Driver.php index 58125c1..31913b2 100644 --- a/src/Orchestra/Widget/Drivers/Driver.php +++ b/src/Orchestra/Widget/Drivers/Driver.php @@ -106,22 +106,6 @@ public function getItems() return $this->nesty->getItems(); } - /** - * Magic method to get all items. - * - * @param string $key - * @return mixed - * @throws \InvalidArgumentException - */ - public function __get($key) - { - if ($key !== 'items') { - throw new InvalidArgumentException("Access to [{$key}] is not allowed."); - } - - return $this->getItems(); - } - /** * Get the number of items for the current page. * diff --git a/tests/Drivers/DriverTest.php b/tests/Drivers/DriverTest.php index b814b3c..271229f 100644 --- a/tests/Drivers/DriverTest.php +++ b/tests/Drivers/DriverTest.php @@ -51,7 +51,6 @@ public function testGetItemMethod() $stub = new DriverStub('foo', array()); $this->assertInstanceOf('\Illuminate\Support\Collection', $stub->getItems()); - $this->assertInstanceOf('\Illuminate\Support\Collection', $stub->items); $this->assertNull($stub->is('foo')); $stub->add('foobar')->hello('world'); @@ -63,16 +62,6 @@ public function testGetItemMethod() $this->assertEquals($expected, $stub->is('foobar')); } - - /** - * Test Orchestra\Widget\Drivers\Driver::__get() throws an exception. - * - * @expectedException \InvalidArgumentException - */ - public function testMagicMethodGetThrowsException() - { - with(new DriverStub('foo', array()))->helloWorld; - } } class DriverStub extends \Orchestra\Widget\Drivers\Driver