Skip to content

Commit 17807fb

Browse files
author
Greg Bowler
authored
Rename getObject to getInstance (#41)
* test: implement unit tests * refactor: remove unused getClass function * test: upgrade phpunit * test: upgrade phpunit * ci: improve QA tooling * docs: update example * docs: update badges * tweak: rename object/instance * tweak: formatting
1 parent 7874a16 commit 17807fb

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Throughout PHP.Gt repositories, wherever an object represents enclosed data, a c
88
<a href="https://github.com/PhpGt/TypeSafeGetter/actions" target="_blank">
99
<img src="https://badge.status.php.gt/typesafegetter-build.svg" alt="Build status" />
1010
</a>
11-
<a href="https://app.codacy.com/gh/PhpGt/Curl" target="_blank">
11+
<a href="https://scrutinizer-ci.com/g/PhpGt/TypeSafeGetter" target="_blank">
1212
<img src="https://badge.status.php.gt/typesafegetter-quality.svg" alt="Code quality" />
1313
</a>
1414
<a href="https://app.codecov.io/gh/PhpGt/TypeSafeGetter" target="_blank">
@@ -29,7 +29,7 @@ The following methods are defined by this interface:
2929
+ `getFloat(string $name):?float`
3030
+ `getBool(string $name):?bool`
3131
+ `getDateTime(string $name):?DateTimeInterface`
32-
+ `getObject(string $name, class-string<T> $className):?T`
32+
+ `getInstance(string $name, class-string<T> $className):?T`
3333

3434
Common areas you will see this interface used:
3535

src/CallbackTypeSafeGetter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ public function getDateTime(
2121
* @param callable():<T> $callback
2222
* @return T
2323
*/
24-
public function getObject(string $name, string $className, callable $callback);
24+
public function getInstance(
25+
string $name,
26+
string $className,
27+
callable $callback,
28+
);
2529
}

src/NullableTypeSafeGetter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function(string|int|DateTimeInterface $value) {
4040
);
4141
}
4242

43-
public function getObject(string $name, string $className) {
43+
public function getInstance(string $name, string $className) {
4444
return $this->getNullableType(
4545
$name,
4646
$className,

src/TypeSafeGetter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ public function getDateTime(string $name):?DateTimeInterface;
1717
* @param class-string<T> $className
1818
* @return T
1919
*/
20-
public function getObject(string $name, string $className);
20+
public function getInstance(string $name, string $className);
2121
}

test/phpunit/TypeSafeGetterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ public function testGetDateTime_castFromInt():void {
114114
self::assertSame($dateString, $dateTime->format("Y-m-d"));
115115
}
116116

117-
public function testGetObject():void {
117+
public function testGetInstance():void {
118118
$example = new ExampleClass("Just an example");
119119
$sut = new TestGetter([
120120
"example" => $example
121121
]);
122-
$object = $sut->getObject("example", ExampleClass::class);
122+
$object = $sut->getInstance("example", ExampleClass::class);
123123
self::assertSame(
124124
$example,
125125
$object
@@ -134,26 +134,26 @@ public function testGetObject():void {
134134
);
135135
}
136136

137-
public function testGetObject_invalidType():void {
137+
public function testGetInstance_invalidType():void {
138138
$example = new ExampleClass("Just an example");
139139
$sut = new TestGetter([
140140
"example" => $example
141141
]);
142142

143143
self::expectException(TypeError::class);
144144
self::expectExceptionMessage("Session value must be of type DateTimeInterface, " . ExampleClass::class . " returned");
145-
$sut->getObject("example", DateTimeInterface::class);
145+
$sut->getInstance("example", DateTimeInterface::class);
146146
}
147147

148-
public function testGetObject_inheritedClass():void {
148+
public function testGetInstance_inheritedClass():void {
149149
$example = new DateTime("1988-04-05");
150150
$sut = new TestGetter([
151151
"example" => $example
152152
]);
153153

154154
self::assertSame(
155155
$example,
156-
$sut->getObject("example", DateTimeInterface::class),
156+
$sut->getInstance("example", DateTimeInterface::class),
157157
);
158158
}
159159
}

0 commit comments

Comments
 (0)