Skip to content

Commit 281714c

Browse files
author
Dominik Liebler
committed
PHP7 Proxy
1 parent 2e287ac commit 281714c

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

Structural/Proxy/Record.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace DesignPatterns\Structural\Proxy;
44

55
/**
6-
* class Record.
6+
* @property string username
77
*/
88
class Record
99
{
@@ -21,31 +21,20 @@ public function __construct(array $data = [])
2121
}
2222

2323
/**
24-
* magic setter
25-
*
2624
* @param string $name
27-
* @param mixed $value
28-
*
29-
* @return void
25+
* @param string $value
3026
*/
3127
public function __set(string $name, string $value)
3228
{
3329
$this->data[$name] = $value;
3430
}
3531

36-
/**
37-
* magic getter
38-
*
39-
* @param string $name
40-
*
41-
* @return string|null
42-
*/
4332
public function __get(string $name): string
4433
{
45-
if (isset($this->data[$name])) {
46-
return $this->data[$name];
47-
} else {
48-
return null;
34+
if (!isset($this->data[$name])) {
35+
throw new \OutOfRangeException('Invalid name given');
4936
}
37+
38+
return $this->data[$name];
5039
}
5140
}

Structural/Proxy/RecordProxy.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public function __construct(array $data)
3232
}
3333

3434
/**
35-
* magic setter
36-
*
3735
* @param string $name
3836
* @param string $value
3937
*/
@@ -44,9 +42,6 @@ public function __set(string $name, string $value)
4442
parent::__set($name, $value);
4543
}
4644

47-
/**
48-
* @return bool
49-
*/
5045
public function isDirty(): bool
5146
{
5247
return $this->isDirty;

Structural/Proxy/Tests/ProxyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class ProxyTest extends \PHPUnit_Framework_TestCase
1010
public function testWillSetDirtyFlagInProxy()
1111
{
1212
$recordProxy = new RecordProxy([]);
13-
$recordProxy->foobar = 'baz';
13+
$recordProxy->username = 'baz';
1414

1515
$this->assertTrue($recordProxy->isDirty());
1616
}
1717

1818
public function testProxyIsInstanceOfRecord()
1919
{
2020
$recordProxy = new RecordProxy([]);
21-
$recordProxy->foobar = 'baz';
21+
$recordProxy->username = 'baz';
2222

2323
$this->assertInstanceOf('DesignPatterns\Structural\Proxy\Record', $recordProxy);
2424
}

0 commit comments

Comments
 (0)